Question: Part 1 : Recursion & 2 D arrays ( 7 0 marks ) We are going to create a game where the user can
Part : Recursion & D arrays marks
We are going to create a game where the user can control a character with specific actions that can be taken. The gameboard will be a D array where each entry represents a location the character can exist. The character can move around the gameboard with the intention to escape. That's right, we placed the character randomly on the board and the user must free them by reaching the exit, which is also randomly placed on the board not the same location
The user has the following actions available to them:
Move updownleftright If on the edge of the D board, they can jump to the opposite side. Moving to a zone that is unsafe will cost life point.
Perform a safety check. This action will check neighbouring zones and the number of safe zones are displayed in the current zone. No information is provided about the individual zones, just a total sum. The zone maintains this number and updates if neighbouring zones become safe from a bomb in future actions and positions.
Neutralize zones bomb The user can choose to neutralize all neighbouring zones make them safe This action can only be taken times in the game. The neighbouring zones are all marked as E for explored or X for the exit if found
The gameboard should be a D array. Note that when displaying the board to the user, you can only show zones that have been explored and neighbour options for movement. Zones that are unsafe are randomly generated at a rate of of the board. The board is by wide. The gameloop should be performed recursively. The inputs are the following: Gameboard D array, lifepoints starting at passed by reference, number of bombs available starting at passed by reference, current position x current position y both passed by value energy starting at number of zones passed by reference.
The recursive function should display zones that have been explored marked as E current position, and neighbouring unexplored options marked as in a grid, safety checks digit and unsafe locations reached and # Any zone that is not one of those types can simply be printed as a whitespace.
Then the function should present the user with possible actions. Given a selected action, the function should perform the action and call itself recursively with the new parameters make sure to handle lifepoints, bombs, energy and gameboard changes before making the recursive call Note that energy is reduced every time an action is taken. If no energy left, they lost a lifepoint instead for any new actions. Consider printing energy to the user off the board. There are an extra lifepoints randomly placed on the board for the user to collect shown as when found and remains as a on the board
When a bomb is used, the neighbouring zones all turn into E for explored while reducing the bomb count. It does not affect zones that were reached and unsafe, and they always cause a lost lifepoint if travelled to again. Note that if the exit is part of the neighbouring zones, then an X is displayed instead so that the user can move there and win
If the user chooses to make a safety check instead, then the T symbol in the current position is changed to a digit for the number of safe neighbouring zones. This digit remains on the board from that point on and updates if a bomb causes one of the unsafe zones to become clear. When travelling to the zone again, the number remains present T disappears
When the user finds the exit, the recursive function will simply return and the entire stack should pop. A message should print to say they won before returning. The user loses when they lost all their lifepoints. In this case the function prints a message saying they lost and returns. Legend:
T: Charactercurrent position
E: Explored Region
: white space unexplored region not accessible yet
: Possible move that can be made neighbouring unexplored zones to T
X : The exit
: Value for number of safe neighbouring zones replaces T when action is taken
: Just moved to an unsafe location lost a lifepointreplaces T at current position
# : Previous unsafe zone that was hit
: Lifepoints increase by
C Ryan Bluteau. All rights reserved.
Page of
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
