java.lang.Objectgreenfoot.World
World_2048
public class World_2048
The 2048 game.
Constructor Summary | |
---|---|
World_2048()
Constructor |
Method Summary | |
---|---|
void |
act()
The act() method |
void |
clearWorld()
Erace everything |
int[] |
findEmptyCell()
Randomly selects an empty grid cell and returns its location coordinates x and y |
boolean |
gridChanged()
Did the grid change or not |
int[] |
invert(int[] array)
Invert the row or column 4 element array array |
int[] |
merge(int[] array)
This method moves non 0 array elements to the left |
void |
mergeDownWardX()
This method is called when the down arrow key is presed |
void |
mergeLeftWard2()
This method is called when the left arrow key is presed |
void |
mergeRightWard2()
This method is called when the right arrow key is presed |
void |
mergeUpWardX()
This method is called when the up arrow key is presed |
void |
newGrid()
Create the initial grid with two cells showing a 2 |
void |
newTile(int value)
Create a new tile with the specified value at a random empty cell |
void |
paintGrid()
Place the tiles on the screen |
void |
populate()
Create and display the initial grid with two cells showing a 2 |
void |
printArray(int[] array)
Usefull when testing and debugging |
void |
printGrid()
Print the grid for initial testing and debugging |
void |
saveGrid()
Save the grid to help us determine if the new grid had changed. |
int[] |
stripZeroes(int[] row)
Input is int array has GRID_SIZE elements |0|2|0|2|0| This method moves all non zero elements to the left |2|2|0|0|0| |
Methods inherited from class |
---|
addObject, getBackground, getCellSize, getColorAt, getHeight, getObjects, getObjectsAt, getWidth, numberOfObjects, removeObject, removeObjects, repaint, setActOrder, setBackground, setBackground, setPaintOrder, started, stopped |
Methods inherited from class |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public World_2048()
Method Detail |
---|
public void act()
act
in class greenfoot.World
public void clearWorld()
public int[] findEmptyCell()
public boolean gridChanged()
public int[] invert(int[] array)
public int[] merge(int[] array)
public void mergeDownWardX()
public void mergeLeftWard2()
public void mergeRightWard2()
public void mergeUpWardX()
public void newGrid()
public void newTile(int value)
public void paintGrid()
public void populate()
public void printArray(int[] array)
public void printGrid()
public void saveGrid()
public int[] stripZeroes(int[] row)