package gamepack;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class WindowGame extends BasicGame
{
	//		ATTRIBUTES
	private GameContainer	container;
	private final int		windowSizeX	= 800;
	private final int		windowSizeY	= 600;
	
	private int				state;				/*
												 * 0 = attente d'input
												 * 1 = en cours de dplacement
												 * (pas d'input possible)
												 * 2 = Fin du dplacement,
												 * gnration des nouveaux tile
												 */
	
	private Grid			grid;
	private TileListManager	GameManager;
	
	//		METHODS
	public WindowGame()
	{
		super("2C0A");
		grid = new Grid(windowSizeX, windowSizeY);
		GameManager = new TileListManager();
	}
	
	public int getWindowSizeX()
	{
		return windowSizeX;
	}
	
	public int getWindowSizeY()
	{
		return windowSizeY;
	}
	
	@Override
	public void init(GameContainer container) throws SlickException
	{
		this.container = container;
	}
	
	public void render(GameContainer container, Graphics g) throws SlickException
	{
		grid.beDrawn(g);
		GameManager.getTileList().beDrawn(g);
		
	}
	
	@Override
	public void update(GameContainer gc, int delta) throws SlickException
	{
		//Once the movement is done, we generate new tiles
		if (state == 2)
		{
			GameManager.generateNewTile();
			state = 0;
		}
		
		//if we press a touch, we manage the movement and the fusions of tiles
		if (state == 1)
		{
			state = GameManager.manageMovement(gc.getFPS());
			GameManager.manageFusion();
		}
	}
	
	@Override
	public void keyPressed(int key, char c)
	{
		//If we are waiting for an event
		if (state == 0)
		{
			state = 1;
			if (key == Input.KEY_LEFT)
				GameManager.initMovement(Direction.Left);
			else if (key == Input.KEY_RIGHT)
				GameManager.initMovement(Direction.Right);
			else if (key == Input.KEY_DOWN)
				GameManager.initMovement(Direction.Down);
			else if (key == Input.KEY_UP)
				GameManager.initMovement(Direction.Up);
			else
				state = 0; //if no interesting event were encoutered
		}
		
	}
	
	public static void main(String[] args) throws SlickException
	{
		AppGameContainer appgc;
		WindowGame wGame = new WindowGame();
		appgc = new AppGameContainer(wGame);
		appgc.setDisplayMode(wGame.getWindowSizeX(), wGame.getWindowSizeY(), false);
		appgc.setShowFPS(false);
		appgc.setVSync(true);
		appgc.start();
	}
}
@@ -322,17 +322,17 @@
 ontainer
-%09
+ 
 containe
@@ -344,34 +344,33 @@
 rivate final int
-%09%09
+ 
 windowSizeX%09= 80
@@ -364,17 +364,17 @@
 dowSizeX
-%09
+ 
 = 800;%0A%09
@@ -390,18 +390,17 @@
 inal int
-%09%09
+ 
 windowSi
@@ -402,17 +402,17 @@
 dowSizeY
-%09
+ 
 = 600;%0A%09
@@ -428,31 +428,19 @@
  int
-%09%09%09%09
+ 
 state;
-%09%09%09%09/*%0A%09%09%09%09%09%09
+ /*%0A
 %09%09%09%09
@@ -463,29 +463,24 @@
  d'input
+ 
 %0A
-%09%09%09
 %09%09%09%09%09%09
-%09%09%09
  * 1 = e
@@ -500,31 +500,16 @@
 lacement
-%0A%09%09%09%09%09%09%09%09%09%09%09%09 *
  (pas d'
@@ -530,22 +530,16 @@
 )%0A%09%09%09%09%09%09
-%09%09%09
-%09%09%09
  * 2 = F
@@ -555,31 +555,16 @@
 acement,
-%0A%09%09%09%09%09%09%09%09%09%09%09%09 *
  gnratio
@@ -589,22 +589,16 @@
 e%0A%09%09%09%09%09%09
-%09%09
-%09%09%09%09
  */%0A%09%0A%09p
@@ -608,19 +608,17 @@
 ate Grid
-%09%09%09
+ 
 grid;%0A%09p
@@ -639,17 +639,17 @@
 tManager
-%09
+ 
 GameMana

Format attributs