aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr
diff options
context:
space:
mode:
authorpacien2018-02-01 21:00:19 +0100
committerpacien2018-02-01 21:00:19 +0100
commit52e3e8f8aba5eaf3f2805add3333f2674b81d61a (patch)
treedeadf73f62da2dc00e020bd4dc1b05ce21da5185 /src/main/java/fr
parent2e2e281265e62f7621ae7094c680000edaddf64a (diff)
parenta07c49065165b2f896684a57d647f2b1a13b68ca (diff)
downloadwallj-52e3e8f8aba5eaf3f2805add3333f2674b81d61a.tar.gz
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
Diffstat (limited to 'src/main/java/fr')
-rw-r--r--src/main/java/fr/umlv/java/wallj/Main.java2
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/Stage.java43
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Game.java3
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/InputHandler.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/GameStateController.java16
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/StageController.java3
-rw-r--r--src/main/java/fr/umlv/java/wallj/viewer/Viewer.java10
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 @@
1package fr.umlv.java.wallj.block;
2
3import fr.umlv.java.wallj.board.Board;
4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.event.Event;
6
7import java.util.Collections;
8import java.util.List;
9import java.util.Objects;
10
11/**
12 * @author
13 */
14public 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
3import fr.umlv.java.wallj.board.TileVec2; 3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.event.BombSetupOrder; 4import fr.umlv.java.wallj.event.BombSetupOrder;
5import fr.umlv.java.wallj.event.ConfirmOrder;
6import fr.umlv.java.wallj.event.GameOverEvent;
5import fr.umlv.java.wallj.event.MoveRobotOrder; 7import fr.umlv.java.wallj.event.MoveRobotOrder;
6import fr.umlv.zen5.ApplicationContext; 8import fr.umlv.zen5.ApplicationContext;
7import fr.umlv.zen5.Event; 9import 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;
3import fr.umlv.java.wallj.context.Context; 3import fr.umlv.java.wallj.context.Context;
4import fr.umlv.java.wallj.event.Event; 4import fr.umlv.java.wallj.event.Event;
5 5
6import java.util.Collections;
6import java.util.List; 7import java.util.List;
7 8
8public class StageController implements Controller { 9public 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;
30public final class Viewer { 30public 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 /**