Snake Xenzia Game . Jar . 128x160 .: Java
public SnakeCanvas() snake = new Vector(); direction = RIGHT; nextDirection = RIGHT; initGame(); gameThread = new Thread(this); gameThread.start();
} public class Point public int x, y; public Point(int x, int y) this.x = x; this.y = y;
protected void paint(Graphics g) Graphics.LEFT); if (!running) Graphics.VCENTER); Java Snake Xenzia Game . Jar . 128x160 .
public void run() { while (true) { if (running) gameTick(); repaint(); try Thread.sleep(200); catch (Exception e) {} } }
private void gameTick() newHead.x >= COLS public SnakeCanvas() snake = new Vector(); direction =
protected void keyPressed(int keyCode) int action = getGameAction(keyCode); if (action == UP && direction != DOWN) nextDirection = UP; else if (action == DOWN && direction != UP) nextDirection = DOWN; else if (action == LEFT && direction != RIGHT) nextDirection = LEFT; else if (action == RIGHT && direction != LEFT) nextDirection = RIGHT;
private void initGame() snake.removeAllElements(); snake.addElement(new Point(8, 10)); snake.addElement(new Point(7, 10)); snake.addElement(new Point(6, 10)); score = 0; spawnFood(); public SnakeCanvas() snake = new Vector()
private static final int UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4;