Homework 04
Due 03/07/2025 by 11:55PM
Pothole Driving
Objective:
Write a game where you are a car, represented by the character
‘X’, trying to avoid pots holes in order to get home. As visibility is very
low, the car can only move one space at a time, and if the space is a pothole,
then the player loses, and the game is over. However, if they manage to reach
home, the player won, and the game is over.
Requirements:
- Functionality. (80pts)
- No Syntax, Major Run-Time, or Major Logic Errors.
(80pts*)
- *Code that cannot be compiled due to syntax errors is
nonfunctional code and will receive no points for this entire section.
- *Code that cannot be executed or tested due to major
run-time or logic errors is nonfunctional code and will receive no
points for this entire section.
- *Only 2D Arrays can be used to solve this problem. If
any other data structure such as a Linked List, Array List, etc. are
used then no points will be awarded for this entire section.
- Create the 2D Environment. (10pts)
- The environment must be represented by a Matrix (2D
Array) whose size is 10x10.
- *Any other kind of data structure, such as a Linked
List, Array List, etc., used to solve this problem will result in an automatic
80pt deduction.
- The program must then randomly select and assign exactly
5 unique cells in the matrix for the “potholes”.
- Unique meaning that if program randomly selects a cell
in the matrix that already has a pothole, then the program must keep
selecting new cells while it has not found an empty cell
(alternatively until an empty cell is selected).
- The program must then assign the car (player) to the top
left cell represented by the indices [0][0] and home to the bottom right
cell represented by the indices [9][9].
- All must apply for full credit.
- Display the Game (20pts)
- Before prompting the user, the program must show the
environment, where the player is clearly indicated by the character ‘X’
and the home space is clearly indicated by the character ‘^’.
- The display must hide all the potholes from the user’s
view, and only show the player as an ‘X’ and the home space as a ‘^’.
- All must apply for full credit.
- User Input and Display (20pts)
- The program must clearly indicate to the player how to
move their car.
- The player must be able to move the car in 8 directions,
- N, S W, E, NW, NE, SW, SE
- The player may only move one space at a time (one cell
at a time).
- Once the player has input the directions, the program
must validate the input and move the player to a space only if it is
within the bounds of the environment.
- Make sure to check for valid indices from 0 to 9.
- If the input entered is invalid, then the program must
indicate this to the player and the player’s car does not move.
- All must apply for full credit.
- Win or Lose. (20pts)
- The program must determine if the player has either won
or lost, and clearly display this to the player.
- The player wins whenever they successfully reach the
home space without encountering a pothole.
- The player automatically loses if they land on a space
with the pothole.
- All must apply for full credit.
- Replay the Game. (10pts)
- When the player has either won or lost, then the program
must ask if they would like to play again.
- If the user answers yes, then the game is reset and they
start over.
- Otherwise, the program must terminate.
- All must apply for full credit.
- Coding Style. (10pts)
- Readable Code
- Meaningful identifiers for data and methods.
- Proper indentation that clearly identifies statements
within the body of a class, a method, a branching statement, a loop
statement, etc.
- All the above must apply for full credit.
- Comments. (10pts)
- Your name in the file. (5pts)
- At least 5 meaningful comments in addition to your name.
These must describe the function of the code it is near. (5pts)
Example Dialog:
*The following Example Dialog demonstrates the interactions
between a user and ONE possible implementation of the required software’s
front-end / user interface. The software’s front-end / user interface may
be implemented in MANY different ways and will receive full credit as
long as it meets the most minimal of the above requirements. While you may use
the example dialog as a guide, it is strongly encouraged to create the
front-end / user interface in your own way. *
Key
|
Unhighlighted
Text
|
Program’s
Output
|
Highlighted Text
|
User’s Input
|
Welcome to Pothole Driving! Get home while avoiding potholes!
X_________
__________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1
in the X or 9 to quit
1
Enter either a -1,0, or 1
in the Y
1
__________
_X________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1
in the X or 9 to quit
0
Enter either a -1,0, or 1
in the Y
1
__________
__________
_X________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1
in the X or 9 to quit
-1
Enter either a -1,0, or 1
in the Y
1
OH NO! POTHOLE!
Would you like to play again?
No
Goodbye!
Finally:
- Upload the source code file or files (.JAVA File
Extension) to Homework04
- To Blackboard
- Following these instructions.
- If there are problems, then let the instructor know as
soon as possible.