From a354d4fb21ad9f78a3a5e2d1c7e65cfdf7ef1c81 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Thu, 2 Dec 2021 20:03:46 +0100 Subject: [PATCH] Mock update and import optimization --- .../src/main/java/fr/lnl/game/client/App.java | 8 +++- .../java/fr/lnl/game/client/view/Cell.java | 1 - .../game/client/view/ClientEventHandler.java | 2 +- .../java/fr/lnl/game/client/view/GUI.java | 3 -- .../java/fr/lnl/game/client/view/Window.java | 3 -- .../java/fr/lnl/game/server/games/Game.java | 1 - .../game/server/games/action/DropMine.java | 3 -- .../fr/lnl/game/server/games/grid/Grid.java | 1 - .../game/server/games/player/HumanPlayer.java | 1 - .../game/server/listener/GameFinishEvent.java | 2 - .../java/fr/lnl/game/server/GridTest.java | 38 ++++++++++++++++--- .../test/java/fr/lnl/game/server/Mock.java | 5 +-- 12 files changed, 41 insertions(+), 27 deletions(-) diff --git a/client/src/main/java/fr/lnl/game/client/App.java b/client/src/main/java/fr/lnl/game/client/App.java index 7b41864..d798d90 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -1,10 +1,14 @@ package fr.lnl.game.client; -import fr.lnl.game.client.view.*; -import fr.lnl.game.server.listener.GameFinishEvent; + import fr.lnl.game.client.listener.UpdateViewEvent; +import fr.lnl.game.client.view.AbstractView; +import fr.lnl.game.client.view.Terminal; +import fr.lnl.game.client.view.ViewManager; +import fr.lnl.game.client.view.Window; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.player.*; +import fr.lnl.game.server.listener.GameFinishEvent; import fr.lnl.game.server.utils.CrashException; import fr.lnl.game.server.utils.Point; import javafx.application.Application; 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 7028f9d..945b58d 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 @@ -3,7 +3,6 @@ package fr.lnl.game.client.view; import fr.lnl.game.server.games.grid.Bomb; import fr.lnl.game.server.games.grid.EnergyBall; 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; diff --git a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java index f587948..47d8d9a 100644 --- a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java +++ b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java @@ -1,7 +1,7 @@ package fr.lnl.game.client.view; -import fr.lnl.game.server.listener.ModelListener; import fr.lnl.game.client.listener.ButtonListener; +import fr.lnl.game.server.listener.ModelListener; import javafx.event.ActionEvent; import javafx.event.EventHandler; diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index 09b4b51..46ce600 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -1,9 +1,7 @@ package fr.lnl.game.client.view; -import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.*; -import fr.lnl.game.server.games.player.AbstractPlayer; import fr.lnl.game.server.games.player.ClassPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.RandomComputerPlayer; @@ -14,7 +12,6 @@ import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; -import javafx.scene.shape.Rectangle; import javafx.stage.Modality; import javafx.stage.Stage; diff --git a/client/src/main/java/fr/lnl/game/client/view/Window.java b/client/src/main/java/fr/lnl/game/client/view/Window.java index 65bb4e0..58a6128 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Window.java +++ b/client/src/main/java/fr/lnl/game/client/view/Window.java @@ -3,14 +3,11 @@ package fr.lnl.game.client.view; import fr.lnl.game.client.listener.ButtonListener; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.player.Player; -import javafx.concurrent.ScheduledService; -import javafx.concurrent.Task; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Stage; -import javafx.util.Duration; public class Window extends AbstractView { 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 97cd161..7c16988 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 @@ -8,7 +8,6 @@ import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.listener.AwakeGame; import fr.lnl.game.server.listener.ModelListener; import fr.lnl.game.server.utils.CrashException; -import fr.lnl.game.server.utils.Point; import java.util.ArrayList; import java.util.Arrays; 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 5ec88f5..6aecc67 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 @@ -3,9 +3,6 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.Mine; import fr.lnl.game.server.games.player.Player; -import fr.lnl.game.server.utils.Point; - -import java.util.List; public class DropMine extends DropObject { diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java index 175f6c3..2db43c1 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java @@ -1,6 +1,5 @@ package fr.lnl.game.server.games.grid; -import fr.lnl.game.server.games.player.AbstractPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; import fr.lnl.game.server.utils.Pair; diff --git a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java index 2be409c..676f572 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java @@ -1,6 +1,5 @@ package fr.lnl.game.server.games.player; -import fr.lnl.game.server.games.action.Action; import fr.lnl.game.server.utils.Point; public class HumanPlayer extends AbstractPlayer { diff --git a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java index f09595f..183b1ea 100644 --- a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java +++ b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java @@ -1,7 +1,5 @@ package fr.lnl.game.server.listener; -import fr.lnl.game.server.listener.AbstractModelListening; - public class GameFinishEvent extends AbstractModelListening { private final Object lock = new Object(); diff --git a/server/src/test/java/fr/lnl/game/server/GridTest.java b/server/src/test/java/fr/lnl/game/server/GridTest.java index 244f38b..bc2bbab 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -1,20 +1,17 @@ package fr.lnl.game.server; import fr.lnl.game.server.games.Game; -import fr.lnl.game.server.games.action.*; +import fr.lnl.game.server.games.grid.Box; import fr.lnl.game.server.games.grid.EnergyBall; import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; +import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Random; - import static org.junit.jupiter.api.Assertions.assertEquals; public class GridTest { @@ -44,4 +41,35 @@ public class GridTest { assertEquals(new EnergyBall(), grid.getBoard().get(new Point(8, 10)).getB()); } + @Test + public void testLock() { + System.out.println("=================== GRID COMPLETE ===================="); + System.out.println(grid.toString()); + System.out.println("=================== GRID AVEC LOCK ==================="); + StringBuilder str = new StringBuilder(); + for (int i = 0; i < grid.getRow(); i++) { + str.append("\n"); + for (int j = 0; j < grid.getColumn(); j++) { + Pair value = grid.getBoard().get(new Point(i, j)); + if(value.getB() != null){ + if(value.getB().isLock()){ + str.append(" \033[0;35mL\033[0m"); + } + if(value.getB() instanceof Wall){ + str.append(" \033[0;32mW\033[0m"); + } + if(value.getB() instanceof EnergyBall){ + str.append(" \033[0;31mE\033[0m"); + } + } + else if(value.getA() != null){ + str.append(" \033[0;34mP\033[0m"); + } + else { + str.append(" \033[0;37m.\033[0m"); + } + } + } + System.out.println(str); + } } diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java index 19e13bb..0279164 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -23,10 +23,7 @@ public class Mock { public Mock() { List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); - this.grid = new Grid(16,16, players); - placePlayersBRUT(); - placeEnergyBallBRUT(); - placeInternWallBRUT(); + this.grid = new Grid(16,16, players, 0.80F,0.95F); game = new Game(grid, players, new MockViewUpdate(), new GameFinishEvent()); }