Browse Source

update

main
Justin Senn 2 years ago
parent
commit
af93a2a318
  1. 25
      src/main/java/Snake/Controller.java

25
src/main/java/Snake/Controller.java

@ -103,6 +103,31 @@ public class Controller {
snakeView.setPositions(snakeModel.getBodySegments()); snakeView.setPositions(snakeModel.getBodySegments());
} }
private void timerTick()
{
snakeModel.update();
inputHandled = true;
checkIfAppleWasEaten();
if(snakeModel.isSelfColliding())
{
messageView.setText("You Lose! Click 'Start Game' to play agaiin.");
messageView.setVisibility(true);
gameState = GameState.PlayerLosed;
timer.stop();
}
updateSnakeViewPosition();
gameView.repaint();
}
private void checkIfAppleWasEaten()
{
if(appleModel.getPosition().equals(snakeModel.getHeadPosition()))
{
score += 1;
scoreView.setText("Score: " + Integer.toString(score));
snakeModel.grow();
selectApplesPosition();
}
}
private class MoveAction extends AbstractAction private class MoveAction extends AbstractAction
{ {

Loading…
Cancel
Save