From cd166fa8091ee13605c1dc1fb68b1a21d0b9671b Mon Sep 17 00:00:00 2001 From: Katchan Date: Thu, 21 Oct 2021 17:19:05 +0200 Subject: [PATCH] Add move doAction --- .../fr/lnl/game/server/games/action/Move.java | 21 +++++++++++++------ .../fr/lnl/game/server/games/grid/Grid.java | 12 ----------- .../server/games/player/AbstractPlayer.java | 4 ++++ .../lnl/game/server/games/player/Player.java | 1 + 4 files changed, 20 insertions(+), 18 deletions(-) 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 b37e418..b14db44 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 @@ -11,6 +11,7 @@ import fr.lnl.game.server.utils.Point; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Random; public class Move extends AbstractAction { public Move(Game game) { @@ -19,7 +20,13 @@ public class Move extends AbstractAction { @Override public void doAction() { - + List points = getValidPoint(); + Random random = new Random(); + Point nextPositon = points.get(random.nextInt(0,points.size() - 1)); + Player player = getGame().getCurrent_player(); + getGame().getGrid().getBoard().get(player.getPoint()).setA(null); + getGame().getGrid().getBoard().get(nextPositon).setA(player); + player.decrementEnergy(player.getClassPlayer().getMoveCost()); } @Override @@ -33,11 +40,13 @@ public class Move extends AbstractAction { Point position = getGame().getCurrent_player().getPoint(); for (int row = -1; row <= 1; row++) { for (int column = -1; column <= 1; column++) { - if(Grid.caseisValid(position.getA(),row,position.getB(),column)){ - Point neighbour = new Point(position.getA() + row, position.getB() + column); - Pair state = board.get(neighbour); - if(state.getA() == null || state.getB() instanceof Wall){ - listMoves.add(neighbour); + if(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){ + if(Grid.caseisValid(position.getA(),row,position.getB(),column)){ + Point neighbour = new Point(position.getA() + row, position.getB() + column); + Pair state = board.get(neighbour); + if(state.getA() == null || state.getB() instanceof Wall){ + listMoves.add(neighbour); + } } } } 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 a89b997..6a21297 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 @@ -49,28 +49,16 @@ public class Grid { } } - /** - * @deprecated A utiliser seulement pour les tests, voir GridTest dans le dossier test - */ - @Deprecated public void placePlayersBRUT(){ board.get(new Point(1,1)).setA(players[0]); board.get(new Point(14,14)).setA(players[1]); } - /** - * @deprecated idem que {@link Grid#placePlayersBRUT()} - */ - @Deprecated public void placeEnergyBallBRUT(){ board.get(new Point(2,3)).setB(new EnergyBall()); board.get(new Point(7,10)).setB(new EnergyBall()); } - /** - * @deprecated idem que {@link Grid#placePlayersBRUT()} - */ - @Deprecated public void placeInternWallBRUT(){ board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); diff --git a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java index 28df0a1..83e2763 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java @@ -70,4 +70,8 @@ public abstract class AbstractPlayer implements Player { public void setPoint(Point point){ this.point = point; } + + public void decrementEnergy(int energy){ + this.energy -= energy; + } } 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 d279b19..b858e5e 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 @@ -17,4 +17,5 @@ public interface Player { Action[] getActions(); ClassPlayer getClassPlayer(); void setPoint(Point point); + void decrementEnergy(int energy); }