From 48902d6696e40cb100c86fa83b131b4b7a016f52 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Feb 2018 12:25:04 +0100 Subject: Rename GameController and update class diagram Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/context/Game.java | 4 +-- .../umlv/java/wallj/controller/GameController.java | 39 ---------------------- .../java/wallj/controller/GameStateController.java | 39 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/fr/umlv/java/wallj/controller/GameController.java create mode 100644 src/main/java/fr/umlv/java/wallj/controller/GameStateController.java (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 d5f9873..6bc63ae 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java @@ -2,7 +2,7 @@ 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.controller.GameStateController; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.block.Stage; @@ -25,7 +25,7 @@ public final class Game { */ public Game(List boards) { this.controllers = new LinkedList<>(); - this.controllers.add(new GameController()); + this.controllers.add(new GameStateController()); Objects.requireNonNull(boards); if (boards.isEmpty()) { throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameController.java b/src/main/java/fr/umlv/java/wallj/controller/GameController.java deleted file mode 100644 index 456793a..0000000 --- a/src/main/java/fr/umlv/java/wallj/controller/GameController.java +++ /dev/null @@ -1,39 +0,0 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.context.Game; -import fr.umlv.java.wallj.event.ConfirmEvent; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.event.GameOverEvent; - -import java.util.LinkedList; -import java.util.List; - -public class GameController implements Controller { - - @Override - public List update(Context context) { - boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmEvent); - boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof GameOverEvent); - Game currentGame = context.getGame(); - LinkedList events = new LinkedList<>(); - if (isConfirmEvent) { - //TODO exiting - if (!isGameOver) { - if (currentGame.getCurrentStage().isCleared()) { - if (currentGame.hasNextBoard()) { //continue - currentGame.nextStage(); - } else { - events.add(new GameOverEvent()); - } - } else {//retry - currentGame.retryStage(); - } - } else { - currentGame.setOver(); - } - } - return events; - } - -} diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java new file mode 100644 index 0000000..2c548f2 --- /dev/null +++ b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java @@ -0,0 +1,39 @@ +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.context.Game; +import fr.umlv.java.wallj.event.ConfirmEvent; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.event.GameOverEvent; + +import java.util.LinkedList; +import java.util.List; + +public class GameStateController implements Controller { + + @Override + public List update(Context context) { + boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmEvent); + boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof GameOverEvent); + Game currentGame = context.getGame(); + LinkedList events = new LinkedList<>(); + if (isConfirmEvent) { + //TODO exiting + if (!isGameOver) { + if (currentGame.getCurrentStage().isCleared()) { + if (currentGame.hasNextBoard()) { //continue + currentGame.nextStage(); + } else { + events.add(new GameOverEvent()); + } + } else {//retry + currentGame.retryStage(); + } + } else { + currentGame.setOver(); + } + } + return events; + } + +} -- cgit v1.2.3