Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, you are to create a program in Java that implements the Mouse Race game. The game will proceed as follows: You should

For this assignment, you are to create a program in Java that implements the Mouse Race game. The game will proceed as follows: You should first display header information (course name, semester, name, assignment#) and the message: WELCOME TO THE MOUSE RACE GAME.

Then enter the game loop. In the game loop, you will repeat the following until the game ends:

o Display the maze. The maze is a 10x10 grid of characters, with a wall around it (so total size is 12x12). This maze should look exactly like the one in the sample output (see last section), except the location of the mouse might be different depending on which moves were made. Represent the mouse as % and the cheese as $. The mouse will always begin in the upper left corner and the cheese will always be in the lower right corner. o Check if the game ended. The game ends when the location of the mouse is the same as the location of the cheese. If the game ends, quit the loop. o Display the current score. The score is initially 0. Each move costs 1 point (subtract 1 from the score). Getting the cheese is +100 points.

o Prompt for direction. The directions are n for north, s for south, w for west, and e for east. If the move is chosen and there is no wall there, change the location of the mouse to the corresponding location. Otherwise (if the mouse bumps into a wall), the location of the mouse will not change and you should display the message You cannot move there!.

Once the game ends, display the message GAME OVER! MOUSE GOT THE CHEESE! and Your score was ..., replacing the with the actual score after the game ended. Program Design Requirements You should have a single class called MouseRace. Inside this class you will have instance data declarations (i.e. object variables) that correspond to things you need to keep track of in the game: the location of the mouse (row and column), the location of the cheese (row and column), the maze itself (2-D array of chars), and the score.

You should have at least 6 methods: 1. main: should only display the header information and then create a new MouseRace object. All of the game functionality will be implemented in the constructor. 2. The constructor method: implements the game - initializes the instance data, displays the intro message, and then enters the game loop. The constructor will call other methods to print the board, check for a game end, etc. 3. gameWon: should return true if the game was won and false otherwise. 4. printMaze: should print the maze (including the mouse and cheese). 5. makeMove: should attempt to make the move to the specified row, column. 6. parseCmd: should accept a string and call the makeMove method with the appropriate parameter values. For example, if the command is n, then it should call makeMove(mouseLocRow-1, mouseLocCol).

Sample Output would be:

**************************************

*** WELCOME TO THE MOUSE RACE GAME ***

**************************************

############

#% ####### #

## ###### #

## ## ##

# ### # ##

# #### # ##

# # # ## ##

# ## # ## ##

# # # ## ##

## # # ##

# #### $#

############

Your current score: 0

Select a move direction (n/s/w/e):n

You cannot move there!

############

#% ####### #

## ###### #

## ## ##

# ### # ##

# #### # ##

# # # ## ##

# ## # ## ##

# # # ## ##

## # # ##

# #### $#

############

Your current score: -1

Select a move direction (n/s/w/e):e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions