Question: Hello this is for a simple 2d array pacman game, so no gui nor pictures I mostly need help with these 3 question(methods) since I

Hello this is for a simple 2d array pacman game, so no gui nor pictures

I mostly need help with these 3 question(methods) since I barely started doing 2d arrays and i am still learning to do them

initializeGrid(): This method will print a fresh new grid with the pac- man located in the middle of the grid and the rest of the grid will containcookies .. Except the boundaries of the grid. Your maze shall have four

boundaries i.e., north, south, east, and west. The boundaries are repre-

sented with an X. Each boundary has a gate in the middle that allows

the pacman to communicate to the opposite gate.

updateGrid(): will happen after the selection of moving a,s,d or w is done. Since these four options will move to west, south, east, or north, then you need to update the grid. The way to do this is by passing the x-coordinate and the y-coordinate as arguments to this method. The method then, will update the new position of the pacman (that is, the x and y coordinate from the arguments). Here is where the previous x and y position of the pacman will disappear (which is now a blank space ). This method will reflect the new position of the pacman in the grid in case it moved. This method will also reflect the number of cookies consumed.

checkBoundaries(): Before moving the pacman to the new position, this method will check if is possible according the current coordinates. In case is a valid movement, the method will return true. In case the movement is invalid, due to a boundary or through something else, then your method will return false.

Here is what i have done until now(please excuse my super messy code)

import java.util.Scanner; public class Engine{ public static void main(String [] args){ String[][] grid = new String[10][10]; int y = 5; int x = 5; initializeGrid(grid); grid[y][x] = "e"; Scanner input = new Scanner(System.in); while(true){ print(grid); String option = input.nextLine(); if(option.equals("w")){ // code goes here y--; } else if(option.equals("a")){ // code goes here x--; } else if(option.equals("s")){ // code goes here y++; } else if(option.equals("d")){ // code goes here x++; } grid[y][x] = "e"; print(grid); // more code goes here } } public static void print(String[][] a){ for(int row = 0; row < a.length; row++){ for(int col = 0; col < a[row].length; col++){ System.out.print(a[row][col]+" "); } System.out.println(); } } // Methods below here public static void initializeGrid(String[][]a){ for(int row = 0; row < a.length; row++){ for(int col = 0; col < a[row].length; col++){ a[row][col]= "."; } } } public static void checkBoundaries(){ boolean solid; } public static void updateGrid(int x ,int y,String[][] grid){ grid[y][x] = " "; //printStringArray(grid); } }

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!