Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The MazeGame class is this entire lab. So naturally, it is very complex. We will start out with the easy parts. MazeGame Fields HEIGHT This

The MazeGame class is this entire lab. So naturally, it is very complex. We will start out with the easy parts.
MazeGame Fields
HEIGHT
This field represents the height of the maze. It should be 19.
WIDTH
This field represents the width of the maze. It should be 39.
ROW
This field is the index of the row index in the player, goal, and start arrays. Its value is 0.
COL
This field is the index of the column index in the player, goal, and start arrays. Its value is 1.
playerInput
This field is the Scanner from which you will get input from the player playing the game.
blocked
This field is a two-dimensional array of booleans. The spots with true are blocked cells in the maze. The spots with false are open cells in the maze.
visited
This field is a two-dimensional array of booleans. The spots with true are cells in the maze that the user has been to. The spots with false are cells that the user has not been to.
player
This field specifies where the player is in the maze. Index 0(ROW) is the row of the player and index 1(COL) is the column of the player.
goal
This field specifies where the goal is in the maze. Index 0(ROW) is the row of the goal and index 1(COL) is the column of the goal.
start
This field specifies where the starting location is in the maze. Index 0(ROW) is the row of the starting location and index 1(COL) is the column of the starting location.
MazeGame Methods (Simple)
MazeGame: Two-Arg
This constructor sets the playerInput field to the provided Scanner. It then calls loadMaze and passes mazeFile to it.
Since loadMaze is reading a file and may throw a FileNotFoundException, the two-arg constructor might throw the exception as well. Handle this with the throws keyword.
MazeGame: One-Arg
This constructor should call the two-arg constructor and pass it the mazefile and a new Scanner that is reading from the keyboard.
Since loadMaze is reading a file and may throw a FileNotFoundException, the two-arg constructor might throw the exception as well. Handle this with the throws keyword.
Simple Getters and Setters
The getters and setters for playerInput, playerCol, playerRow, goalCol, goalRow, startCol, and startRow are all basic getters and setters.
You will have to index into the player, start, and goal arrays using the ROW and COL constants for their corresponding setters and getters.
For example, getPlayerRow should return this.player[ROW]. The tests for these methods will not pass until the loadMaze method has been completed (think about why).
You will also need to ensure that the player, goal, and start values are not out of bounds. If the provided value is out of bounds, the field should not change.
copyTwoDimBoolArray
This is a helper method for you to use in the getters and setters for visited and blocked. Since all four of those methods require making a copy of a two dimensional boolean array, it is good for us to make that a helper method so that we do not need to duplicate code.
This method should create a new two dimensional array of booleans that is the same size as the argument passed to it.
It should then copy every value from the provided two dimensional array into the new one.
Finally, it should return the copy.
Getters and Setters for visited and blocked
The getters and setters for visited and blocked are slightly more complicated. The getters should return a copy of the arrays, not the actual arrays. The setters should set the fields to a copy of the parameter, not the actual parameter.
You should use the copyTwoDimBoolArray helper method in these getters and setters so that you do not have to duplicate your code.
prompt
This is a helper method to use in playGame to prompt the user for a move. It should do two things:
Call printMaze(). You haven't implemented that method yet, but that is okay.
Print the message:
"Enter your move (up, down, left, right, or q to quit): "
There should NOT be a newline at the end.
playerAtGoal
This is a helper method that simply returns true if the player is at the goal and false if they are not.
You can do this by comparing the player's row and column to the goal row and column.
Try to do this in a single return statement (ask if you cannot figure out how to).
valid
This is a helper method to check if a given location is legal to move to. Return true if it is valid, false if not.
Check that the provided row and column are within the bounds of the board and that the spot is not blocked.
Try to do this in a single return statement (ask if you cannot figure out how to).
visit
This helper method is extremely simple. It just sets the cell in the visited array at the provided row and column to true, indicating that the cell has been visited.
This is separated out into its own function so that, if we wanted to change how we track what is visited, we would only need to change this function, not any other part of the class. It also helps us follow the Single Responsibility Principle.Java

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

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago