diff options
author | pacien | 2018-02-03 15:51:28 +0100 |
---|---|---|
committer | pacien | 2018-02-03 15:51:28 +0100 |
commit | 9b05a7b77876fac4cc603aa2d7300fc8f443822b (patch) | |
tree | 6e2200eec2ceb8b4061a913d075c79c98957db42 | |
parent | 2e5e21102ea5b1a7f5b3c77126f891b657eb8434 (diff) | |
parent | 3692905833094a74f9d9951585b312589eb9feeb (diff) | |
download | wallj-9b05a7b77876fac4cc603aa2d7300fc8f443822b.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/context/Game.java | 53 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/event/QuitGameOrder.java (renamed from src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java) | 3 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java | 4 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/Main.java | 1 | ||||
-rw-r--r-- | src/test/java/fr/umlv/java/wallj/viewer/ViewerTest.java | 7 |
5 files changed, 30 insertions, 38 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 422e9b7..46de147 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java | |||
@@ -1,10 +1,7 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | 3 | import fr.umlv.java.wallj.board.Board; |
4 | import fr.umlv.java.wallj.event.ConfirmOrder; | 4 | import fr.umlv.java.wallj.event.*; |
5 | import fr.umlv.java.wallj.event.Event; | ||
6 | import fr.umlv.java.wallj.event.Events; | ||
7 | import fr.umlv.java.wallj.event.GameOverEvent; | ||
8 | 5 | ||
9 | import java.util.*; | 6 | import java.util.*; |
10 | 7 | ||
@@ -76,34 +73,38 @@ public final class Game implements Updateable { | |||
76 | currentStage = new Stage(currentStage.getBoard()); | 73 | currentStage = new Stage(currentStage.getBoard()); |
77 | } | 74 | } |
78 | 75 | ||
76 | |||
77 | |||
78 | private void goToNext(){ | ||
79 | if (hasNextBoard()) { //continue | ||
80 | nextStage(); | ||
81 | return; | ||
82 | } | ||
83 | setOver(); | ||
84 | } | ||
85 | private void handleEvents(Context context) { | ||
86 | if (Events.findFirst(context.getEvents(), QuitGameOrder.class).isPresent()) { | ||
87 | context.getGame().setOver(); | ||
88 | return; | ||
89 | } | ||
90 | if (Events.findFirst(context.getEvents(), ConfirmOrder.class).isPresent()) { | ||
91 | if (currentStage.isCleared()) { | ||
92 | goToNext(); | ||
93 | return; | ||
94 | } | ||
95 | retryStage(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
79 | /** | 100 | /** |
80 | * @param context the current context | 101 | * @param context the current context |
81 | * @return a list of new events | 102 | * @return a list of new events |
82 | */ | 103 | */ |
83 | @Override | 104 | @Override |
84 | public List<Event> update(Context context) { | 105 | public List<Event> update(Context context) { |
85 | boolean isConfirmOrder = Events.findFirst(context.getEvents(),ConfirmOrder.class).isPresent(); | 106 | handleEvents(context); |
86 | boolean isGameOverEvent = Events.findFirst(context.getEvents(),GameOverEvent.class).isPresent(); | 107 | return currentStage.update(context); |
87 | Game currentGame = context.getGame(); | ||
88 | LinkedList<Event> events = new LinkedList<>(); | ||
89 | if (isGameOverEvent) { | ||
90 | currentGame.setOver(); | ||
91 | } else { | ||
92 | if (isConfirmOrder) { | ||
93 | if (false /*currentGame.getCurrentStage().isCleared()*/) { // FIXME: use StageClearedEvent | ||
94 | if (currentGame.hasNextBoard()) { //continue | ||
95 | currentGame.nextStage(); | ||
96 | } else { //no more board so game over => exiting | ||
97 | currentGame.setOver(); | ||
98 | } | ||
99 | } else {//retry | ||
100 | currentGame.retryStage(); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | // FIXME: update underlying stage and merge generated events | ||
106 | return events; | ||
107 | } | 108 | } |
108 | 109 | ||
109 | 110 | ||
diff --git a/src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java b/src/main/java/fr/umlv/java/wallj/event/QuitGameOrder.java index 4365dc4..2cabac1 100644 --- a/src/main/java/fr/umlv/java/wallj/event/GameOverEvent.java +++ b/src/main/java/fr/umlv/java/wallj/event/QuitGameOrder.java | |||
@@ -5,6 +5,5 @@ package fr.umlv.java.wallj.event; | |||
5 | * | 5 | * |
6 | * @author Pacien TRAN-GIRARD | 6 | * @author Pacien TRAN-GIRARD |
7 | */ | 7 | */ |
8 | public final class GameOverEvent implements GameEvent { | 8 | public final class QuitGameOrder implements InputEvent { |
9 | // void | ||
10 | } | 9 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java b/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java index a8f53d3..9eea443 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java | |||
@@ -3,7 +3,7 @@ package fr.umlv.java.wallj.viewer; | |||
3 | import fr.umlv.java.wallj.board.TileVec2; | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.event.BombSetupOrder; | 4 | import fr.umlv.java.wallj.event.BombSetupOrder; |
5 | import fr.umlv.java.wallj.event.ConfirmOrder; | 5 | import fr.umlv.java.wallj.event.ConfirmOrder; |
6 | import fr.umlv.java.wallj.event.GameOverEvent; | 6 | import fr.umlv.java.wallj.event.QuitGameOrder; |
7 | import fr.umlv.java.wallj.event.MoveRobotOrder; | 7 | import fr.umlv.java.wallj.event.MoveRobotOrder; |
8 | import fr.umlv.zen5.ApplicationContext; | 8 | import fr.umlv.zen5.ApplicationContext; |
9 | import fr.umlv.zen5.Event; | 9 | import fr.umlv.zen5.Event; |
@@ -58,7 +58,7 @@ public final class InputHandler { | |||
58 | events.add(new ConfirmOrder()); | 58 | events.add(new ConfirmOrder()); |
59 | break; | 59 | break; |
60 | case Q: | 60 | case Q: |
61 | events.add(new GameOverEvent()); | 61 | events.add(new QuitGameOrder()); |
62 | break; | 62 | break; |
63 | } | 63 | } |
64 | } | 64 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Main.java b/src/main/java/fr/umlv/java/wallj/viewer/Main.java index ac1a088..01c6211 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Main.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Main.java | |||
@@ -34,7 +34,6 @@ public class Main { | |||
34 | return paths; | 34 | return paths; |
35 | } | 35 | } |
36 | 36 | ||
37 | // TODO: use System.getProperty("levels") to get the path to the level directory | ||
38 | public static void main(String[] args) { | 37 | public static void main(String[] args) { |
39 | List<Board> boards = new LinkedList<>(); | 38 | List<Board> boards = new LinkedList<>(); |
40 | try { | 39 | try { |
diff --git a/src/test/java/fr/umlv/java/wallj/viewer/ViewerTest.java b/src/test/java/fr/umlv/java/wallj/viewer/ViewerTest.java deleted file mode 100644 index ca9ee0c..0000000 --- a/src/test/java/fr/umlv/java/wallj/viewer/ViewerTest.java +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | package fr.umlv.java.wallj.viewer; | ||
2 | |||
3 | import org.junit.jupiter.api.Test; | ||
4 | |||
5 | public class ViewerTest { | ||
6 | |||
7 | } | ||