From 22ca9ec1a0dc852a4e350875b71d9d716ea455dc Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sat, 3 Feb 2018 00:04:58 +0100 Subject: Refactoring Game --- src/main/java/fr/umlv/java/wallj/context/Game.java | 39 +++++++++------------- 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/main/java/fr/umlv/java/wallj/context/Game.java b/src/main/java/fr/umlv/java/wallj/context/Game.java index 56e380f..842d484 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java @@ -74,41 +74,32 @@ public final class Game implements Updateable { } - private void handleEvents(Context context){ - if (Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent()){ + private void handleEvents(Context context) { + if (Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent()) { context.getGame().setOver(); return; } - if (Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent()){ - + if (Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent()) { + if (currentStage.isCleared()) { + if (context.getGame().hasNextBoard()) { //continue + context.getGame().nextStage(); + } else { //no more board so game over => exiting + setOver(); + } + return; + } + retryStage(); } } + + /** * @param context the current context * @return a list of new events */ @Override public List update(Context context) { - boolean isConfirmOrder = Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent(); - boolean isQuitGameOrder = Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent(); - boolean isStageCleared = Events.findFirst(context.getEvents(), StageClearedEvent.class).isPresent(); - - Game currentGame = context.getGame(); - if (isQuitGameOrder) { - currentGame.setOver(); - } else { - if (isConfirmOrder) { - if (isStageCleared) { - if (currentGame.hasNextBoard()) { //continue - currentGame.nextStage(); - } else { //no more board so game over => exiting - currentGame.setOver(); - } - } else {//retry - currentGame.retryStage(); - } - } - } + handleEvents(context); return currentStage.update(context); } -- cgit v1.2.3