diff options
Diffstat (limited to 'src/main')
7 files changed, 74 insertions, 11 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/Main.java b/src/main/java/fr/umlv/java/wallj/Main.java index 0ac4136..37a99b0 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java | |||
@@ -27,7 +27,7 @@ public class Main { | |||
27 | paths.add(Paths.get(string)); | 27 | paths.add(Paths.get(string)); |
28 | } | 28 | } |
29 | } else { | 29 | } else { |
30 | paths.add(getResourcePath("/maps/smallvalid.txt")); | 30 | paths.add(getResourcePath("/maps/level0.txt")); |
31 | } | 31 | } |
32 | return paths; | 32 | return paths; |
33 | } | 33 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/block/Stage.java b/src/main/java/fr/umlv/java/wallj/block/Stage.java new file mode 100644 index 0000000..5d2d07c --- /dev/null +++ b/src/main/java/fr/umlv/java/wallj/block/Stage.java | |||
@@ -0,0 +1,43 @@ | |||
1 | package fr.umlv.java.wallj.block; | ||
2 | |||
3 | import fr.umlv.java.wallj.board.Board; | ||
4 | import fr.umlv.java.wallj.context.Context; | ||
5 | import fr.umlv.java.wallj.event.Event; | ||
6 | |||
7 | import java.util.Collections; | ||
8 | import java.util.List; | ||
9 | import java.util.Objects; | ||
10 | |||
11 | /** | ||
12 | * @author | ||
13 | */ | ||
14 | public class Stage { | ||
15 | //TODO Class Stage | ||
16 | private final Board currentBoard; | ||
17 | |||
18 | public Stage(Board board) { | ||
19 | currentBoard = Objects.requireNonNull(board); | ||
20 | } | ||
21 | |||
22 | /** | ||
23 | * @return the current board of the game | ||
24 | */ | ||
25 | public Board getCurrentBoard() { | ||
26 | return currentBoard; | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @param context the current context | ||
31 | * @return a list of new events to perform | ||
32 | */ | ||
33 | public List<Event> update(Context context) { | ||
34 | //TODO | ||
35 | return Collections.emptyList(); | ||
36 | } | ||
37 | |||
38 | public boolean isCleared() { | ||
39 | // TODO | ||
40 | return false; | ||
41 | } | ||
42 | |||
43 | } | ||
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 3ef725e..41d51db 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java | |||
@@ -63,7 +63,8 @@ public final class Game implements Updateable { | |||
63 | public boolean isOver() { | 63 | public boolean isOver() { |
64 | return over; | 64 | return over; |
65 | } | 65 | } |
66 | public void setOver(){ | 66 | |
67 | public void setOver() { | ||
67 | over = true; | 68 | over = true; |
68 | } | 69 | } |
69 | 70 | ||
diff --git a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java index 64591df..2dcd512 100644 --- a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java +++ b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java | |||
@@ -2,6 +2,8 @@ package fr.umlv.java.wallj.context; | |||
2 | 2 | ||
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; | ||
6 | import fr.umlv.java.wallj.event.GameOverEvent; | ||
5 | import fr.umlv.java.wallj.event.MoveRobotOrder; | 7 | import fr.umlv.java.wallj.event.MoveRobotOrder; |
6 | import fr.umlv.zen5.ApplicationContext; | 8 | import fr.umlv.zen5.ApplicationContext; |
7 | import fr.umlv.zen5.Event; | 9 | import fr.umlv.zen5.Event; |
@@ -53,6 +55,12 @@ public final class InputHandler { | |||
53 | case SPACE: | 55 | case SPACE: |
54 | events.add(new BombSetupOrder()); | 56 | events.add(new BombSetupOrder()); |
55 | break; | 57 | break; |
58 | case R: | ||
59 | events.add(new ConfirmOrder()); | ||
60 | break; | ||
61 | case Q: | ||
62 | events.add(new GameOverEvent()); | ||
63 | break; | ||
56 | } | 64 | } |
57 | } | 65 | } |
58 | } | 66 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java index c2c28a7..d7b1638 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java | |||
@@ -14,23 +14,23 @@ public class GameStateController implements Controller { | |||
14 | @Override | 14 | @Override |
15 | public List<Event> update(Context context) { | 15 | public List<Event> update(Context context) { |
16 | boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmOrder); | 16 | boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmOrder); |
17 | boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof GameOverEvent); | 17 | boolean isGameOverEvent = context.getEvents().stream().anyMatch(event -> event instanceof GameOverEvent); |
18 | Game currentGame = context.getGame(); | 18 | Game currentGame = context.getGame(); |
19 | LinkedList<Event> events = new LinkedList<>(); | 19 | LinkedList<Event> events = new LinkedList<>(); |
20 | if (isConfirmEvent) { | 20 | //TODO exiting |
21 | //TODO exiting | 21 | if (isGameOverEvent) { |
22 | if (!isGameOver) { | 22 | currentGame.setOver(); |
23 | } else { | ||
24 | if (isConfirmEvent) { | ||
23 | if (currentGame.getCurrentStage().isCleared()) { | 25 | if (currentGame.getCurrentStage().isCleared()) { |
24 | if (currentGame.hasNextBoard()) { //continue | 26 | if (currentGame.hasNextBoard()) { //continue |
25 | currentGame.nextStage(); | 27 | currentGame.nextStage(); |
26 | } else { | 28 | } else { //no more board so game over |
27 | events.add(new GameOverEvent()); | 29 | currentGame.setOver(); |
28 | } | 30 | } |
29 | } else {//retry | 31 | } else {//retry |
30 | currentGame.retryStage(); | 32 | currentGame.retryStage(); |
31 | } | 33 | } |
32 | } else { | ||
33 | currentGame.setOver(); | ||
34 | } | 34 | } |
35 | } | 35 | } |
36 | return events; | 36 | return events; |
diff --git a/src/main/java/fr/umlv/java/wallj/controller/StageController.java b/src/main/java/fr/umlv/java/wallj/controller/StageController.java index d62e246..57a87fd 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/StageController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/StageController.java | |||
@@ -3,6 +3,7 @@ package fr.umlv.java.wallj.controller; | |||
3 | import fr.umlv.java.wallj.context.Context; | 3 | import fr.umlv.java.wallj.context.Context; |
4 | import fr.umlv.java.wallj.event.Event; | 4 | import fr.umlv.java.wallj.event.Event; |
5 | 5 | ||
6 | import java.util.Collections; | ||
6 | import java.util.List; | 7 | import java.util.List; |
7 | 8 | ||
8 | public class StageController implements Controller { | 9 | public class StageController implements Controller { |
@@ -10,7 +11,7 @@ public class StageController implements Controller { | |||
10 | 11 | ||
11 | @Override | 12 | @Override |
12 | public List<Event> update(Context context) { | 13 | public List<Event> update(Context context) { |
13 | return null; | 14 | return Collections.emptyList(); |
14 | } | 15 | } |
15 | 16 | ||
16 | } | 17 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java index 463a461..a424f99 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java | |||
@@ -30,6 +30,7 @@ import java.util.Objects; | |||
30 | public final class Viewer { | 30 | public final class Viewer { |
31 | 31 | ||
32 | private final Game currentGame; | 32 | private final Game currentGame; |
33 | |||
33 | /** | 34 | /** |
34 | * @param boards the valid list of boards charged in the application | 35 | * @param boards the valid list of boards charged in the application |
35 | */ | 36 | */ |
@@ -43,10 +44,19 @@ public final class Viewer { | |||
43 | public void eventLoop(ApplicationContext applicationContext) { | 44 | public void eventLoop(ApplicationContext applicationContext) { |
44 | List<Event> events = new LinkedList<>(); | 45 | List<Event> events = new LinkedList<>(); |
45 | while (!currentGame.isOver()) { | 46 | while (!currentGame.isOver()) { |
47 | long timeBeforeExec = System.currentTimeMillis(); | ||
46 | applicationContext.renderFrame(graphics2D -> { | 48 | applicationContext.renderFrame(graphics2D -> { |
47 | events.addAll(renderFrame(graphics2D, applicationContext, events)); //add the new events returned by updates | 49 | events.addAll(renderFrame(graphics2D, applicationContext, events)); //add the new events returned by updates |
48 | }); | 50 | }); |
51 | long timeAfterExec = System.currentTimeMillis(); | ||
52 | long delay = timeAfterExec - timeBeforeExec; | ||
53 | try { | ||
54 | Thread.sleep(delay > 0 ? delay : 0); | ||
55 | } catch (Exception e) { | ||
56 | applicationContext.exit(-1); | ||
57 | } | ||
49 | } | 58 | } |
59 | applicationContext.exit(0); | ||
50 | } | 60 | } |
51 | 61 | ||
52 | /** | 62 | /** |