diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java b/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java index 92659de..3575fdc 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/build/AbstractBuildStrategy.java @@ -5,10 +5,10 @@ import fr.lnl.game.server.games.grid.Grid; public abstract class AbstractBuildStrategy implements BuildStrategy{ private final float WALL_PROBABILITY, ENERGY_PROBABILITY; - private final Grid GRID; + protected final Grid grid; public AbstractBuildStrategy(Grid grid, float wallProbability, float energyProbability){ - this.GRID = grid; + this.grid = grid; this.WALL_PROBABILITY = wallProbability; this.ENERGY_PROBABILITY = energyProbability; build(); @@ -30,12 +30,12 @@ public abstract class AbstractBuildStrategy implements BuildStrategy{ } public Grid getGrid() { - return GRID; + return grid; } - abstract void initGrid(); - abstract void initPlaceEnergyBall(float probability); - abstract void initPlaceInternWall(float probability); + protected abstract void initGrid(); + protected abstract void initPlaceEnergyBall(float probability); + protected abstract void initPlaceInternWall(float probability); diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/build/LockStrategy.java b/server/src/main/java/fr/lnl/game/server/games/grid/build/LockStrategy.java index 98801ca..b71661b 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/build/LockStrategy.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/build/LockStrategy.java @@ -17,7 +17,7 @@ public class LockStrategy extends AbstractBuildStrategy{ } @Override - void initGrid() { + protected void initGrid() { for (int i = 0; i < getGrid().getRow(); i++) { for (int j = 0; j < getGrid().getColumn(); j++) { Box box; @@ -46,7 +46,7 @@ public class LockStrategy extends AbstractBuildStrategy{ } @Override - void initPlaceEnergyBall(float probability) { + protected void initPlaceEnergyBall(float probability) { for (int i = 1; i < getGrid().getRow() - 1; i++) { for (int j = 1; j < getGrid().getColumn() - 1; j++) { if(Math.random() >= probability){ @@ -60,7 +60,7 @@ public class LockStrategy extends AbstractBuildStrategy{ } @Override - void initPlaceInternWall(float probability) { + protected void initPlaceInternWall(float probability) { for (int i = 1; i < getGrid().getRow() - 1; i++) { for (int j = 1; j < getGrid().getColumn() - 1; j++) { if(Math.random() >= probability){ 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 c597274..fa475e8 100644 --- a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java +++ b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java @@ -7,6 +7,7 @@ import fr.lnl.game.server.games.grid.elements.Bomb; import fr.lnl.game.server.games.player.ClassPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.RandomComputerPlayer; +import fr.lnl.game.server.mock.Mock; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -47,7 +48,7 @@ public class ActionPlayerTest { Point newPoint = game.getCurrentPlayer().getPosition(); Assertions.assertEquals(newPoint, new Point(oldPoint.getA() + savedDirection.getDeltaX(), - oldPoint.getA() + savedDirection.getDeltaY() + oldPoint.getB() + savedDirection.getDeltaY() ) ); } 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 ed6d6f5..9ecc58b 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -8,6 +8,7 @@ import fr.lnl.game.server.games.grid.elements.Wall; import fr.lnl.game.server.games.player.ClassPlayer; import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.RandomComputerPlayer; +import fr.lnl.game.server.mock.Mock; import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.BeforeEach; @@ -40,6 +41,7 @@ public class GridTest { assertEquals(new Wall(grid.getRow() - 1, 0), grid.getBoard().get(new Point(grid.getRow() - 1, 0)).getB()); assertEquals(new Wall(grid.getRow() - 1, grid.getColumn() - 1), grid.getBoard().get(new Point(grid.getRow() - 1, grid.getColumn() - 1)).getB()); // test placePlayersBRUT (mocked) + grid.getPlayers().forEach(p -> System.out.println(p.getId() + ": " + p.getPosition())); assertEquals(grid.getPlayers().get(0), grid.getBoard().get(new Point(7, 7)).getA()); assertEquals(grid.getPlayers().get(1), grid.getBoard().get(new Point(7, 8)).getA()); // test placeEnergyBallBRUT (mocked) diff --git a/server/src/test/java/fr/lnl/game/server/games/GameTest.java b/server/src/test/java/fr/lnl/game/server/games/GameTest.java deleted file mode 100644 index c97db50..0000000 --- a/server/src/test/java/fr/lnl/game/server/games/GameTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package fr.lnl.game.server.games; - -import fr.lnl.game.server.Mock; -import fr.lnl.game.server.games.action.Action; -import fr.lnl.game.server.games.action.Nothing; -import fr.lnl.game.server.games.grid.Grid; -import fr.lnl.game.server.games.player.ClassPlayer; -import fr.lnl.game.server.games.player.HumanPlayer; -import fr.lnl.game.server.games.player.Player; -import fr.lnl.game.server.games.player.RandomComputerPlayer; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -public class GameTest { - - private Grid grid; - private Game game; - - @BeforeEach - public void mock() { - List players = Arrays.asList(new HumanPlayer(1,null, ClassPlayer.DEFAULT), - new HumanPlayer(2,null, ClassPlayer.DEFAULT)); - Mock mock = new Mock(players); - grid = mock.grid; - game = mock.game; - } - - @Test - public void testPlay(){ - System.out.println(game.getGrid()); - while (!game.isOver()){ - game.play(); - } - System.out.println("Le gagnant est " + game.getWinner().toString()); - } -} diff --git a/server/src/test/java/fr/lnl/game/server/mock/Mock.java b/server/src/test/java/fr/lnl/game/server/mock/Mock.java new file mode 100644 index 0000000..dfc33c2 --- /dev/null +++ b/server/src/test/java/fr/lnl/game/server/mock/Mock.java @@ -0,0 +1,22 @@ +package fr.lnl.game.server.mock; + +import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.grid.Grid; +import fr.lnl.game.server.games.grid.build.BuildStrategy; +import fr.lnl.game.server.games.player.Player; + +import java.util.List; + +public class Mock { + + public BuildStrategy buildStrategy; + public Game game; + public Grid grid; + + public Mock(List players) { + this.buildStrategy = new MockGridStrategy(new Grid(16,16, players),0.80F, 0.95F); + game = new Game(buildStrategy, players, new MockDisplayWinner()); + this.grid = buildStrategy.getGrid(); + } + +} diff --git a/server/src/test/java/fr/lnl/game/server/MockDisplayWinner.java b/server/src/test/java/fr/lnl/game/server/mock/MockDisplayWinner.java similarity index 85% rename from server/src/test/java/fr/lnl/game/server/MockDisplayWinner.java rename to server/src/test/java/fr/lnl/game/server/mock/MockDisplayWinner.java index cfb7b5f..9ca73e8 100644 --- a/server/src/test/java/fr/lnl/game/server/MockDisplayWinner.java +++ b/server/src/test/java/fr/lnl/game/server/mock/MockDisplayWinner.java @@ -1,4 +1,4 @@ -package fr.lnl.game.server; +package fr.lnl.game.server.mock; import fr.lnl.game.server.listener.AbstractModelListening; diff --git a/server/src/test/java/fr/lnl/game/server/Mock.java b/server/src/test/java/fr/lnl/game/server/mock/MockGridStrategy.java similarity index 53% rename from server/src/test/java/fr/lnl/game/server/Mock.java rename to server/src/test/java/fr/lnl/game/server/mock/MockGridStrategy.java index 323f0ff..f75e917 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/mock/MockGridStrategy.java @@ -1,49 +1,36 @@ -package fr.lnl.game.server; +package fr.lnl.game.server.mock; -import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.Grid; -import fr.lnl.game.server.games.grid.build.BuildStrategy; import fr.lnl.game.server.games.grid.build.LockStrategy; import fr.lnl.game.server.games.grid.elements.EnergyBall; import fr.lnl.game.server.games.grid.elements.Wall; -import fr.lnl.game.server.games.player.ClassPlayer; -import fr.lnl.game.server.games.player.Player; -import fr.lnl.game.server.games.player.RandomComputerPlayer; -import fr.lnl.game.server.listener.GameFinishEvent; import fr.lnl.game.server.utils.Point; -import java.util.Arrays; -import java.util.List; +public class MockGridStrategy extends LockStrategy { -public class Mock { - - public BuildStrategy buildStrategy; - public Game game; - public Grid grid; - - public Mock(List players) { - this.buildStrategy = new LockStrategy(new Grid(16,16, players),0.80F, 0.95F); - game = new Game(buildStrategy, players, new MockDisplayWinner()); - this.grid = buildStrategy.getGrid(); + public MockGridStrategy(Grid grid, float wallProbability, float energyProbability) { + super(grid, wallProbability, energyProbability); } - public void placePlayersBRUT(){ - grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0)); - grid.getPlayers().get(0).setPosition(new Point(7, 7)); - grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1)); - grid.getPlayers().get(1).setPosition(new Point(7, 8)); - } - - public void placeEnergyBallBRUT(){ + @Override + protected void initPlaceEnergyBall(float probability) { grid.getBoard().get(new Point(2,3)).setB(new EnergyBall()); grid.getBoard().get(new Point(8,10)).setB(new EnergyBall()); } - public void placeInternWallBRUT(){ + @Override + protected void initPlaceInternWall(float probability) { grid.getBoard().get(new Point(3,6)).setB(new Wall(3,6)); grid.getBoard().get(new Point(7,14)).setB(new Wall(7,14)); grid.getBoard().get(new Point(10,7)).setB(new Wall(10,7)); grid.getBoard().get(new Point(14,2)).setB(new Wall(14,2)); } + @Override + public void initPlacePlayers() { + grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0)); + grid.getPlayers().get(0).setPosition(new Point(7, 7)); + grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1)); + grid.getPlayers().get(1).setPosition(new Point(7, 8)); + } }