diff --git a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java index dce25fc8fac4ce6aa58a994ef8472b2d3fae443f..f35c5b7893d0f580b2138992730dbbea115a634b 100644 --- a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java +++ b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java @@ -58,10 +58,11 @@ public class ChaosGameController implements Observer, Subject, GameController { } public void gameSelection(String selectedGame) { - if (selectedGame == null || selectedGame.trim().isEmpty()) { - AlertUtility.showErrorDialog("Invalid input", "Please select a game."); - } else { - updateChaosGame(ChaosGameDescriptionFactory.get(ChaosGameType.valueOf(selectedGame))); + try { + ChaosGameType gameType = ChaosGameType.valueOf(selectedGame); + updateChaosGame(ChaosGameDescriptionFactory.get(gameType)); + } catch (IllegalArgumentException e) { + AlertUtility.showErrorDialog("Invalid input", "Please select a valid game."); } } @@ -192,6 +193,13 @@ public class ChaosGameController implements Observer, Subject, GameController { } } + public void resetGame() { + chaosGame.resetTotalSteps(); + update(); + chaosPage.clearCanvas(); + } + + @Override public void updateJuliaValue(String partType, double value) { JuliaTransform juliaTransform = (JuliaTransform) chaosGame.getDescription().getTransforms().getFirst(); double realPart = partType.equals("real") ? value : juliaTransform.getComplex().getX(); @@ -221,12 +229,7 @@ public class ChaosGameController implements Observer, Subject, GameController { } } - public void resetGame() { - chaosGame.resetTotalSteps(); - update(); - chaosPage.clearCanvas(); - } - + @Override public void homeButtonClicked() { notifyObservers(); }