From 8ca2326c892997a30fbf0f30f9ae570766b606d3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 7 Nov 2021 15:58:55 +0100 Subject: [PATCH] Added 1 test --- .../java/fr/lnl/game/client/view/Cell.java | 1 - .../java/fr/lnl/game/server/games/Game.java | 2 ++ .../lnl/game/server/games/action/DropBomb.java | 4 ++++ .../lnl/game/server/games/action/DropMine.java | 5 +++++ .../fr/lnl/game/server/games/action/Move.java | 4 +++- .../fr/lnl/game/server/games/action/Shot.java | 3 ++- .../fr/lnl/game/server/ActionPlayerTest.java | 18 +++++++++++------- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/src/main/java/fr/lnl/game/client/view/Cell.java b/client/src/main/java/fr/lnl/game/client/view/Cell.java index c915462..a6df2a7 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Cell.java +++ b/client/src/main/java/fr/lnl/game/client/view/Cell.java @@ -6,7 +6,6 @@ import fr.lnl.game.server.games.grid.Mine; import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; import javafx.scene.image.Image; -import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 473af24..1272a6a 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -28,6 +28,7 @@ public class Game { } public Player getWinner() { + // On part du principe que isOver est forcément appelé avant d'appeler getWinner return players.parallelStream().filter(player -> !player.isAlive()).findFirst().orElseThrow(ArrayIndexOutOfBoundsException::new); } @@ -47,6 +48,7 @@ public class Game { index = 0; currentPlayer = players.get(index); } while(!currentPlayer.isAlive()); // On arrête la boucle dès qu'on trouve un joueur en vie + currentPlayer.setShieldDeploy(false); // on reset son état return true; } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DropBomb.java b/server/src/main/java/fr/lnl/game/server/games/action/DropBomb.java index 66d49ed..5fe8ad5 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DropBomb.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DropBomb.java @@ -13,6 +13,10 @@ public class DropBomb extends DropObject { super(game, player); } + /** + * @deprecated même principe que {@link Shot#doAction()} + */ + @Deprecated @Override public void doAction() { List points = getValidPoint(); diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java index 43b16c7..f22615e 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java @@ -12,6 +12,11 @@ public class DropMine extends DropObject { public DropMine(Game game, Player player){ super(game, player); } + + /** + * @deprecated même principe que {@link Shot#doAction()} + */ + @Deprecated @Override public void doAction() { List points = getValidPoint(); diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Move.java b/server/src/main/java/fr/lnl/game/server/games/action/Move.java index d04d175..e4dd8d3 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Move.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Move.java @@ -1,7 +1,9 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; -import fr.lnl.game.server.games.grid.*; +import fr.lnl.game.server.games.grid.Box; +import fr.lnl.game.server.games.grid.InteractiveBox; +import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Shot.java b/server/src/main/java/fr/lnl/game/server/games/action/Shot.java index 11301e7..bf77c75 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Shot.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Shot.java @@ -16,7 +16,8 @@ public class Shot extends AbstractAction { } /** - * @deprecated a rewrite -> L'aléatoire ne devrait pas être ici, mais au moment de l'instanciation comme dans {@link Move} + * @deprecated a rewrite -> L'aléatoire ne devrait pas être ici, mais au moment de l'instanciation par exemple + * comme dans {@link Move} */ @Deprecated @Override diff --git a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java index 3e1447d..eb31671 100644 --- a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java +++ b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java @@ -1,11 +1,9 @@ package fr.lnl.game.server; import fr.lnl.game.server.games.Game; -import fr.lnl.game.server.games.action.Action; -import fr.lnl.game.server.games.action.Move; -import fr.lnl.game.server.games.action.NotValidDirectionException; -import fr.lnl.game.server.games.action.Shot; +import fr.lnl.game.server.games.action.*; import fr.lnl.game.server.games.grid.Grid; +import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -23,13 +21,11 @@ public class ActionPlayerTest { Mock mock = new Mock(); this.grid = mock.grid; this.game = mock.game; + Assertions.assertEquals(game.getPlayers().get(0), game.getCurrentPlayer()); } - // TODO: 21/10/2021 Vérifier sur Move effectue la bonne action en pensant a appeler isPossible() avant et - // en checkant son résultat @Test public void moveActionTest() { - Assertions.assertEquals(game.getPlayers().get(0), game.getCurrentPlayer()); Action move = null; Point oldPoint = game.getCurrentPlayer().getPoint(); Move.Direction savedDirection = null; @@ -51,6 +47,14 @@ public class ActionPlayerTest { ); } + @Test + public void DeployShieldTest() { + Player player = game.getCurrentPlayer(); + Assertions.assertFalse(player.isShieldDeploy()); + Action action = new DeployShield(player); + action.doAction(); + Assertions.assertTrue(player.isShieldDeploy()); + } // TODO: 10/28/2021 pas un vrai test et marche qu'avec le mock actuel @Test