Building is a class declared in
Building.h and is responsible for containing the full state of the game. It controls all of the
Floors by performing the
Moves and adding the
Person objects that are presented to it. There is a single instance of a
Building class that will be used by the
Game class to track the state of the assets while the game is played.
elevators[NUM_ELEVATORS]is an array that represents all of the elevators in the building.
floors[NUM_FLOORS]is an array that represents each floor in the building
timeis an integer that represents the internal clock of the game, which
ticks forward on each turn. It is used to regulate new spawns and the movement and updating of the elevators and floors.
Many member functions have been written for you. Please refer to their RME’s for reference.
You will be writing the implementations for the following functions:
/* * Requires: move is a valid move * Modifies: The private member variables of building * Effects: Increments time and calls update() on the input move. * Then, ticks all of the elevators with the new time. * Next, ticks all of the building floors, keeping track of new * exploded people. * Returns the total number of people that exploded in this tick */ int tick(Move move);
tick is the function that advances the game one turn. During each turn, we give the player the opportunity to make one
Move, which comes in as an argument to this function. Overall, this function is responsible for:
- Updating the
- Applying the
Moveto the building and updating the appropriate state.
tickwith the new time on all the assets in the building.
- Finally, return number of people who exploded.
Building::tick() function will update the time and call the
tick() function of each of the
Floor::tick() function will then call the
tick() function of each of
Persons waiting for an elevator on that floor. The below diagram helps explain how the
tick() functions will be used to carry out updates throughout the game.
/* * Requires: move is a valid move * Modifies: The building member variables affected by the move * Effects: Applies the move to the building: * * If the move is a Pass Move, nothing happens * * If the move is a Pickup Move, copies the list of people to * pickup into an array, and calls removePeople() on the * appropriate floor * * For both Pickup Moves and Service Moves, the appropriate * elevator should be sent to service the targetFloor of the move */ void update(Move move);
This is one part of a
tick, during which we take the incoming
Move and use it to update the appropriate
Elevator. (See the section on
Move for more details) for definitions of Pass Move, Pickup Move, and Service Move.
- There’s nothing to be done for Pass Moves. Game moves (save or quit moves) will never be passed to this function by the game.
- Both Pickup Moves and Service Moves require the appropriate elevator to change floors. This is done by calling
Elevatorsection for more details)
- For Pickup Moves, we have to remove
Moveis happening. This is done using
Tutorial Video for
You can find this and other walkthroughs in the Google drive folder for the project here.
/* * Requires: newPerson is a valid Person object * Modifies: A floor in the building * Effects: Adds a person to the Floor corresponding to startingFloor * of the event */ void spawnPerson(Person newPerson);
Person corresponds to a person appearing on a
Floor. So, to process a person, we call
floor.addPerson() on the
Floor where this
Person appeared. The
Floor::addPerson function requires two arguments: a
Person, provided as the parameter of this function, and an
int which you must calculate based on the
newPerson’s target and current floors.
The table below provides an outline of which other functions each function should call, if any. The functions listed here do not include any library functions you may wish to use. Please look at the starter code section of the spec to see which libraries you are allowed to use.
|Function||Other functions it should call|