Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package game 2 0 4 8 logic; import game 2 0 4 8 rendering.Board; import game 2 0 4 8 rendering.Side; import game 2 0

package game2048logic;
import game2048rendering.Board;
import game2048rendering.Side;
import game2048rendering.Tile;
import java.util.Formatter;
/** The state of a game of 2048.
* @author P. N. Hilfinger + Josh Hug
*/
public class Model {
/** Current contents of the board. */
private final Board board;
/** Current score. */
private int score;
/* Coordinate System: column x, row y of the board (where x =0,
* y =0 is the lower-left corner of the board) will correspond
* to board.tile(x, y). Be careful!
*/
/** Largest piece value. */
public static final int MAX_PIECE =2048;
/** A new 2048 game on a board of size SIZE with no pieces
* and score 0.*/
public Model(int size){
board = new Board(size);
score =0;
}
/** A new 2048 game where RAWVALUES contain the values of the tiles
*(0 if null). VALUES is indexed by (x, y) with (0,0) corresponding
* to the bottom-left corner. Used for testing purposes. */
public Model(int[][] rawValues, int score){
board = new Board(rawValues);
this.score = score;
}
/** Return the current Tile at (x, y), where 0<= x < size(),
*0<= y < size(). Returns null if there is no tile there.
* Used for testing. */
public Tile tile(int x, int y){
return board.tile(x, y);
}
/** Return the number of squares on one side of the board. */
public int size(){
return board.size();
}
/** Return the current score. */
public int score(){
return score;
}
/** Clear the board to empty and reset the score. */
public void clear(){
score =0;
board.clear();
}
/** Add TILE to the board. There must be no Tile currently at the
* same position. */
public void addTile(Tile tile){
board.addTile(tile);
}
/** Return true iff the game is over (there are no moves, or
* there is a tile with value 2048 on the board).*/
public boolean gameOver(){
return maxTileExists()||!atLeastOneMoveExists();
}
/** Returns this Model's board. */
public Board getBoard(){
return board;
}
/** Returns true if at least one space on the Board is empty.
* Empty spaces are stored as null.
**/
public boolean emptySpaceExists(){
// TODO: Task 2. Fill in this function.
return false;

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the five components of total rewards?

Answered: 1 week ago

Question

Proficiency with Microsoft Word, Excel, PowerPoint

Answered: 1 week ago