Class World_2048

java.lang.Object
  extended by greenfoot.World
      extended by World_2048

public class World_2048
extends greenfoot.World

The 2048 game.

Version:
2 August 2014
Author:
M. Kadri

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

World_2048

public World_2048()
Constructor

Method Detail

act

public void act()
The act() method

Overrides:
act in class greenfoot.World

clearWorld

public void clearWorld()
Erace everything


findEmptyCell

public int[] findEmptyCell()
Randomly selects an empty grid cell and returns its location coordinates x and y


gridChanged

public boolean gridChanged()
Did the grid change or not


invert

public int[] invert(int[] array)
Invert the row or column 4 element array array


merge

public int[] merge(int[] array)
This method moves non 0 array elements to the left


mergeDownWardX

public void mergeDownWardX()
This method is called when the down arrow key is presed


mergeLeftWard2

public void mergeLeftWard2()
This method is called when the left arrow key is presed


mergeRightWard2

public void mergeRightWard2()
This method is called when the right arrow key is presed


mergeUpWardX

public void mergeUpWardX()
This method is called when the up arrow key is presed


newGrid

public void newGrid()
Create the initial grid with two cells showing a 2


newTile

public void newTile(int value)
Create a new tile with the specified value at a random empty cell


paintGrid

public void paintGrid()
Place the tiles on the screen


populate

public void populate()
Create and display the initial grid with two cells showing a 2


printArray

public void printArray(int[] array)
Usefull when testing and debugging


printGrid

public void printGrid()
Print the grid for initial testing and debugging


saveGrid

public void saveGrid()
Save the grid to help us determine if the new grid had changed.


stripZeroes

public 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|