diff options
author | Adam NAILI | 2018-01-14 15:20:19 +0100 |
---|---|---|
committer | Adam NAILI | 2018-01-14 15:20:19 +0100 |
commit | b54e20222747a12621cdc31e6ee78f841726d14c (patch) | |
tree | 1424eb03f87ee1026298a7e5020ef4cd9777d2be | |
parent | f6d2592328941b8b6510f82a447d0984c9e56c05 (diff) | |
download | wallj-b54e20222747a12621cdc31e6ee78f841726d14c.tar.gz |
Adding 'isOver' feature to GameController
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/controller/GameController.java | 27 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java | 4 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameController.java b/src/main/java/fr/umlv/java/wallj/controller/GameController.java index b678937..e6fceb9 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GameController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GameController.java | |||
@@ -1,16 +1,39 @@ | |||
1 | package fr.umlv.java.wallj.controller; | 1 | package fr.umlv.java.wallj.controller; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.context.Context; | 3 | import fr.umlv.java.wallj.context.Context; |
4 | import fr.umlv.java.wallj.context.Game; | ||
5 | import fr.umlv.java.wallj.event.ConfirmEvent; | ||
4 | import fr.umlv.java.wallj.event.Event; | 6 | import fr.umlv.java.wallj.event.Event; |
7 | import fr.umlv.java.wallj.event.GameOverEvent; | ||
5 | 8 | ||
9 | import java.util.LinkedList; | ||
6 | import java.util.List; | 10 | import java.util.List; |
7 | 11 | ||
8 | public class GameController implements Controller { | 12 | public class GameController implements Controller { |
9 | //TODO | ||
10 | 13 | ||
11 | @Override | 14 | @Override |
12 | public List<Event> update(Context context) { | 15 | public List<Event> update(Context context) { |
13 | return null; | 16 | boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmEvent); |
17 | boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof) | ||
18 | Game currentGame = context.getGame(); | ||
19 | LinkedList<Event> events = new LinkedList<>(); | ||
20 | if (isConfirmEvent) { | ||
21 | //TODO exiting | ||
22 | if (!isGameOver) { | ||
23 | if (currentGame.getCurrentStage().isCleared()) { | ||
24 | if (currentGame.hasNextBoard()) { //continue | ||
25 | currentGame.nextStage(); | ||
26 | } else { | ||
27 | events.add(new GameOverEvent()); | ||
28 | } | ||
29 | } else {//retry | ||
30 | currentGame.retryStage(); | ||
31 | } | ||
32 | } else { | ||
33 | currentGame.setOver(); | ||
34 | } | ||
35 | } | ||
36 | return events; | ||
14 | } | 37 | } |
15 | 38 | ||
16 | } | 39 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java b/src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java new file mode 100644 index 0000000..3605e01 --- /dev/null +++ b/src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java | |||
@@ -0,0 +1,4 @@ | |||
1 | package fr.umlv.java.wallj.event; | ||
2 | |||
3 | public class GameOverEvent { | ||
4 | } | ||