aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2018-02-01 15:47:44 +0100
committerpacien2018-02-01 15:47:44 +0100
commita1942c8cfebd7c850e2cc3ecf94aa6dd8039409f (patch)
treec7acf0fbb6a37725072ba210f622abab9fc17ee3
parent48902d6696e40cb100c86fa83b131b4b7a016f52 (diff)
downloadwallj-a1942c8cfebd7c850e2cc3ecf94aa6dd8039409f.tar.gz
Add stage controller and Updateable interface
Signed-off-by: pacien <pacien.trangirard@pacien.net>
-rw-r--r--src/docs/class.puml17
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/Block.java4
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/Stage.java41
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Game.java5
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Updateable.java28
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/Controller.java12
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/StagePhysicsController.java34
7 files changed, 112 insertions, 29 deletions
diff --git a/src/docs/class.puml b/src/docs/class.puml
index b404102..dfbf5f8 100644
--- a/src/docs/class.puml
+++ b/src/docs/class.puml
@@ -23,6 +23,11 @@ package viewer {
23} 23}
24 24
25package context { 25package context {
26 interface Updateable {
27 List<Event> update(Context)
28 static List<Event> updateAll(List<Updateable>, Context)
29 }
30
26 class Context { 31 class Context {
27 Context(Game,List<Event>,GraphicsContext) 32 Context(Game,List<Event>,GraphicsContext)
28 Game getGame() 33 Game getGame()
@@ -52,7 +57,7 @@ package context {
52 GraphicsContext clearScreen() 57 GraphicsContext clearScreen()
53 } 58 }
54 59
55 class Game { 60 class Game implements Updateable {
56 Stage 61 Stage
57 final List<Controller> 62 final List<Controller>
58 int indexBoard 63 int indexBoard
@@ -91,7 +96,6 @@ package event {
91 class ConfirmEvent implements InputEvent 96 class ConfirmEvent implements InputEvent
92 class GameOverEvent implements Event 97 class GameOverEvent implements Event
93 98
94
95 class ExplosionEvent implements GameEvent { 99 class ExplosionEvent implements GameEvent {
96 Block source 100 Block source
97 Body source 101 Body source
@@ -161,7 +165,7 @@ package block {
161 Block build(BlockType, TileVec2) 165 Block build(BlockType, TileVec2)
162 } 166 }
163 167
164 abstract class Block { 168 abstract class Block implements Updateable {
165 BlockType 169 BlockType
166 List<Controller> 170 List<Controller>
167 Vec2 171 Vec2
@@ -180,10 +184,11 @@ package block {
180 class GarbageBlock extends Block 184 class GarbageBlock extends Block
181 class RobotBlock extends Block 185 class RobotBlock extends Block
182 186
183 class Stage { 187 class Stage implements Updateable {
184 List<Block> 188 List<Block>
185 Board 189 Board
186 Stage(Board) 190 Stage(Board)
191 Board getBoard()
187 List<Block> getBlocks() 192 List<Block> getBlocks()
188 List<Event> update(Context) 193 List<Event> update(Context)
189 bool isCleared() 194 bool isCleared()
@@ -191,9 +196,7 @@ package block {
191} 196}
192 197
193package controller { 198package controller {
194 interface Controller { 199 interface Controller extends Updateable
195 List<Event> update(Context)
196 }
197 200
198 abstract class BlockController implements Controller { 201 abstract class BlockController implements Controller {
199 Block 202 Block
diff --git a/src/main/java/fr/umlv/java/wallj/block/Block.java b/src/main/java/fr/umlv/java/wallj/block/Block.java
index d3c349e..ba299b4 100644
--- a/src/main/java/fr/umlv/java/wallj/block/Block.java
+++ b/src/main/java/fr/umlv/java/wallj/block/Block.java
@@ -2,6 +2,7 @@ package fr.umlv.java.wallj.block;
2 2
3import fr.umlv.java.wallj.board.TileVec2; 3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.context.Context; 4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.context.Updateable;
5import fr.umlv.java.wallj.controller.BlockController; 6import fr.umlv.java.wallj.controller.BlockController;
6import fr.umlv.java.wallj.controller.Controller; 7import fr.umlv.java.wallj.controller.Controller;
7import fr.umlv.java.wallj.event.Event; 8import fr.umlv.java.wallj.event.Event;
@@ -15,7 +16,7 @@ import java.util.stream.Collectors;
15 * 16 *
16 * @author Pacien TRAN-GIRARD 17 * @author Pacien TRAN-GIRARD
17 */ 18 */
18public abstract class Block { 19public abstract class Block implements Updateable {
19 20
20 private final BlockType type; 21 private final BlockType type;
21 private List<Controller> controllers; 22 private List<Controller> controllers;
@@ -66,6 +67,7 @@ public abstract class Block {
66 * @param ctx execution context 67 * @param ctx execution context
67 * @return list of generated events 68 * @return list of generated events
68 */ 69 */
70 @Override
69 public List<Event> update(Context ctx) { 71 public List<Event> update(Context ctx) {
70 return controllers.stream() 72 return controllers.stream()
71 .flatMap(controller -> controller.update(ctx).stream()) 73 .flatMap(controller -> controller.update(ctx).stream())
diff --git a/src/main/java/fr/umlv/java/wallj/block/Stage.java b/src/main/java/fr/umlv/java/wallj/block/Stage.java
index d34af97..cbb75e5 100644
--- a/src/main/java/fr/umlv/java/wallj/block/Stage.java
+++ b/src/main/java/fr/umlv/java/wallj/block/Stage.java
@@ -1,42 +1,59 @@
1package fr.umlv.java.wallj.block; 1package fr.umlv.java.wallj.block;
2 2
3import fr.umlv.java.wallj.board.Board; 3import fr.umlv.java.wallj.board.Board;
4import fr.umlv.java.wallj.board.BoardConverter;
4import fr.umlv.java.wallj.context.Context; 5import fr.umlv.java.wallj.context.Context;
6import fr.umlv.java.wallj.context.Updateable;
7import fr.umlv.java.wallj.controller.Controller;
8import fr.umlv.java.wallj.controller.StagePhysicsController;
5import fr.umlv.java.wallj.event.Event; 9import fr.umlv.java.wallj.event.Event;
10import org.jbox2d.common.Vec2;
11import org.jbox2d.dynamics.World;
6 12
13import java.util.Arrays;
14import java.util.Collections;
7import java.util.List; 15import java.util.List;
8import java.util.Objects; 16import java.util.Objects;
9 17
10/** 18/**
11 * @author 19 * @author Pacien TRAN-GIRARD
12 */ 20 */
13public class Stage { 21public class Stage implements Updateable {
14 //TODO Class Stage 22 private final List<Controller> controllers = Collections.singletonList(new StagePhysicsController(this));
15 private final Board currentBoard; 23 private final World world = new World(new Vec2());
24
25 private final Board board;
26 private final List<Block> blocks;
16 27
17 public Stage(Board board) { 28 public Stage(Board board) {
18 currentBoard = Objects.requireNonNull(board); 29 this.board = Objects.requireNonNull(board);
30 this.blocks = BoardConverter.boardToWorld(board);
31 }
32
33 public World getWorld() {
34 return world;
19 } 35 }
20 36
21 /** 37 /**
22 * @return the current board of the game 38 * @return the current board of the game
23 */ 39 */
24 public Board getCurrentBoard() { 40 public Board getBoard() {
25 return currentBoard; 41 return board;
42 }
43
44 public boolean isCleared() {
45 // TODO
46 return false;
26 } 47 }
27 48
28 /** 49 /**
29 * @param context the current context 50 * @param context the current context
30 * @return a list of new events to perform 51 * @return a list of new events to perform
31 */ 52 */
53 @Override
32 public List<Event> update(Context context) { 54 public List<Event> update(Context context) {
33 //TODO 55 //TODO
34 return null; 56 return null;
35 } 57 }
36 58
37 public boolean isCleared() {
38 // TODO
39 return false;
40 }
41
42} 59}
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 6bc63ae..182f121 100644
--- a/src/main/java/fr/umlv/java/wallj/context/Game.java
+++ b/src/main/java/fr/umlv/java/wallj/context/Game.java
@@ -13,7 +13,7 @@ import java.util.*;
13 * 13 *
14 * @author Adam NAILI 14 * @author Adam NAILI
15 */ 15 */
16public final class Game { 16public final class Game implements Updateable {
17 private Stage currentStage; 17 private Stage currentStage;
18 private final List<Controller> controllers; 18 private final List<Controller> controllers;
19 private int indexBoard; 19 private int indexBoard;
@@ -75,13 +75,14 @@ public final class Game {
75 } 75 }
76 76
77 public void retryStage() { 77 public void retryStage() {
78 currentStage = new Stage(currentStage.getCurrentBoard()); 78 currentStage = new Stage(currentStage.getBoard());
79 } 79 }
80 80
81 /** 81 /**
82 * @param context the current context 82 * @param context the current context
83 * @return a list of new events 83 * @return a list of new events
84 */ 84 */
85 @Override