Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; import java.io . FileNotFoundException; public class MazeGame { / / Constants for array indices private static final int ROW = 0 ; private

import java.util.Scanner;
import java.io.FileNotFoundException;
public class MazeGame {
// Constants for array indices
private static final int ROW =0;
private static final int COL =1;
// Fields
private final int HEIGHT =19;
private final int WIDTH =39;
private final int playerInput;
private final boolean[][] blocked;
private final boolean[][] visited;
private final int[] player;
private final int[] goal;
private final int[] start;
// Constructors
public MazeGame(Scanner scanner) throws FileNotFoundException {
this.playerInput = scanner.nextInt();
// Call loadMaze here
}
public MazeGame(String mazeFile) throws FileNotFoundException {
this(new Scanner(System.in)); // Assume reading from keyboard
}
// Getters and Setters
public int getPlayerInput(){
return playerInput;
}
public int getPlayerRow(){
return player[ROW];
}
public void setPlayerRow(int row){
if (row >=0 && row < HEIGHT){
player[ROW]= row;
}
}
public int getPlayerCol(){
return player[COL];
}
public void setPlayerCol(int col){
if (col >=0 && col < WIDTH){
player[COL]= col;
}
}
public int getGoalRow(){
return goal[ROW];
}
public void setGoalRow(int row){
if (row >=0 && row < HEIGHT){
goal[ROW]= row;
}
}
public int getGoalCol(){
return goal[COL];
}
public void setGoalCol(int col){
if (col >=0 && col < WIDTH){
goal[COL]= col;
}
}
// Other methods (not fully implemented)
private boolean[][] copyTwoDimBoolArray(boolean[][] array){
// Implementation of copying a two-dimensional boolean array
//(Left as an exercise for you)
return null;
}
private void printMaze(){
// Implementation of printing the maze
//(Left as an exercise for you)
}
private void loadMaze(String mazeFile) throws FileNotFoundException {
// Implementation of loading maze from file
//(Left as an exercise for you)
}
private void prompt(){
printMaze();
System.out.print("Enter your move (up, down, left, right, or q to quit): ");
}
private boolean playerAtGoal(){
return player[ROW]== goal[ROW] && player[COL]== goal[COL];
}
private boolean valid(int row, int col){
return row >=0 && row < HEIGHT && col >=0 && col < WIDTH && !blocked[row][col];
}
private void visit(int row, int col){
visited[row][col]= true;
}
}

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

Students also viewed these Databases questions