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 1d0fc7b..e591d1f 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -143,7 +143,6 @@ public class App extends Application { default -> throw new IllegalArgumentException("Unknown argument: " + str); } } - System.out.println("oui"); if(playerClass != null) playerList.add(createNewPlayer(playerClass, classPlayer != null ? classPlayer : ClassPlayer.DEFAULT, playerList.size()) 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 b6c0ea6..8e9c242 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 @@ -98,6 +98,12 @@ public class Game { try { actions.add(new Move(this, player, direction)); } catch (NotValidDirectionException ignored){} + try { + actions.add(new Shot(this, player, direction)); + } catch (NotValidDirectionException | NoMoreBulletInWeaponException ignored) {} + + } + for(Direction8Axis direction : Direction8Axis.values()) { try { actions.add(new DropBomb(this, player, direction)); } catch (NotValidDirectionException ignored) {} @@ -105,11 +111,6 @@ public class Game { actions.add(new DropMine(this, player, direction)); } catch (NotValidDirectionException ignored) {} } - for(Direction8Axis direction : Direction8Axis.values()) { - try { - actions.add(new Shot(this, player, direction)); - } catch (NotValidDirectionException | NoMoreBulletInWeaponException ignored) {} - } actions.addAll(Arrays.asList(new Nothing(), new DeployShield(player))); return actions; } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Direction4Axis.java b/server/src/main/java/fr/lnl/game/server/games/action/Direction4Axis.java index 24dcf3d..4c3edea 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Direction4Axis.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Direction4Axis.java @@ -5,17 +5,19 @@ package fr.lnl.game.server.games.action; */ public enum Direction4Axis implements Direction { - UP(-1, 0), - DOWN(1, 0), - LEFT(0, -1), - RIGHT(0, 1); + UP(-1, 0, true), + DOWN(1, 0, true), + LEFT(0, -1, false), + RIGHT(0, 1, false); private final int deltaX; private final int deltaY; + private final boolean isVertical; - Direction4Axis(int i, int i1) { + Direction4Axis(int i, int i1, boolean isVertical) { this.deltaX = i; this.deltaY = i1; + this.isVertical = isVertical; } @Override @@ -27,4 +29,13 @@ public enum Direction4Axis implements Direction { public int getDeltaY() { return deltaY; } + + /** + * Used by {@link Shot} to know if the direction is in vertical direction cause shot action can have a different + * distance depending on the direction + * @return true if the direction is vertical + */ + public boolean isVertical() { + return isVertical; + } } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Direction8Axis.java b/server/src/main/java/fr/lnl/game/server/games/action/Direction8Axis.java index 3ed49b2..fe3cf48 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Direction8Axis.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Direction8Axis.java @@ -2,23 +2,21 @@ package fr.lnl.game.server.games.action; public enum Direction8Axis implements Direction { - UP(-1, 0, true), - DOWN(1, 0, true), - LEFT(0, -1, false), - RIGHT(0, 1, false), - UP_LEFT(-1, -1, true), - UP_RIGHT(-1, 1, true), - DOWN_RIGHT(1, 1, true), - DOWN_LEFT(1, -1, true); + UP(-1, 0), + DOWN(1, 0), + LEFT(0, -1), + RIGHT(0, 1), + UP_LEFT(-1, -1), + UP_RIGHT(-1, 1), + DOWN_RIGHT(1, 1), + DOWN_LEFT(1, -1); private final int deltaX; private final int deltaY; - private final boolean isVertical; - Direction8Axis(int i, int i1, boolean isVertical) { + Direction8Axis(int i, int i1) { this.deltaX = i; this.deltaY = i1; - this.isVertical = isVertical; } @Override @@ -31,14 +29,5 @@ public enum Direction8Axis implements Direction { return deltaY; } - /** - * Used by {@link Shot} to know if the direction is in vertical direction cause shot action can have a different - * distance depending of the direction - * @return true if the direction is vertical - */ - public boolean isVertical() { - return isVertical; - } - } 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 44e25bc..b078633 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 @@ -9,7 +9,7 @@ import fr.lnl.game.server.games.player.Player; */ public class DropBomb extends DropObject { - public DropBomb(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException { + public DropBomb(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException { super(game, player, direction); } 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 2728609..866bc50 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 @@ -9,7 +9,7 @@ import fr.lnl.game.server.games.player.Player; */ public class DropMine extends DropObject { - public DropMine(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException { + public DropMine(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException { super(game, player, direction); } 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 dedaabd..d146b25 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 @@ -16,14 +16,14 @@ import java.util.List; public abstract class DropObject extends AbstractAction { protected final Point point; - private final Direction4Axis direction; + private final Direction8Axis direction; /** * @param player basically current player * @param direction chosen direction * @throws NotValidDirectionException throw when the chosen direction is invalid */ - public DropObject(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException { + public DropObject(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException { super(game, player); List points = getValidPoint(); Point playerPosition = player.getPosition(); @@ -67,7 +67,7 @@ public abstract class DropObject extends AbstractAction { return listMoves; } - public Direction4Axis getDirection() { + public Direction8Axis getDirection() { return 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 9b4dff8..4640941 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 @@ -12,9 +12,9 @@ import java.util.List; public class Shot extends AbstractAction { private final Point point; - private final Direction8Axis direction; + private final Direction4Axis direction; - public Shot(Game game, Player player, Direction8Axis direction) throws NoMoreBulletInWeaponException, NotValidDirectionException { + public Shot(Game game, Player player, Direction4Axis direction) throws NoMoreBulletInWeaponException, NotValidDirectionException { super(game, player); if(player.getWeapon().getBullet() == 0) { throw new NoMoreBulletInWeaponException(); @@ -75,7 +75,7 @@ public class Shot extends AbstractAction { List listMoves = new ArrayList<>(); Point position = game.getCurrentPlayer().getPosition(); Weapon weapon = game.getCurrentPlayer().getWeapon(); - for(Direction8Axis direction : Direction8Axis.values()) { + for(Direction4Axis direction : Direction4Axis.values()) { Point neighbour = seeNeighbour(position, direction.getDeltaX(), direction.getDeltaY(), direction.isVertical() ? weapon.getVerticalDistance() : weapon.getHorizontalDistance()); if(neighbour != null) @@ -102,7 +102,6 @@ public class Shot extends AbstractAction { return null; } if(game.getGrid().getBoard().get(neighbour).getA() instanceof Player) { - System.out.println(game.getGrid().getBoard().get(neighbour).getA().getPosition()); return neighbour; } } 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 fab0c87..1e2b7b9 100644 --- a/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java +++ b/server/src/test/java/fr/lnl/game/server/ActionPlayerTest.java @@ -65,7 +65,7 @@ public class ActionPlayerTest { @Test public void shotActionTest(){ Action shot = null; - for(Direction8Axis direction : Direction8Axis.values()) { + for(Direction4Axis direction : Direction4Axis.values()) { try { shot = new Shot(game, game.getCurrentPlayer(), direction); break; @@ -84,8 +84,8 @@ public class ActionPlayerTest { public void dropBombActionTest() { Player player = game.getCurrentPlayer(); Action action = null; - Direction4Axis savedDirection = null; - for(Direction4Axis direction : Direction4Axis.values()) { + Direction8Axis savedDirection = null; + for(Direction8Axis direction : Direction8Axis.values()) { try { action = new DropBomb(game, game.getCurrentPlayer(), direction); savedDirection = direction;