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 a0d129a..d560a15 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 @@ -18,8 +18,8 @@ public class Cell extends Rectangle { private static Image PLAYER_IMAGE = new Image("player.png"); private static Image ENERGY_BALL_IMAGE = new Image("energyBall.png"); - private static Image BOMB_IMAGE = new Image("bomb.jpg"); - private static Image MINE_IMAGE = new Image("mine.webp"); + private static Image BOMB_IMAGE = new Image("bomb.png"); + private static Image MINE_IMAGE = new Image("mine.png"); private static Image WALL_IMAGE = new Image("wall.jpg"); public Cell(int x, int y){ diff --git a/client/src/main/resources/bomb.jpg b/client/src/main/resources/bomb.jpg deleted file mode 100644 index b354c21..0000000 Binary files a/client/src/main/resources/bomb.jpg and /dev/null differ diff --git a/client/src/main/resources/bomb.png b/client/src/main/resources/bomb.png new file mode 100644 index 0000000..012c1a2 Binary files /dev/null and b/client/src/main/resources/bomb.png differ diff --git a/client/src/main/resources/bottomLeftWall.PNG b/client/src/main/resources/bottomLeftWall.PNG deleted file mode 100644 index af2c630..0000000 Binary files a/client/src/main/resources/bottomLeftWall.PNG and /dev/null differ diff --git a/client/src/main/resources/bottomRightWall.PNG b/client/src/main/resources/bottomRightWall.PNG deleted file mode 100644 index 3e87801..0000000 Binary files a/client/src/main/resources/bottomRightWall.PNG and /dev/null differ diff --git a/client/src/main/resources/bottomWall.PNG b/client/src/main/resources/bottomWall.PNG deleted file mode 100644 index 3287196..0000000 Binary files a/client/src/main/resources/bottomWall.PNG and /dev/null differ diff --git a/client/src/main/resources/energyBall.png b/client/src/main/resources/energyBall.png index 5ff8898..3dd424a 100644 Binary files a/client/src/main/resources/energyBall.png and b/client/src/main/resources/energyBall.png differ diff --git a/client/src/main/resources/mine.png b/client/src/main/resources/mine.png new file mode 100644 index 0000000..c23e00b Binary files /dev/null and b/client/src/main/resources/mine.png differ diff --git a/client/src/main/resources/mine.webp b/client/src/main/resources/mine.webp deleted file mode 100644 index 665e077..0000000 Binary files a/client/src/main/resources/mine.webp and /dev/null differ diff --git a/client/src/main/resources/rightWall.PNG b/client/src/main/resources/rightWall.PNG deleted file mode 100644 index f2f5278..0000000 Binary files a/client/src/main/resources/rightWall.PNG and /dev/null differ diff --git a/client/src/main/resources/topLeftWall.PNG b/client/src/main/resources/topLeftWall.PNG deleted file mode 100644 index 73a2dd5..0000000 Binary files a/client/src/main/resources/topLeftWall.PNG and /dev/null differ diff --git a/client/src/main/resources/topRightWall.PNG b/client/src/main/resources/topRightWall.PNG deleted file mode 100644 index 74ff2dc..0000000 Binary files a/client/src/main/resources/topRightWall.PNG and /dev/null differ diff --git a/client/src/main/resources/topWall.PNG b/client/src/main/resources/topWall.PNG deleted file mode 100644 index c769e82..0000000 Binary files a/client/src/main/resources/topWall.PNG and /dev/null differ 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 5d82d3f..eacfcd0 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 @@ -42,9 +42,7 @@ public class Game { } public void play() { - if (currentPlayer instanceof ComputerPlayer player) { - selectedAction = player.choseAction(); - } + selectedAction = currentPlayer.choseAction(); selectedAction.doAction(); countdownGridElementsUpdate(); nextCurrentPlayer(); @@ -52,7 +50,6 @@ public class Game { if(isOver()) { gameFinishEvent.updateModel(null); } - } private void countdownGridElementsUpdate() { @@ -67,10 +64,10 @@ public class Game { actions.add(new Move(this, player, direction)); } catch (NotValidDirectionException ignored){} try { - new DropBomb(this, player, direction); + actions.add(new DropBomb(this, player, direction)); } catch (NotValidDirectionException ignored) {} try { - new DropMine(this, player, direction); + actions.add(new DropMine(this, player, direction)); } catch (NotValidDirectionException ignored) {} try { actions.add(new Shot(this, player, direction)); 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 bf0b38e..9a1c704 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 @@ -71,7 +71,7 @@ public class Shot extends AbstractAction { return null; for(int i = 0; i < range; i++) { Point neighbour = new Point(point.getA() + deltaX + (i * deltaX), point.getB() + deltaY + (i * deltaY)); - if(game.getGrid().boardPositionIsValid(point)) { + if(game.getGrid().boardPositionIsValid(neighbour)) { if(game.getGrid().getBoard().get(neighbour).getB() instanceof Wall) { return null; } 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 b2d2dc0..92659de 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 @@ -14,6 +14,7 @@ public abstract class AbstractBuildStrategy implements BuildStrategy{ build(); } + @Override public void build() { initGrid(); initPlaceInternWall(WALL_PROBABILITY); diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java b/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java index 16f4e9c..9d0b144 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/build/BuildStrategy.java @@ -4,6 +4,7 @@ import fr.lnl.game.server.games.grid.Grid; public interface BuildStrategy { + void build(); void initPlacePlayers(); Grid getGrid(); diff --git a/server/src/main/java/fr/lnl/game/server/games/player/ComputerPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/ComputerPlayer.java index a6fd6c5..9468333 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/ComputerPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/ComputerPlayer.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 abstract class ComputerPlayer extends AbstractPlayer { @@ -8,6 +7,4 @@ public abstract class ComputerPlayer extends AbstractPlayer { public ComputerPlayer(Integer id, Point point, ClassPlayer classPlayer) { super(id, point, false, classPlayer); } - - public abstract Action choseAction(); } 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 676f572..2a83908 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,9 @@ package fr.lnl.game.server.games.player; +import fr.lnl.game.server.games.action.Action; +import fr.lnl.game.server.utils.Maths; import fr.lnl.game.server.utils.Point; +import java.util.Scanner; public class HumanPlayer extends AbstractPlayer { @@ -8,4 +11,22 @@ public class HumanPlayer extends AbstractPlayer { super(id, point,false, classPlayer); } + @Override + public Action choseAction() { + String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + getActions().size(); + Action action = null; + Scanner scanner = new Scanner(System.in); + do{ + System.out.println("Choisissez une action :"); + for (int i = 0; i < getActions().size(); i++) { + System.out.println((i + 1) + " : " + getActions().get(i).getClass().getSimpleName()); + } + String entry = scanner.next(); + int value = Maths.testInteger(entry,scanner,error); + if(value >= 1 && value <= getActions().size()){ + action = getActions().get(value - 1); + } + }while(action == null); + return action; + } } diff --git a/server/src/main/java/fr/lnl/game/server/games/player/Player.java b/server/src/main/java/fr/lnl/game/server/games/player/Player.java index 4eef35e..17c77e5 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/Player.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/Player.java @@ -8,6 +8,8 @@ import java.util.List; public interface Player { + Action choseAction(); + Point getPosition(); boolean isAlive(); diff --git a/server/src/main/java/fr/lnl/game/server/utils/Error.java b/server/src/main/java/fr/lnl/game/server/utils/Error.java new file mode 100644 index 0000000..ec7dc6d --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/utils/Error.java @@ -0,0 +1,6 @@ +package fr.lnl.game.server.utils; + +public class Error { + + public static final String Entry_Error_Message = "\033[0;31mErreur de saisie\033[0m : "; +} diff --git a/server/src/main/java/fr/lnl/game/server/utils/Maths.java b/server/src/main/java/fr/lnl/game/server/utils/Maths.java new file mode 100644 index 0000000..eceb872 --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/utils/Maths.java @@ -0,0 +1,40 @@ +package fr.lnl.game.server.utils; + +import java.util.Scanner; + +public class Maths { + + public static int testInteger(String entry, Scanner scanner, String error) { + while (!isNumeric(entry)) { + System.out.println(Error.Entry_Error_Message + error); + entry = scanner.next(); + } + return Integer.parseInt(entry); + } + + public static float testFloat(String entry, Scanner scanner) { + while (!isFloat(entry)) { + System.out.println("\033[0;31mErreur de saisie\033[0m : Veuillez rentrer une valeur correcte !"); + entry = scanner.next(); + } + return Integer.parseInt(entry); + } + + public static boolean isFloat(String strNum) { + try { + float d = Float.parseFloat(strNum); + } catch (NumberFormatException | NullPointerException nfe) { + return false; + } + return true; + } + + public static boolean isNumeric(String strNum) { + try { + int d = Integer.parseInt(strNum); + } catch (NumberFormatException | NullPointerException nfe) { + return false; + } + return true; + } +} 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 c0638bc..c597274 100644 --- a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java +++ b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java @@ -4,12 +4,17 @@ import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.action.*; import fr.lnl.game.server.games.grid.Grid; 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.utils.Point; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; + public class ActionPlayerTest { private Grid grid; @@ -17,7 +22,9 @@ public class ActionPlayerTest { @BeforeEach public void mock() { - Mock mock = new Mock(); + List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), + new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); + Mock mock = new Mock(players); this.grid = mock.grid; this.game = mock.game; Assertions.assertEquals(game.getPlayers().get(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 f8739fe..ed6d6f5 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -5,12 +5,17 @@ import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.grid.elements.Box; 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.utils.Pair; import fr.lnl.game.server.utils.Point; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; public class GridTest { @@ -20,7 +25,9 @@ public class GridTest { @BeforeEach public void mock() { - Mock mock = new Mock(); + List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), + new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); + Mock mock = new Mock(players); grid = mock.grid; game = mock.game; } 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 5bf0c0c..b9e17c8 100644 --- a/server/src/test/java/fr/lnl/game/server/Mock.java +++ b/server/src/test/java/fr/lnl/game/server/Mock.java @@ -21,9 +21,7 @@ public class Mock { public Game game; public Grid grid; - public Mock() { - List players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT), - new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT)); + public Mock(List players) { this.buildStrategy = new LockStrategy(new Grid(16,16, players),0.80F, 0.95F); game = new Game(buildStrategy, players, new GameFinishEvent()); this.grid = buildStrategy.getGrid(); 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 index 3673011..c97db50 100644 --- a/server/src/test/java/fr/lnl/game/server/games/GameTest.java +++ b/server/src/test/java/fr/lnl/game/server/games/GameTest.java @@ -4,10 +4,15 @@ 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 { @@ -17,39 +22,19 @@ public class GameTest { @BeforeEach public void mock() { - Mock mock = new 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()){ - System.out.println(" Tour du joueur " + game.getCurrentPlayer().getId() + " : " + - game.getCurrentPlayer().getEnergy() + " points de vies restants"); - Player player = game.getCurrentPlayer(); - player.setActions(game.generateAndGetPlayerActions(player)); - System.out.println(game.getGrid().toString()); - Action action = null; - switch (player.getActions().size()){ - case 0 -> action = new Nothing(); - case 1 -> action = game.getCurrentPlayer().getActions().get(0); - default -> { - Random random = new Random(); - while (action == null || !action.isPossible()) { - action = game.getCurrentPlayer().getActions().get( - random.nextInt(0,game.getCurrentPlayer().getActions().size()) - ); - } - } - } - action.doAction(); - System.out.println("Action " + action + " : " + game.getCurrentPlayer().getEnergy() + - " points de vies restants"); - game.nextCurrentPlayer(); + game.play(); } - System.out.println(game.getGrid().toString()); - Player winner = game.getWinner(); - System.out.println(winner != null ? ("Le joueur gagnant : " + winner.getId()) : ("Partie nulle, aucun gagnant")); + System.out.println("Le gagnant est " + game.getWinner().toString()); } }