Question: Part 1 : Recursion & 2 D arrays ( 7 0 marks ) We are going to create a game where the user can

Part 1: Recursion \& 2D arrays (70 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 2D 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:
(1) Move up/down/left/right. If on the edge of the 2 D board, they can jump to the opposite side. Moving to a zone that is unsafe will cost 1 life point.
(2) 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.
(3) Neutralize zones (bomb). The user can choose to neutralize all neighbouring zones (make them safe). This action can only be taken 3 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 2D 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 \(20\%\) of the board. The board is 15 by 30 wide. The gameloop should be performed recursively. The inputs are the following: Gameboard 2D array, lifepoints (starting at 3) passed by reference, number of bombs available (starting at 3) passed by reference, current position \( x \), current position \( y \)(both passed by value), energy (starting at \(450=\) 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 3 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: Character/current 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
-1/2/3/4 : Value for number of safe neighbouring zones (replaces T when action is taken).
-! : Just moved to an unsafe location (lost a lifepoint)(replaces T at current position)
-\# : Previous unsafe zone that was hit
-+ : Lifepoints increase by 1
(C)2024 Ryan Bluteau. All rights reserved.
Page 2 of 4
Part 1 : Recursion \ & 2 D arrays ( 7 0 marks )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!