diff options
Diffstat (limited to 'src/main/java/fr')
8 files changed, 121 insertions, 35 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java index 6231875..c4d47cc 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java | |||
@@ -6,13 +6,17 @@ import java.util.ArrayList; | |||
6 | import java.util.List; | 6 | import java.util.List; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Operations of conversion on Board and List of blocks | ||
9 | * @author Adam NAILI | 10 | * @author Adam NAILI |
10 | */ | 11 | */ |
11 | public final class BoardConverter { | 12 | public final class BoardConverter { |
12 | //TODO | ||
13 | private BoardConverter() { | 13 | private BoardConverter() { |
14 | } | 14 | } |
15 | 15 | ||
16 | /** | ||
17 | * @param blocks the list of blocks to convert in a board | ||
18 | * @return the converted board | ||
19 | */ | ||
16 | public static Board worldToBoard(List<Block> blocks) { | 20 | public static Board worldToBoard(List<Block> blocks) { |
17 | int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1; | 21 | int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1; |
18 | int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; | 22 | int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; |
@@ -24,6 +28,10 @@ public final class BoardConverter { | |||
24 | return builder.build(); | 28 | return builder.build(); |
25 | } | 29 | } |
26 | 30 | ||
31 | /** | ||
32 | * @param board the board to convert into a list of blocks | ||
33 | * @return the list of blocks converted | ||
34 | */ | ||
27 | public static List<Block> boardToWorld(Board board) { | 35 | public static List<Block> boardToWorld(Board board) { |
28 | ArrayList<Block> blocks = new ArrayList<>(); | 36 | ArrayList<Block> blocks = new ArrayList<>(); |
29 | int nbRow = board.getDim().getRow(); | 37 | int nbRow = board.getDim().getRow(); |
@@ -31,7 +39,7 @@ public final class BoardConverter { | |||
31 | for (int i = 0; i < nbRow; i++) { | 39 | for (int i = 0; i < nbRow; i++) { |
32 | for (int j = 0; j < nbCol; j++) { | 40 | for (int j = 0; j < nbCol; j++) { |
33 | Block block; | 41 | Block block; |
34 | TileVec2 location = TileVec2.of(j,i); | 42 | TileVec2 location = TileVec2.of(j, i); |
35 | block = BlockFactory.build(board.getBlockTypeAt(location), location); | 43 | block = BlockFactory.build(board.getBlockTypeAt(location), location); |
36 | if (block != null) { | 44 | if (block != null) { |
37 | blocks.add(block); | 45 | blocks.add(block); |
diff --git a/src/main/java/fr/umlv/java/wallj/context/Context.java b/src/main/java/fr/umlv/java/wallj/context/Context.java index 053bc8e..01b1f3f 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Context.java +++ b/src/main/java/fr/umlv/java/wallj/context/Context.java | |||
@@ -13,17 +13,17 @@ import java.util.Objects; | |||
13 | */ | 13 | */ |
14 | public final class Context { | 14 | public final class Context { |
15 | //TODO Class Context | 15 | //TODO Class Context |
16 | private final Stage stage; | 16 | private final Game game; |
17 | private final List<Event> events; | 17 | private final List<Event> events; |
18 | private final GraphicsContext graphicsContext; | 18 | private final GraphicsContext graphicsContext; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @param stage the current stage | 21 | * @param game the current game |
22 | * @param events the list of events of the tick | 22 | * @param events the list of events of the tick |
23 | * @param graphicsContext the current graphics context | 23 | * @param graphicsContext the current graphics context |
24 | */ | 24 | */ |
25 | public Context(Stage stage, List<Event> events, GraphicsContext graphicsContext) { | 25 | public Context(Game game, List<Event> events, GraphicsContext graphicsContext) { |
26 | this.stage = Objects.requireNonNull(stage); | 26 | this.game = Objects.requireNonNull(game); |
27 | this.events = Objects.requireNonNull(events); | 27 | this.events = Objects.requireNonNull(events); |
28 | this.graphicsContext = Objects.requireNonNull(graphicsContext); | 28 | this.graphicsContext = Objects.requireNonNull(graphicsContext); |
29 | } | 29 | } |
@@ -31,8 +31,8 @@ public final class Context { | |||
31 | /** | 31 | /** |
32 | * @return the stage | 32 | * @return the stage |
33 | */ | 33 | */ |
34 | public Stage getStage() { | 34 | public Game getGame() { |
35 | return stage; | 35 | return game; |
36 | } | 36 | } |
37 | 37 | ||
38 | /** | 38 | /** |
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 7ddac02..c7dd6f1 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java | |||
@@ -1,66 +1,84 @@ | |||
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.controller.Controller; | ||
4 | import fr.umlv.java.wallj.controller.GameController; | 5 | import fr.umlv.java.wallj.controller.GameController; |
6 | import fr.umlv.java.wallj.event.Event; | ||
7 | import fr.umlv.java.wallj.model.Stage; | ||
5 | 8 | ||
6 | import java.util.Collections; | 9 | import java.util.*; |
7 | import java.util.List; | ||
8 | import java.util.NoSuchElementException; | ||
9 | import java.util.Objects; | ||
10 | 10 | ||
11 | /** | 11 | /** |
12 | * A game. | 12 | * A game. |
13 | * | ||
13 | * @author Adam NAILI | 14 | * @author Adam NAILI |
14 | */ | 15 | */ |
15 | public final class Game { | 16 | public final class Game { |
16 | //TODO | 17 | private Stage currentStage; |
17 | private final GameController gameController; | 18 | private final List<Controller> controllers; |
18 | private int indexBoard; | 19 | private int indexBoard; |
19 | private final List<Board> boards; | 20 | private final List<Board> boards; |
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @param gameController the controller of the game | 23 | * @param boards the list of boards charged for the game |
23 | * @param boards the list of boards charged for the game | ||
24 | */ | 24 | */ |
25 | public Game(GameController gameController, List<Board> boards) { | 25 | public Game(List<Board> boards) { |
26 | this.gameController = Objects.requireNonNull(gameController); | 26 | this.controllers = new LinkedList<>(); |
27 | this.controllers.add(new GameController()); | ||
27 | Objects.requireNonNull(boards); | 28 | Objects.requireNonNull(boards); |
28 | if (boards.isEmpty()) { | 29 | if (boards.isEmpty()) { |
29 | throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); | 30 | throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); |
30 | } | 31 | } |
31 | this.boards = Collections.unmodifiableList(boards); | 32 | this.boards = Collections.unmodifiableList(boards); |
32 | this.indexBoard = 0; | 33 | this.indexBoard = 0; |
34 | this.currentStage = new Stage(this.boards.get(0)); | ||
33 | } | 35 | } |
34 | 36 | ||
35 | /** | 37 | /** |
36 | * @return the game controller | 38 | * @return a boolean on the condition of having a next Board in our game. |
37 | */ | 39 | */ |
38 | public GameController getGameController() { | 40 | public boolean hasNextBoard() { |
39 | return gameController; | 41 | return indexBoard + 1 < boards.size(); |
40 | } | 42 | } |
41 | 43 | ||
42 | /** | 44 | /** |
43 | * @return the current board of the game. | 45 | * @return the next board |
44 | */ | 46 | */ |
45 | public Board getCurrentBoard() { | 47 | private Board nextBoard() { |
48 | if (!hasNextBoard()) { | ||
49 | throw new IllegalStateException("No more board for the game."); | ||
50 | } | ||
51 | indexBoard++; | ||
46 | return boards.get(indexBoard); | 52 | return boards.get(indexBoard); |
47 | } | 53 | } |
48 | 54 | ||
49 | /** | 55 | /** |
50 | * @return a boolean on the condition of having a next Board in our game. | 56 | * @return the current stage |
51 | */ | 57 | */ |
52 | public boolean hasNextBoard() { | 58 | public Stage getCurrentStage() { |
53 | return indexBoard + 1 < boards.size(); | 59 | return currentStage; |
60 | } | ||
61 | |||
62 | public void nextStage() { | ||
63 | if (hasNextBoard()) { | ||
64 | currentStage = new Stage(nextBoard()); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public void retryStage() { | ||
69 | currentStage = new Stage(currentStage.getCurrentBoard()); | ||
54 | } | 70 | } |
55 | 71 | ||
56 | /** | 72 | /** |