Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A java Programing question; I want to create the following game; the maze grid is m . . . . . . b . .

A java Programing question;

I want to create the following game;

the maze grid is

m . . . .

. . b . .

. . . . .

b b . . .

. . . . b

. . . . .

m (mouse) at (0,0)- the starting position of the mouse

6 rows and 5 columns

number of boxes - 4

number of cheese - 2

cheese positions ( 3,0) and (1,2)

the remaining boxes are traps.

Add the following to enable moving along the Maze

count variables: one to track how many cheese crumbs Mouse has collected, and

one to track how many moves Mouse has made moving through the grid

Create 1 boolean instance variable to indicate that Mouse is still loose and roaming the Maze.

Create a method void move(char direction). This will move Mouse in the direction

specified. The following characters will represent the movements along the grid

  • w up
  • s down
  • a - left
  • d - right

Throw appropriate IndexOutOfBoundsException for moving off the grid. If the move is

valid, then process the move using the following helper method.

Create a method private void processMove(char direction), which determines the next outcome of the game based on the direction from the move() method.

  • A move onto a valid path (.) increases the number of moves Mouse has made.
  • A move onto a b can either:
  • increase Mouses cheese collection by 1 (as well as her move count), or
  • end the game (and increase her move count) by calling the endTerror() method you will implement in the next phase.

Update the grid to show Mouses movements. If she moves, replace her last position in the

grid with . and set the char at the new position to m. If Mouse collects a cheese, replace the

b with m to show where she currently is. When she moves from that location, update the

grid accordingly.

Game ending condition

Mouse has to keep scouring the Maze for boxes of cheese crumbs. She only stops when any of these happens:

  • Mouse has collected all the cheese in the Maze, or
  • Mouse is caught by a trap in a box.

To do this:

Create method private void endTerror(), that changes the value of the variable indicating

that Mouse is still roaming the Maze.

Create a method boolean isRoamingMaze() that tells the outside world if Mouse is still on

the loose in the Maze!

Update the processMove method to check if the game is over, and calling endTerror to

end the game.

Extracting data

First, create your own Exception type named DataDoesNotExistException. For this class,

implement only a constructor that receives a String message.

Then, add two methods to your BigMaze class:

ASSIGNMENT 2: Multidimensional arrays, Files and Exceptions

COMP 1020 Winter 2020

  • char [ ] extractRow(int rowNum) that extracts the row specified by the passed

integer. 0 will fetch the first row, 1 the second (index-by-zero rules).

  • char [ ] extractColumn(int colNum), which extracts a single column, much like extract row.

Both methods should throw a DataDoesNotExistException when passed a row or column number that does not exist in your Maze grid.

For example, if your Maze is a 3x3 grid and the extractRow() method is passed a -1

Exception Thrown: DataDoesNotExistException: BigMaze grid does not have a row index of -1

Write a toString with Mouses stats!

When Mouses reign of terror is done in a Big Maze, update the output of your toString()

method to include one of the following on a new line in addition printing out the map. For

an extra, optional challenge: watch out for singular and plural tenses.

Sample output:

Mouse outsmarted the exterminators and got away.

Moves 5

cheese collected 2

traps escaped - 3

Mouses reign of terror came to an end when she met a trap instead of cheese.

Moves 10

cheese collected 1

If the game is still running, print out just the map, as described in Phase 1.

Hint: You will know if Mouse was captured if she is no longer roaming the Maze and somehow there are still cheese crumbs left.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago