[SOLVED] CS32 -Project 1 -  Battle for Zion 

30.00 $

Category:

Description

5/5 - (5 votes)

The appendix to this document is the specification of the last CS 31 project from a previous quarter. We will provide you with a correct1 solution to that project. Your assignment is to (1) organize the code for the solution in appropriate header and implementation files, and (2) implement a new feature.

You should read the appendix now. It describes a game in which a player has to escape from robots in an arena. You will be working with this code that implements the game. Notice that it is a single file. (Just so you know, the way we tested its correctness is similar to how we’ll test the correctness of the programs you write in CS 32.)

 

Organize the Code

Take the single source file, and divide it into appropriate header files and implementation files, one pair of files for each class. Place the main routine in its own file named main.cpp. Make sure each file #includes the headers it needs. Each header file must have include guards.

Now what about the global constants? Place them in their own header file named globals.h. And what about utility functions like decodeDirection or clearScreen? Place them in their own implementation file named utilities.cpp, and place their prototype declarations in globals.h.

The Visual C++ 2019 and the Xcode writeups demonstrate how to create a multi-file project. From the collection of the eleven files produced as a result of this part of the project, make sure you can build an executable file that behaves exactly the same way as the original single-file program.

 

Add a Feature

If you try running the updated programs (the Windows version, the Mac version or the Linux version of the full game, and the Windows version, the Mac version or the Linux version of the smaller version of the game), you’ll see they have one new command you can type: p for Previous. This command shows you how many turns the player has been on each grid point (not counting the player’s initial placement on the grid): dot means 0, a letter character A through Y means 1 through 25 times (A means 1, B means 2, etc.) and Z means 26 or more times.

 

Your task is to implement this functionality. You will need to do the following:

Define a class named Previous with the following public interface:

class Previous

{

public:

Previous(int nRows, int nCols);         bool dropACrumb(int r, int c);         void showPreviousMoves() const;

};

The constructor initializes a Previous object that corresponds to an Arena with nRows rows and nCols columns. You may assume (i.e., you do not have to check) that it will be called with a first argument that does not exceed MAXROWS and a second that does not exceed MAXCOLS, and that neither argument will be less than 1.

The dropACrumb function is to be called to notify the Previous object that the player has arrived at or stayed at a grid point. The function returns false if row r, column c is not within bounds; otherwise, it returns true after recording what it needs to. This function expects its parameters to be expressed in the same coordinate system as the arena (e.g., row 1, column 1 is the upper-left-most position).

The showPreviousMoves function clears the screen and displays the grid of what has happened previously as the posted programs do. This function does clear the screen; it does not print the “Press Enter to continue” after the display.

The class declaration (with any private members you choose to add to support your implementation) must be in a file named Previous.h, and the implementation of the Previous class’s member functions must be in Previous.cpp. If you wish, you may add a public destructor to the Previous class. You must not add any other public members to the class. (This implies, for example, that you must not add a public default constructor.) The only member function of the Previous class that may cout is Previous::showPreviousMoves.

Add a data member of type Previous (not of type pointer-to-Previous) to the Arena class and provide this public function to access it; notice that it returns a reference to a

Previous object.

class Arena

{

Previous& thePrevious();

…       }; Have the player notify its arena’s Previous object about the player’s resulting position when the player stands or moves.

Have the Game recognize the new p command, tell the Arena’s Previous object to show the grid beforehand, and then print the “Press Enter to continue” prompt and wait for the user to respond. (cin.ignore(10000,’\n’); does that nicely.) Typing the p command does not count as the player’s turn.