Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Created September 12, 2018 05:27
Show Gist options
  • Save dulimarta/9988c19badaa59979cfdc0ff3a388240 to your computer and use it in GitHub Desktop.
Save dulimarta/9988c19badaa59979cfdc0ff3a388240 to your computer and use it in GitHub Desktop.
The interface of 1024 game.
package game1024;
import game1024.Cell;
import java.util.ArrayList;
/**
* Created by Hans Dulimarta
*/
public interface NumberSlider {
/**
* Reset the game logic to handle a board of a given dimension
*
* @param height the number of rows in the board
* @param width the number of columns in the board
* @param winningValue the value that must appear on the board to
* win the game
* @throws IllegalArgumentException when the winning value is not power of two
* or negative
*/
void resizeBoard (int height, int width, int winningValue);
/**
* Remove all numbered tiles from the board and place
* TWO non-zero values at random location
*/
void reset();
/**
* Set the game board to the desired values given in the 2D array.
* This method should use nested loops to copy each element from the
* provided array to your own internal array. Do not just assign the
* entire array object to your internal array object. Otherwise, your
* internal array may get corrupted by the array used in the JUnit
* test file. This method is mainly used by the JUnit tester.
* @param ref a 2D array whose dimension matches the height and width given in
* the resizeBoard() call
*/
void setValues(final int[][] ref);
/**
* Insert one random tile into an empty spot on the board. The top left
* corner is at row 0 and column 0. Column number goes up from left to right
* row number goes up from top to bottom.
*
* @return a Cell object with its row, column, and value attributes
* initialized properly
*
* @throws IllegalStateException when the board has no empty cell
*/
Cell placeRandomValue();
/**
* Slide all the (non-empty) tiles in the board in the requested direction
* @param dir move direction of the tiles
*
* @return true when the board changes
*/
boolean slide (SlideDirection dir);
/**
*
* @return an arraylist of Cells. Each cell holds the (row,column) and
* value of a tile
*/
ArrayList<Cell> getNonZeroCells();
/**
* Return the current state of the game
* @return one of the possible values of GameStatus enum
*/
GameStatus getStatus();
/**
* Undo the most recent action, i.e. restore the board to its previous
* state. Calling this method multiple times will ultimately restore
* the gam to the very first initial state of the board holding two
* random values. Further attempt to undo beyond this state will throw
* an IllegalStateException.
*
* @throws IllegalStateException when undo is not possible
*/
void undo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment