From 88eb9363202ad415b2c49b6ecd57bb3d49900739 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 00:13:01 +0100 Subject: Moving Stage inside Game, and implementing methods related to this new management or not --- src/main/java/fr/umlv/java/wallj/context/Game.java | 66 ++++++++++++++-------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'src/main/java/fr') 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 @@ package fr.umlv.java.wallj.context; import fr.umlv.java.wallj.board.Board; +import fr.umlv.java.wallj.controller.Controller; import fr.umlv.java.wallj.controller.GameController; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.Stage; -import java.util.Collections; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Objects; +import java.util.*; /** * A game. + * * @author Adam NAILI */ public final class Game { - //TODO - private final GameController gameController; + private Stage currentStage; + private final List controllers; private int indexBoard; private final List boards; /** - * @param gameController the controller of the game - * @param boards the list of boards charged for the game + * @param boards the list of boards charged for the game */ - public Game(GameController gameController, List boards) { - this.gameController = Objects.requireNonNull(gameController); + public Game(List boards) { + this.controllers = new LinkedList<>(); + this.controllers.add(new GameController()); Objects.requireNonNull(boards); if (boards.isEmpty()) { throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); } this.boards = Collections.unmodifiableList(boards); this.indexBoard = 0; + this.currentStage = new Stage(this.boards.get(0)); } /** - * @return the game controller + * @return a boolean on the condition of having a next Board in our game. */ - public GameController getGameController() { - return gameController; + public boolean hasNextBoard() { + return indexBoard + 1 < boards.size(); } /** - * @return the current board of the game. + * @return the next board */ - public Board getCurrentBoard() { + private Board nextBoard() { + if (!hasNextBoard()) { + throw new IllegalStateException("No more board for the game."); + } + indexBoard++; return boards.get(indexBoard); } /** - * @return a boolean on the condition of having a next Board in our game. + * @return the current stage */ - public boolean hasNextBoard() { - return indexBoard + 1 < boards.size(); + public Stage getCurrentStage() { + return currentStage; + } + + public void nextStage() { + if (hasNextBoard()) { + currentStage = new Stage(nextBoard()); + } + } + + public void retryStage() { + currentStage = new Stage(currentStage.getCurrentBoard()); } /** - * @return the next board + * @param context the current context + * @return a list of new events */ - public Board nextBoard() { - if (indexBoard >= boards.size()) { - throw new NoSuchElementException("No more board for the game."); + public List update(Context context) { + LinkedList events = new LinkedList<>(); + for (Controller controller : controllers) { + events.addAll(controller.update(context)); } - indexBoard++; - return boards.get(indexBoard); + events.addAll(currentStage.update(context)); + return events; } } -- cgit v1.2.3