Question: Can you help me write a C + + whack a mole code? in main, you will use three integer variables called score, molesLeft, and
Can you help me write a C whack a mole code?
in main, you will use three integer variables called score, molesLeft, and
attemptsLeft. Make one more variable called moleGrid which is a
dimensional array of characters. You will also need a global constant
integer called gridDimension.
These specify the current score, maximum number of moles, total number
of whacks allowed, the game board, and the grid dimensions.
make sure to initialize the moleGrid with the
appropriate character. bool placeint x int y char moleGridgridDimension
gridDimensionint & molesLeft Given a location, place a mole at that
location. Return true if you can and update number of moles left.
void whackint x int y char moleGridgridDimensiongridDimension
int& score, int& molesLeft, int& attemptsLeft Given a location, take a
whack at that location. If that location contains a mole, update the score,
number of attemptsLeft, and molesLeft is updated. If that location does not
contain a mole, only attemptsLeft is updated.
void printGridToUserchar moleGridgridDimensiongridDimension
Print the grid without showing where the moles are. For every spot that
has recorded a whacked mole, print out a W or otherwise.
void printGridchar moleGridgridDimensiongridDimension Print
the grid completely. This is effectively dumping the d array on the screen.
The places where the moles are should be printed as an M The places
where the moles have been whacked should be printed as a W The
places that dont have a mole should be printed as
Putting it all together main method
In order to play this game you need to create a main method.
Begin by creating a by grid where you randomly place the moles.
Place a total of moles.
Now allow the user remember how to use cin? to enter the x and y
coordinates of where they would like to take a whack. Tell them they have
a maximum of attempts to get all the moles.
At any point in the game, they can input coordinates of in order to
indicate that they are giving up If the user gives up they get to see the
entire grid.
The game ends if the user is able to uncover all the moles or if the user
runs out of attempts
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
