/** Resets the game's variables to their default states and starts a new game. */ private void resetGame() { /* * Reset the score statistics. (Note that nextFruitPoints is reset in * the spawnFruit function later on). */ this.score = 0; this.fruitsEaten = 0; /* * Reset both the new game and game over flags. */ this.isNewGame = false; this.isGameOver = false; /* * Create the head at the center of the board. */ Point head = new Point(BoardPanel.COL_COUNT / 2, BoardPanel.ROW_COUNT / 2); /* * Clear the snake list and add the head. */ snake.clear(); snake.add(head); /* * Clear the board and add the head. */ board.clearBoard(); board.setTile(head, TileType.SnakeHead); /* * Clear the directions and add north as the * default direction. */ directions.clear(); directions.add(Direction.North); /* * Reset the logic timer. */ logicTimer.reset(); /* * Spawn a new fruit. */ spawnFruit(); }