128x160 Snake Xenzia Java Game [DIRECT]

public void stop() running = false;

g.setColor(0xFFFFFF); // head highlight g.fillRect(offsetX + x[0]*CELL_SIZE + 2, offsetY + y[0]*CELL_SIZE + 2, 4,4); g.setColor(0xFF0000); g.fillArc(offsetX + foodX*CELL_SIZE, offsetY + foodY*CELL_SIZE, CELL_SIZE, CELL_SIZE, 0, 360); Score Display Draw at top: Score: 0 using small font ( Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL ). 6. Input Handling Override keyPressed(int keyCode) in Canvas: 128x160 snake xenzia java game

int action = getGameAction(keyCode); switch(action) case UP: if(direction != DOWN) nextDir = UP; break; case DOWN: if(direction != UP) nextDir = DOWN; break; case LEFT: if(direction != RIGHT) nextDir = LEFT; break; case RIGHT: if(direction != LEFT) nextDir = RIGHT; break; case FIRE: if(gameState == RUNNING) gameState = PAUSED; else if(gameState == PAUSED) gameState = RUNNING; break; public void stop() running = false; g

public void run() { while(running) { long start = System.currentTimeMillis(); if(gameState == 0) updateGame(); repaint(); long delay = 150 - (System.currentTimeMillis()-start); if(delay < 5) delay = 5; try Thread.sleep(delay); catch(Exception e) {} } } public void stop() running = false

// game data private static final int W = 15, H = 18; private int[] snakeX = new int[400]; private int[] snakeY = new int[400]; private int length, direction, nextDir; private int foodX, foodY; private int score;