Exemplo n.º 1
0
 // This method is called once a second, and it is a good place to
 // do things like check if the snake has collided into the wall
 // or the apple.
 public void onTimer() {
   if ((snake.hasHitTail() == false) && (snake.hasHitWall(gameBoard) == false)) {
     snake.move(gameBoard);
     if (snake.hasHitApple(apple)) {
       apple.setPos(gameBoard.getRandomXCoord(), gameBoard.getRandomYCoord());
       System.out.println("It hit the apple");
       scoreBoard.incrementPlayerScore();
     }
   } else gameOver = true;
 }
Exemplo n.º 2
0
 // This method is called once a second to redraw the canvas,
 // so you can do things like draw the snake.
 public void redrawCanvas(Graphics canvas) {
   gameBoard.draw(canvas);
   scoreBoard.drawScore(canvas, gameOver);
   snake.draw(canvas);
   apple.draw(canvas);
 }