diff --git a/client/src/main/java/fr/lnl/game/client/AbstractView.java b/client/src/main/java/fr/lnl/game/client/AbstractView.java new file mode 100644 index 0000000..d837f18 --- /dev/null +++ b/client/src/main/java/fr/lnl/game/client/AbstractView.java @@ -0,0 +1,4 @@ +package fr.lnl.game.client; + +public abstract class AbstractView implements View { +} diff --git a/client/src/main/java/fr/lnl/game/client/View.java b/client/src/main/java/fr/lnl/game/client/View.java new file mode 100644 index 0000000..c36feb7 --- /dev/null +++ b/client/src/main/java/fr/lnl/game/client/View.java @@ -0,0 +1,4 @@ +package fr.lnl.game.client; + +public interface View { +} diff --git a/client/src/main/java/fr/lnl/game/client/Window.java b/client/src/main/java/fr/lnl/game/client/Window.java new file mode 100644 index 0000000..93fe618 --- /dev/null +++ b/client/src/main/java/fr/lnl/game/client/Window.java @@ -0,0 +1,4 @@ +package fr.lnl.game.client; + +public class Window extends AbstractView { +} diff --git a/client/src/main/java/fr/lnl/game/client/graphics/Terminal.java b/client/src/main/java/fr/lnl/game/client/graphics/Terminal.java new file mode 100644 index 0000000..b17a216 --- /dev/null +++ b/client/src/main/java/fr/lnl/game/client/graphics/Terminal.java @@ -0,0 +1,6 @@ +package fr.lnl.game.client.graphics; + +import fr.lnl.game.client.AbstractView; + +public class Terminal 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 9858edd..fd1fd50 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,13 +28,15 @@ public class Game { } public Player getWinner(){ + // Quentin: simple avis: appel de isOver pas forcément nécessaire, puisqu'on appelera surement getWinner après + // un appel a isOver retournant true if(isOver()){ return players[0]; } return null; } - public Player getCurrent_player() { + public Player getCurrentPlayer() { return current_player; } @@ -42,14 +44,6 @@ public class Game { return grid; } - public Player getPlayer_One() { - return player_One; - } - - public Player getPlayer_Two() { - return player_Two; - } - public Player[] getPlayers() { return players; } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DeployShield.java b/server/src/main/java/fr/lnl/game/server/games/action/DeployShield.java index da4880a..4fec118 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DeployShield.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DeployShield.java @@ -9,7 +9,7 @@ public class DeployShield extends AbstractAction { @Override public void doAction(){ - getGame().getCurrent_player().setShieldDeploy(true); + getGame().getCurrentPlayer().setShieldDeploy(true); //TO-DO retirer les point du player } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DropObject.java b/server/src/main/java/fr/lnl/game/server/games/action/DropObject.java index 6202198..7284eaa 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DropObject.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DropObject.java @@ -11,7 +11,6 @@ import fr.lnl.game.server.utils.Point; import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Random; public abstract class DropObject extends AbstractAction { @@ -31,7 +30,7 @@ public abstract class DropObject extends AbstractAction { public List getValidPoint() { List listMoves = new LinkedList<>(); HashMap> board = getGame().getGrid().getBoard(); - Point position = getGame().getCurrent_player().getPoint(); + Point position = getGame().getCurrentPlayer().getPoint(); for (int row = -1; row <= 1; row++) { for (int column = -1; column <= 1; column++) { if(Grid.caseisValid(position.getA(),row,position.getB(),column)){ 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 b14db44..0651104 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 @@ -23,7 +23,7 @@ public class Move extends AbstractAction { List points = getValidPoint(); Random random = new Random(); Point nextPositon = points.get(random.nextInt(0,points.size() - 1)); - Player player = getGame().getCurrent_player(); + Player player = getGame().getCurrentPlayer(); getGame().getGrid().getBoard().get(player.getPoint()).setA(null); getGame().getGrid().getBoard().get(nextPositon).setA(player); player.decrementEnergy(player.getClassPlayer().getMoveCost()); @@ -37,7 +37,7 @@ public class Move extends AbstractAction { public List getValidPoint() { List listMoves = new LinkedList<>(); HashMap> board = getGame().getGrid().getBoard(); - Point position = getGame().getCurrent_player().getPoint(); + Point position = getGame().getCurrentPlayer().getPoint(); for (int row = -1; row <= 1; row++) { for (int column = -1; column <= 1; column++) { if(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){ diff --git a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java new file mode 100644 index 0000000..6c887b7 --- /dev/null +++ b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java @@ -0,0 +1,28 @@ +package fr.lnl.game.server; + +import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.grid.Grid; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ActionPlayerTest { + + private Grid grid; + private Game game; + + @BeforeEach + public void mock() { + Mock mock = new Mock(); + this.grid = mock.grid; + this.game = mock.game; + } + + // TODO: 21/10/2021 Vérifier sur Move effectue la bonne action en pensant a appeller isPossible() avant et + // en checkant son résultat + @Test + public void moveActionTest() { + Assertions.assertEquals(game.getPlayers()[0], game.getCurrentPlayer()); + } + +} 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 0e9a056..cead165 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -1,12 +1,8 @@ package fr.lnl.game.server; -import fr.lnl.game.server.games.Game; 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.ComputerPlayer; -import fr.lnl.game.server.games.player.ClassPlayer; -import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.BeforeEach; @@ -18,17 +14,10 @@ public class GridTest { private Grid grid; - @BeforeEach - public void mockGrid() { - Player playerOne = new ComputerPlayer(1,null, ClassPlayer.DEFAULT); - Player playerTwo = new ComputerPlayer(2,null, ClassPlayer.DEFAULT); - this.grid = new Grid(16,16,new Player[]{playerOne,playerTwo}); - grid.initGrid(); - placePlayersBRUT(); - placeEnergyBallBRUT(); - placeInternWallBRUT(); - Game game = new Game(grid,playerOne,playerTwo); + public void mock() { + Mock mock = new Mock(); + grid = mock.grid; } @Test @@ -46,21 +35,4 @@ public class GridTest { assertEquals(new EnergyBall(), grid.getBoard().get(new Point(7, 10)).getB()); } - public void placePlayersBRUT(){ - grid.getBoard().get(new Point(1,1)).setA(grid.getPlayers()[0]); - grid.getBoard().get(new Point(14,14)).setA(grid.getPlayers()[1]); - } - - public void placeEnergyBallBRUT(){ - grid.getBoard().get(new Point(2,3)).setB(new EnergyBall()); - grid.getBoard().get(new Point(7,10)).setB(new EnergyBall()); - } - - public void placeInternWallBRUT(){ - grid.getBoard().get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); - grid.getBoard().get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); - grid.getBoard().get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7)); - grid.getBoard().get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2)); - } - } diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/Mock.java new file mode 100644 index 0000000..6a4d463 --- /dev/null +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -0,0 +1,46 @@ +package fr.lnl.game.server; + +import fr.lnl.game.server.games.Game; +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.ClassPlayer; +import fr.lnl.game.server.games.player.ComputerPlayer; +import fr.lnl.game.server.games.player.Player; +import fr.lnl.game.server.utils.Cardinal; +import fr.lnl.game.server.utils.Point; + +public class Mock { + + Grid grid; + Game game; + + public Mock() { + Player playerOne = new ComputerPlayer(1,null, ClassPlayer.DEFAULT); + Player playerTwo = new ComputerPlayer(2,null, ClassPlayer.DEFAULT); + this.grid = new Grid(16,16,new Player[]{playerOne,playerTwo}); + grid.initGrid(); + placePlayersBRUT(); + placeEnergyBallBRUT(); + placeInternWallBRUT(); + game = new Game(grid,playerOne,playerTwo); + } + + public void placePlayersBRUT(){ + grid.getBoard().get(new Point(1,1)).setA(grid.getPlayers()[0]); + grid.getBoard().get(new Point(14,14)).setA(grid.getPlayers()[1]); + } + + public void placeEnergyBallBRUT(){ + grid.getBoard().get(new Point(2,3)).setB(new EnergyBall()); + grid.getBoard().get(new Point(7,10)).setB(new EnergyBall()); + } + + public void placeInternWallBRUT(){ + grid.getBoard().get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); + grid.getBoard().get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); + grid.getBoard().get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7)); + grid.getBoard().get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2)); + } + +}