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();
private void gameTick()
private static final int UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4; Java Snake Xenzia Game . Jar . 128x160 .
} public class Point public int x, y; public Point(int x, int y) this.x = x; this.y = y; private void initGame() snake
private Vector snake; // stores Points private int direction, nextDirection; private Point food; private boolean running; private int score; private Thread gameThread; private void initGame() snake.removeAllElements()
public void pauseApp() {} public void destroyApp(boolean unconditional) {} } import javax.microedition.lcdui.*; import java.util.*; public class SnakeCanvas extends Canvas implements Runnable { private static final int WIDTH = 128; private static final int HEIGHT = 160; private static final int CELL_SIZE = 8; private static final int COLS = WIDTH / CELL_SIZE; // 16 private static final int ROWS = HEIGHT / CELL_SIZE; // 20