Question: Answer in C + + please and give step by step code and explenation thank you You will create at least four files for this
Answer in C please and give step by step code and explenation thank you
You will create at least four files for this assignment: GameObject.h Game.h Game.cpp Main.cpp
Create a GameObject class declaration and implementation in GameObject.h since this class is very simple:
Protected attribute:
symbol the symbol for the game object that gets displayed
Public methods:
void setSymbolchar s: set the game object symbol
char getSymbol: return the game object symbol
Create a UserPlayer class that is a child of the GameObject class in GameObject.h:
Private attribute:
x y the location of the player
Public methods:
UserPlayerint x int, y char s X: a constructor that takes up to variables and doubles as a default constructor too.
void setLocationint x int y: set the attributes x y
int getX: return the x location
int getY: return the y location
Create a Game class declaration and simple implementations in Game.h while complex implementation in Game.cpp:
Private attributes required:
width the width of the game board
height the height of the game board
gameBoardthe game board consisting of symbols You would need to use the absolute number here and instead of the attributes width and height since, from a compiler point of view, these attributes are not defined until the object is completely created.
numDeadBlock the number of deadly blocks in the game
player UserPlayer object for this game
block GameObject object for the empty slots
Private attributes optional:
numHit how many times the player got hit
deadBlockLocationa D array of the location of the deadly blocks. You can hardcode this, ie explicitly specify the location
Public methods required:
GameUserPlayer p GameObject b: constructor you may add extra parameters
void printGameBoard: print the game board on the screen
void playGame: runs the game fully by asking the user for input wasd or q to quit moving the player if the move is valid, printing the game board after every round, checking if the user has hit a hidden deadly block. It also stops the game when the user is at the end of the board, ie bottom right Hint when this condition happens, simply write return; This will exit the whole method You may want to call printGameBoard and withinBorders methods here.
Public methods optional:
bool withinBordersint x int y: check of x and y are within the game borders.
In the main function in Main.cpp:
Create a UserPlayer object for the player and set its symbol.
Create a GameObject object for empty blocks and set its symbol.
Create a Game object.
Call the playGame method for the game object.
Enhancement :
Create the deadly blocks at random locations Hint: we did random number generation in the class Suggestion: In the main function, write down srandunsigned inttimenullptr; before you create the game. This statement tells the compiler to generate more randomized numbers.
Make what you print in the console colorful as shown in the game play.
Notes
Make sure declarations and simple implementations are done in header files h while complex implementations are done in cpp files cpp
Make sure to use the attributesvariables rather than hardcoding. For example, don't use the numbers and when printing the boardGame array. Rather, use the the attributesvariables that hold the board dimensions.
Add description for your classesmethods
You may add other publicprivate attributes and methods and even classes. You may do other things in your main function eg ask the user for their name
You may change the value of the attributes. The ones I gave you just make a simple yet challenging game.
You may choose not to use a D array in the game.
You may use any builtin library.
The optional attributesmethods are ones I used for my solutions to make my code more concise. You may find them useful.
You may add extra features eg add walls that block the player
You can use std::cin to get the user input OR you can use getche from #include to avoid having the user pressing enter after printing the direction letter the function reads one character only
You may NOT CHANGE the structure. The goal of the assignment is to have multiple classes at least implement inheritance, and use an object from a class we built as an attribute in another class. Moreover, you must get used to distributing code across multiple files.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
