Question: public final int GRID_SIZE; // my question: How to make a 2D array grid made of asterisks and spaces. NOTE that pacman consumes an asterik

public final int GRID_SIZE;

// my question: How to make a 2D array grid made of asterisks and spaces. NOTE that pacman consumes an asterik when the symbol char P touches it. I've made a 2D array of int rows and cols but I've rarely coded with chars so I'm quite confused.

// String Representation of Pac-man Game Board

private char[][] grid;

// Record of where Pac-man has visited

private boolean[][] visited;

Instruction write up just in case:

Getters and Setters to be implemented:

// Constructor

public PacCharacter(int row, int col, char appearance)

// Getter for variable row

public int getRow()

// Getter for variable col

public int getCol()

// Getter for variable appearance

public char getAppearance()

// Setter for row and col

public void setPosition(int row, int col)

// Setter for Appearance characters

public void setAppearance(char appearance)

ASSUMPTIONS YOU MAY MAKE:

  1. The input variables validities are already checked in the outside program (Your Board.java), thus you do not need to worry about invalid inputs.

public final int GRID_SIZE;

// String Representation of Pac-man Game Board

private char[][] grid;

// Record of where Pac-man has visited

private boolean[][] visited;

// Pac-man that user controls

private PacCharacter pacman;

// 4 Ghosts that controlled by the program

private PacCharacter[] ghosts;

// Score Recorded for the gamer

private int score;

GRID_SIZE is the side length of the grid in Pac-Man Game. The Pac-Man grid should be a square of size GRID_SIZE x GRID_SIZE.

grid is a 2D-array of type char, which represents the char representations of the slots in the Pac-Man board. The representations for different scenario is described in the following chart:

char Representation

Slot Information

' ' (Single Whitespace)

Empty Slot

'*' (Asterisk)

Slot which has a Pac-Dot in it

'P'

Slot where only the Pac-Man is at

'G'

Slot where one or more Ghosts are at (Multiple Ghosts in the same slot is still represented by one char G)

'X'

Slot where the Pac-Man and one or more Ghosts are at (GAME OVER state, Pac-Man is consumed by one or more Ghost)

visited is a 2D-array of type boolean, which represents whether the Pac-Man has visited the slot or not. This is a simplified solution of recording Pac-Dots information in the grid, since in a new game, slots that Pac-Man has visited will not contain Pac-Dots, and slots that Pac-Man has never visited will definitely contain Pac-Dots (because Ghosts do not consume Pac-Dots). Thus, if Pac-Man has visited a coordinate, the value of the slot at that coordinate will be true; otherwise, the value of the slot at that coordinate will be false.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!