fp-elevators

Game.cpp

You need to implement the functions in this file for the Reach, not the Core.

We have provided stub implementations for these functions in the starter code, so that your game is playable as you implement the Core. You will need to erase the code we provided for these functions when you implement them for the Reach.

Overview

Game is a class declared in the Game.h file. The Game class is the engine behind the elevators project, and will be the main object used for how users interact with the program.

Member data

Member Functions

Many member functions have been written for you. Please refer to their RME’s for use reference.

You will be writing the implementations for the following functions:

playGame

/**
 * Requires: nothing
 * Modifies: cout, isAIMode, building, satisfactionIndex
 * Effects:  prints game start prompt
 *           if game input file is not open, exits with status 1
 *           else reads events from game input file
 *           if event is happening on current turn, updates building 
 *           with event else prints building and checks if game has 
 *           ended, if it hasn't yet, gets user (player or AI) move, 
 *           and updates building with move.
 */
void playGame(bool isAIModeIn, ifstream &gameFile);

IMPORTANT NOTE: For this function, the autograder is expecting the first and the second lines of the Effects clause to be switched. That means that the effects clause should read as follows:

   Effects: if game input file is not open, exits with status 1
            prints game start prompt
            ...
   

Essentially, the autograder wants you to first check that the file is open, and then print the prompt.

This function should set isAIMode based on the argument, then call 2 member functions (in the order below) of Game in order to set up the main game loop:

  1. Game::printGameStartPrompt(): This will alert the user that the game will begin, and will display the menu options available during the Game.
  2. Game::initGame(): This will initialize the Game by loading in the initial data from gameFile.

The input file will have lines describing when people will be spawned. The user will play the game as these files are read and the people are spawned. After all the people have spawned, the user can continue playing the game. To do this:

  1. While there is another line in gameFile:
    1. Create a Person using that line
    2. Determine which tick the Person will be spawned
    3. Have the user play the game until that tick has finished
    4. Spawn the person
  2. Until the game is over:
    1. Have the user play the game

Here are the steps to have the user play the game:

  1. Make a call to prettyPrintBuilding on the building member variable with cout as the parameter argument
  2. Make a call to printSatisfaction on the satisfactionIndex member variable with cout and false as the parameter arguments
  3. Check to see if the game has ended (we’ve given you the checkForGameEnd() function for this)
  4. Ask the user for a Move (we’ve provided a member function for this)
  5. Apply the inputted Move (we’ve provided a member function for this)

To exit with status 1, use the exit() standard library function.

isValidPickupList

/**
* Requires: pickupFloorNum is the floor the pickup move was called on
* Modifies: nothing
* Effects: determines if pickupList is a valid
*          list of people to pick up
*/
bool isValidPickupList(const string& pickupList, const int pickupFloorNum) const;

This function is called when the user decides to pick up people on a floor. The game gives the user an opportunity to select which people currently on that floor they would like to pick up, then calls this function to verify that the user’s selection is valid.

An example pickupList: "0135"

“I choose the people at indices 0, 1, 3, and 5 to pickup”

A pickupList is valid if it meets the following conditions:

  1. There are no duplicate indices present in pickupList
  2. Each element of pickupList is a non-negative digit
  3. The length of the pickupList is less than or equal to the capacity of an elevator
  4. The maximum value pointed to by an index of pickupList must be strictly less than the number of people on the floor pointed to by pickupFloorNum
  5. Each person represented by an index in pickupList must be going in the same direction relative to pickupFloorNum