Question: I have the following java code, complete the empty methods. package maze; import java.io . FileNotFoundException; import java.util.Scanner; public class MazeGame { public final static
I have the following java code, complete the empty methods. package maze;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class MazeGame
public final static int HEIGHT ;
public final static int WIDTH ;
private final static int COL ;
private final static int ROW ;
private Scanner playerInput;
private boolean blocked;
private boolean visited;
private int player;
private int goal;
private int start;
public MazeGameString mazeFile, Scanner playerInput throws FileNotFoundException
this.playerInput playerInput;
loadMazemazeFile;
public MazeGameString mazeFile throws FileNotFoundException
thismazeFile new ScannerSystemin;
public void playGame
public void printMaze
for int row ; row HEIGHT; row
for int col ; col WIDTH; col
if row getPlayerRow && col getPlayerCol
System.out.printP;
else if row getGoalRow && col getGoalCol
System.out.printG;
else if blockedrowcol
System.out.print#;
else
System.out.print;
System.out.println;
public int getPlayerRow
return playerROW;
public int getPlayerCol
return playerCOL;
public int getGoalRow
return goalROW;
public int getGoalCol
return goalCOL;
public int getStartRow
return startROW;
public int getStartCol
return startCOL;
public boolean getBlocked
return copyTwoDimBoolArrayblocked;
public boolean getVisited
return copyTwoDimBoolArrayvisited;
public Scanner getPlayerInput
return this.getPlayerInput;
public void setPlayerRowint row
if row && row HEIGHT
playerROW row;
public void setPlayerColint col
if col && col WIDTH
playerCOL col;
public void setGoalRowint row
if row && row HEIGHT
goalROW row;
public void setGoalColint col
if col && col WIDTH
goalCOL col;
public void setStartRowint row
if row && row HEIGHT
startROW row;
public void setStartColint col
if col && col WIDTH
this.startCOL col;
public void setBlockedboolean blocked
blocked copyTwoDimBoolArrayblocked;
public void setVisitedboolean visited
visited copyTwoDimBoolArrayvisited;
public void setPlayerInputScanner playerInput
private boolean copyTwoDimBoolArrayboolean arrayToCopy
int rows arrayToCopy.length;
int cols arrayToCopylength;
boolean copy new booleanrowscols;
for int i ; i rows; i
for int j ; j cols; j
copyij arrayToCopyij;
return copy;
private void prompt
printMaze;
System.out.printEnter your move up down, left, right, or q to quit: ;
private boolean playerAtGoal
return playerROW goalROW && playerCOL goalCOL;
private boolean validint row, int col
return row && row HEIGHT && col && col WIDTH && blockedrowcol;
private void visitint row, int col
visitedrowcol true;
private void loadMazeString mazeFile
private boolean makeMoveString move
makeMove needs to return true if the game has been won and false every time it's not won, the move is not asked for here but instead provided as a parameter, interpret the user's input from q to quit, l to left, u to up d to down, and r to right. If it is q then quit the game, elsewise check if the move is valid using the method and update the player position, once done mark the new cell as visited.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
