Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this lab. I need help on writing the code. thank you In this lab youll be writing a Game class to

Please help me with this lab. I need help on writing the code. thank you

In this lab youll be writing a Game class to use for Project 3. A Game object will be composed of all of the elements that make up the game (such as the player playing the game and the locations in the world that the player can visit). For this lab, open up the Visual Studio project you made for Lab 5 and add files called game.h and game.cpp. Write your Game class so that it has the following attributes:

Location ***world;

Player p;

int rows;

int cols;

int playerRow;

int playerCol;

Your Game class will need to have the following methods:

1. a default constructor that initializes world, rows, cols, playerRow, and playerCol to 0.

2. a method called setUpGame that first sets rows and cols to the number of rows and columns you want to have in your game world (I recommend starting with something no bigger than 8x8) and initializes playerRow and playerCol to the location in the world where you want the player to start. Next, world should be dynamically allocated into a two dimensional array of type Location * with rows and cols as its dimensions. The method should then initialize every location in this array to 0 (or NULL). Finally, this method should create objects of each of your location classes (that you made for Lab 5) at appropriate positions in the world array (you can decide what makes an appropriate position). Place Location objects at each position not filled by an object of one of your other classes.

3. a method called drawGame that loops over the world array and prints a P at the location of the Player and calls the draw method for every other location in the world array.

4. a method called playGame that starts by calling the setUpGame method and then begins a do while loop that runs as long as the user wants to continue exploring (youll need to come up with a way to ask the user if he/she wants to keep exploring the game world at the bottom of the loop). At the top of the loop call the drawGame method and ask the user what direction he/she wants to move. If the entered move indicates a valid move (i.e. will not move him/her out of the game world), then update playerRow and playerCol appropriately. Finally, call the visit method for the location in the world that the player just entered.

5. a destructor that correctly deletes the dynamically allocated world array.

Once you have written the appropriate code for your game class, have your main function create a Game object and then call its playGame method. You should see the initial state of the game appropriately displayed on the screen and the program should allow you to move around and explore the game world. A sample display is shown on the next page (yours does not have to look like mine).

NOTE: If you want to try to make your display a little more aesthetically pleasing, you can place system(cls) calls in your code whenever you want to clear the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions