diff options
author | Adam NAILI | 2018-02-03 00:04:58 +0100 |
---|---|---|
committer | Adam NAILI | 2018-02-03 00:04:58 +0100 |
commit | 22ca9ec1a0dc852a4e350875b71d9d716ea455dc (patch) | |
tree | 0269bd4a0f49f73a98298bd2dea337ee50e00bab /src/main/java | |
parent | 960662d7bf433d7bbfb93bf7ca58a85645110fe5 (diff) | |
download | wallj-22ca9ec1a0dc852a4e350875b71d9d716ea455dc.tar.gz |
Refactoring Game
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/context/Game.java | 39 |
1 files changed, 15 insertions, 24 deletions
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 { | |||
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | private void handleEvents(Context context){ | 77 | private void handleEvents(Context context) { |
78 | if (Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent()){ | 78 | if (Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent()) { |
79 | context.getGame().setOver(); | 79 | context.getGame().setOver(); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | if (Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent()){ | 82 | if (Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent()) { |
83 | 83 | if (currentStage.isCleared()) { | |
84 | if (context.getGame().hasNextBoard()) { //continue | ||
85 | context.getGame().nextStage(); | ||
86 | } else { //no more board so game over => exiting | ||
87 | setOver(); | ||
88 | } | ||
89 | return; | ||
90 | } | ||
91 | retryStage(); | ||
84 | } | 92 | } |
85 | } | 93 | } |
94 | |||
95 | |||
86 | /** | 96 | /** |
87 | * @param context the current context | 97 | * @param context the current context |
88 | * @return a list of new events | 98 | * @return a list of new events |
89 | */ | 99 | */ |
90 | @Override | 100 | @Override |
91 | public List<Event> update(Context context) { | 101 | public List<Event> update(Context context) { |
92 | boolean isConfirmOrder = Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent(); | 102 | handleEvents(context); |
93 | boolean isQuitGameOrder = Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent(); | ||
94 | boolean isStageCleared = Events.findFirst(context.getEvents(), StageClearedEvent.class).isPresent(); | ||
95 | |||
96 | Game currentGame = context.getGame(); | ||
97 | if (isQuitGameOrder) { | ||
98 | currentGame.setOver(); | ||
99 | } else { | ||
100 | if (isConfirmOrder) { | ||
101 | if (isStageCleared) { | ||
102 | if (currentGame.hasNextBoard()) { //continue | ||
103 | currentGame.nextStage(); | ||
104 | } else { //no more board so game over => exiting | ||
105 | currentGame.setOver(); | ||
106 | } | ||
107 | } else {//retry | ||
108 | currentGame.retryStage(); | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | return currentStage.update(context); | 103 | return currentStage.update(context); |
113 | } | 104 | } |
114 | 105 | ||