- #1
FallArk
- 127
- 0
The instructions are given below:
I'm thinking about using array to print out the board and then assign different values to display the bomb and where the user is. Then use a switch statement to make all the potential if statements i will use much cleaner. Am I on the right track at least?
But I don't know how to code it that when the "U" moves and turn the previous location to a "*". I also don't know how to check if the user win or lose.
PROBLEM STATEMENT: Write a generalized program that mimics the following sample runs.
Be sure not to hard code the solutions; the program must work in the general case (what is
the general case here?). User input is shown as underlined.
In this game, you must survive a certain number of moves (a random number between 5 and
12). You survive a move by moving on to a square that does not contain a bomb (‘*’). You can
move North, South, East or West. Your position is shown by the letter “U”. Each time you
move from a spot, it turns into a bomb. A random number of bombs (between 3 and 7) are
automatically placed when the game starts. If you fall off the edge, you lose! If you get blown
up, you lose!
Example run 1:
SURVIVE 8 MORE MOVES!
_ _ _ _ _
_ _ * _ _
_ _ _ _ U
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): W
SURVIVE 7 MORE MOVES!
_ _ _ _ _
_ _ * _ _
_ _ _ U *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): W
SURVIVE 6 MORE MOVES!
_ _ _ _ _
_ _ * _ _
_ _ U * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): W
SURVIVE 5 MORE MOVES!
_ _ _ _ _
_ _ * _ _
_ U * * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): W
SURVIVE 4 MORE MOVES!
_ _ _ _ _
_ _ * _ _
U * * * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): N
SURVIVE 3 MORE MOVES!
_ _ _ _ _
U _ * _ _
* * * * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): N
SURVIVE 2 MORE MOVES!
U _ _ _ _
* _ * _ _
* * * * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): E
SURVIVE 1 MORE MOVES!
* U _ _ _
* _ * _ _
* * * * *
_ _ _ * _
* _ _ _ *
Enter direction (N/S/E/W): E
*** YOU WIN! ***
Example run 2:
SURVIVE 5 MORE MOVES!
U _ _ _ _
_ _ _ _ _
_ * _ _ _
_ _ _ _ _
_ _ * _ *
Enter direction (N/S/E/W): N
YOU FELL OFF THE BOARD!
*** YOU LOSE! ***
Example run 3:
SURVIVE 11 MORE MOVES!
_ _ * _ U
_ _ _ * _
_ _ * _ _
_ _ _ _ *
_ _ * _ _
Enter direction (N/S/E/W): W
SURVIVE 10 MORE MOVES!
_ _ * U *
_ _ _ * _
_ _ * _ _
_ _ _ _ *
_ _ * _ _
Enter direction (N/S/E/W): W
BANG! You're dead!
*** YOU LOSE! ***
I'm thinking about using array to print out the board and then assign different values to display the bomb and where the user is. Then use a switch statement to make all the potential if statements i will use much cleaner. Am I on the right track at least?
But I don't know how to code it that when the "U" moves and turn the previous location to a "*". I also don't know how to check if the user win or lose.