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 55320bb..da4880a 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,8 @@ public class DeployShield extends AbstractAction { @Override public void doAction(){ - + getGame().getCurrent_player().setShieldDeploy(true); + //TO-DO retirer les point du player } @Override 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 32d88d7..8bd298d 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 @@ -1,6 +1,9 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.utils.Point; + +import java.util.List; public class DropBomb extends DropObject { @@ -15,6 +18,13 @@ public class DropBomb extends DropObject { @Override public boolean isPossible() { - return false; + return super.isPossible(); } + + @Override + public List getValidPoint() { + return super.getValidPoint(); + } + } + 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 bfdee35..7d020ba 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 @@ -1,6 +1,11 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.grid.Mine; +import fr.lnl.game.server.utils.Point; + +import java.util.List; +import java.util.Random; public class DropMine extends DropObject { public DropMine(Game game){ @@ -8,11 +13,22 @@ public class DropMine extends DropObject { } @Override public void doAction() { - super.doAction(); + List points = getValidPoint(); + Random random = new Random(); + Point point = points.get(random.nextInt(0,points.size()-1)); + Mine mine = new Mine(); + getGame().getGrid().getBoard().get(point).setB(mine); + //TO-DO : retirer les points au player } @Override public boolean isPossible() { - return false; + return super.isPossible(); } + + @Override + public List getValidPoint() { + return super.getValidPoint(); + } + } 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 c2b234c..6202198 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 @@ -1,6 +1,17 @@ package fr.lnl.game.server.games.action; import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.grid.Box; +import fr.lnl.game.server.games.grid.Grid; +import fr.lnl.game.server.games.grid.Wall; +import fr.lnl.game.server.games.player.Player; +import fr.lnl.game.server.utils.Pair; +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 { @@ -10,6 +21,30 @@ public abstract class DropObject extends AbstractAction { @Override public void doAction() { - } + + @Override + public boolean isPossible() { + return getValidPoint().isEmpty(); + } + + public List getValidPoint() { + List listMoves = new LinkedList<>(); + HashMap> board = getGame().getGrid().getBoard(); + 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); + } + } + } + } + return listMoves; + } + + } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Nothing.java b/server/src/main/java/fr/lnl/game/server/games/action/Nothing.java index 20f0531..fa87d98 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Nothing.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Nothing.java @@ -8,7 +8,7 @@ public class Nothing extends AbstractAction { super(game); } @Override - public void doAction() { + public void doAction(){ } 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 ab14fbc..d279b19 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 @@ -1,7 +1,20 @@ package fr.lnl.game.server.games.player; +import fr.lnl.game.server.games.action.Action; +import fr.lnl.game.server.games.weapon.Weapon; import fr.lnl.game.server.utils.Point; public interface Player { Point getPoint(); + boolean isAlive(); + int getId(); + int getEnergy(); + Weapon getWeapon(); + boolean isShieldDeploy(); + void setEnergy(int energy); + void setShieldDeploy(boolean shieldDeploy); + void setWeapon(Weapon weapon); + Action[] getActions(); + ClassPlayer getClassPlayer(); + void setPoint(Point point); }