aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2018-01-14 15:20:19 +0100
committerAdam NAILI2018-01-14 15:20:19 +0100
commitb54e20222747a12621cdc31e6ee78f841726d14c (patch)
tree1424eb03f87ee1026298a7e5020ef4cd9777d2be
parentf6d2592328941b8b6510f82a447d0984c9e56c05 (diff)
downloadwallj-b54e20222747a12621cdc31e6ee78f841726d14c.tar.gz
Adding 'isOver' feature to GameController
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/GameController.java27
-rw-r--r--src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java4
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 @@
1package fr.umlv.java.wallj.controller; 1package fr.umlv.java.wallj.controller;
2 2
3import fr.umlv.java.wallj.context.Context; 3import fr.umlv.java.wallj.context.Context;
4import fr.umlv.java.wallj.context.Game;
5import fr.umlv.java.wallj.event.ConfirmEvent;
4import fr.umlv.java.wallj.event.Event; 6import fr.umlv.java.wallj.event.Event;
7import fr.umlv.java.wallj.event.GameOverEvent;
5 8
9import java.util.LinkedList;
6import java.util.List; 10import java.util.List;
7 11
8public class GameController implements Controller { 12public 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 @@
1package fr.umlv.java.wallj.event;
2
3public class GameOverEvent {
4}