/** The act method is called by the GameScreen to perform the action in the ScreenState. */ public void act() { if (backToMenuButton.wasClicked()) { // go to start state gameScreen.setState(gameScreen.getStartState()); } String key = gameScreen.getKey(); if (arrowLeftButton.wasClicked() || (key != null && key.equals("left"))) { currentHighscoreLevel--; if (currentHighscoreLevel < 1) { currentHighscoreLevel = gameScreen.getNumberOfLevels(); } // reload this state gameScreen.setState(gameScreen.getHighscoreState()); } if (arrowRightButton.wasClicked() || (key != null && key.equals("right"))) { currentHighscoreLevel++; if (currentHighscoreLevel > gameScreen.getNumberOfLevels()) { currentHighscoreLevel = 1; } // reload this state gameScreen.setState(gameScreen.getHighscoreState()); } }
/** The act method is called by the GameScreen to perform the action in the ScreenState. */ public void act() { // handle key events String key = Greenfoot.getKey(); if (key != null) { handleKeyPress(key); } // handle mouse events if (startGameButton.wasClicked()) { handleStartGame(); } if (highscoreButton != null && highscoreButton.wasClicked()) { // Set the new screen state gameScreen.setState(gameScreen.getHighscoreState()); } }