fp-elevators

Building.cpp

Overview

Building is a class declared in Building.h and is responsible for containing the full state of the game. It controls all of the Elevators and 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.

Member Data

Member Functions

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:

tick

/*
* 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:

  1. Updating the time
  2. Applying the Move to the building and updating the appropriate state.
  3. Calling tick with the new time on all the assets in the building.
  4. Finally, return number of people who exploded.

The Building::tick() function will update the time and call the tick() function of each of the Floors and Elevators. 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.

update

/*
* 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 Floor or Elevator. (See the section on Move for more details) for definitions of Pass Move, Pickup Move, and Service Move.

Tutorial Video for update

spawnPerson

/*
* Requires: newPerson is a valid Person object
* Modifies: A floor in the building - floors
* Effects:  Adds a person to the Floor corresponding to currentFloor
*           of the person
*/
void spawnPerson(Person newPerson);

Each 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.

Function Table

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
spawnPerson() Person::getCurrentFloor(), Person::getTargetFloor(), Floor::addPerson()
update() Move::isPassMove(), Move::getElevatorId(), Elevator::getCurrentFloor(), Move::isPickupMove(), Move::copyListOfPeopleToPickup(), Move::getNumPeopleToPickup(), Floor::removePeople(), Elevator::serviceRequest(), Move::getTargetFloor()
tick() Building::update(), Elevator::tick(), Floor:tick()