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.
- Collecting and returning the information about the
Peoplewho exploded that turn for scoring purposes
/* * 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
/* * 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