Question: I understand the concepts but I need help implementing the code. Just a basic building block to get me going // Implement try catch and

I understand the concepts but I need help implementing the code. Just a basic building block to get me going

// Implement try catch and printWriter

// Contains an overloaded constructor that is able to initialize a board from a file
Class Board { public Board(int size) { // Initialize instance variables this.GRID_SIZE = size; this.grid = new char[GRID_SIZE][GRID_SIZE]; this.visited = new boolean[GRID_SIZE][GRID_SIZE]; this.score = 0; pacman = new PacCharacter(GRID_SIZE/2, GRID_SIZE/2, 'P'); ghosts = new PacCharacter[4]; ghosts[0] = new PacCharacter( 0, 0, 'G'); ghosts[1] = new PacCharacter( 0, GRID_SIZE-1, 'G'); ghosts[2] = new PacCharacter(GRID_SIZE-1, 0, 'G'); ghosts[3] = new PacCharacter(GRID_SIZE-1, GRID_SIZE-1, 'G'); setVisited(GRID_SIZE/2, GRID_SIZE/2); refreshGrid(); } public Board(String inputBoard) throws Exception { try { // body } catch (parameter) { throw } /* There are two conditions under which we want to save a game:
  1. When the user enters q, in which case the game is saved and the program is exited

  2. When the game ends (when Pac-Man gets caught). */

Note: this means that an output file should be (over)written every time the game is played.

public void saveBoard(String outputBoard) throws Exception{ // TODO }

}

Class Game Manager {

  • Initializes the board

    • Either by creating a new game

    • Or reading it from a file

  • Implements the play functionality

    • Take user input

    • If valid, execute move

    • Evaluate game state (isGameOver)

* Purpose: Constructs a GameManager to Generate new game * Parameter: int boardSize - Integer player want to set as board size. * String outputBoard - the filename the Board will be saved as. * Random random - the Random generator player wanna use. * */ GameManager(int boardSize, String outputBoard) throws Exception { // TODO }

/* * GameManager Constructor * * Purpose: Constructs a GameManager to Load a saved game. * Parameter: String inputBoard - the filename the Board will be inputted. * String outputBoard - the filename the Board will be saved as. * Random random - the Random generator player wanna use. * */ GameManager(String inputBoard, String outputBoard) throws Exception { // TODO }

I need some help understanding the implementation of these concepts.

Example: board using asterik characters as dots, P as pacman, and G as ghosts.

I understand the concepts but I need help implementing the code. Just

Welcome to Pac-Man Loading Board from Pac-Man.board Controls: w - Move Up S -Move Down a -Move Left d -Move Right q-Quit and Save Board Score: 70 * k * k GP * Welcome to Pac-Man Loading Board from Pac-Man.board Controls: w - Move Up S -Move Down a -Move Left d -Move Right q-Quit and Save Board Score: 70 * k * k GP *

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!