Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement public void printBoard(String direction) Call public int[][] getGrid() to save a copy of the 2D array. Make sure you understand how this method works

Implement

public void printBoard(String direction)
  1. Call public int[][] getGrid() to save a copy of the 2D array. Make sure you understand how this method works and what it does.
  2. Make a function call to public boolean move(String direction) by passing the direction from the parameter. This will perform one step of action which makes changes to the current grid.
  3. Print out the private member variable grid like method 1. (You can even do this by calling the method printBoard()).
  4. Call public void setGrid(int [][] gridIn) and pass in the saved 2D array from step 1 to reset the board to its original state. The methods: public void setGrid(int[][] newGrid) { for (int r = 0; r < this.grid.length; r++) { for (int c = 0; c < this.grid[r].length; c++) { this.grid[r][c] = newGrid[r][c]; } } } public int[][] getGrid() { int[][] gridCopy = new int[this.GRID_SIZE][this.GRID_SIZE]; for (int r = 0; r < this.grid.length; r++) { for (int c = 0; c < this.grid[r].length; c++) { gridCopy[r][c] = this.grid[r][c]; } } return gridCopy; }

    public boolean move(String direction) { /* if canMove is false, exit and don't move tiles */ if (!this.canMove(direction)) return false;

    /* move in relationship to the direction passed in */ if (direction.equals(this.UP)) { this.moveUp(); } else if (direction.equals(this.RIGHT)) { this.moveRight(); } else if (direction.equals(this.DOWN)) { this.moveDown(); } else if (direction.equals(this.LEFT)) { this.moveLeft(); } else { return false; }

    return true; } public void printBoard() { for(int row=0;row

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago