diff --git a/build.gradle b/build.gradle index 6876522..ebdf119 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,4 @@ subprojects { javadoc { options.memberLevel = JavadocMemberLevel.PRIVATE } - compileJava { - // options.encoding = "UTF-8" - } } diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 98a0792..0000000 --- a/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -# org.gradle.jvmargs='-Dfile.encoding=UTF-8' -systemProp.file.encoding=UTF-8 \ No newline at end of file diff --git a/server/src/main/java/fr/lnl/game/server/games/action/AbstractAction.java b/server/src/main/java/fr/lnl/game/server/games/action/AbstractAction.java index 5a36fb6..72212f1 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/AbstractAction.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/AbstractAction.java @@ -17,19 +17,4 @@ public abstract class AbstractAction implements Action { this.player = player; } - protected Point choseRandomPoint(List getValidPoint) { - Point point = null; - switch (getValidPoint.size()) { - case 0: - break; - case 1: - point = getValidPoint.get(0); - break; - default: { - Random random = new Random(); - point = getValidPoint.get(random.nextInt(0, getValidPoint.size())); - } - } - return point; - } } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Action.java b/server/src/main/java/fr/lnl/game/server/games/action/Action.java index 4b136e5..325caa4 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Action.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Action.java @@ -6,8 +6,22 @@ import fr.lnl.game.server.utils.Point; import java.util.List; public interface Action { + + /** + * Call by {@link fr.lnl.game.server.games.Game} when player do this action + */ void doAction(); + + /** + * + * @return true if this action is possible, false otherwise + */ boolean isPossible(); + + /** + * Used by {@link Move}, {@link Shot} and {@link DropObject} to list all direction when the action is possible + * @return a list a point where the action is possible (not block by a wall per example) + */ List getValidPoint(); } 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 559b62a..955812f 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 @@ -5,18 +5,28 @@ import fr.lnl.game.server.utils.Point; import java.util.List; +/** + * Used when a player want to protect himself from taking damage (shield state is reset to false at next player turn) + */ public class DeployShield extends AbstractAction { public DeployShield(Player player){ super(null, player); } + /** + * Deploy player shield and decrement its energy + */ @Override public void doAction(){ - player.setShieldDeploy(true); player.decrementEnergy(player.getClassPlayer().getShieldCost()); + player.setShieldDeploy(true); } + /** + * This action is always possible + * @return always true + */ @Override public boolean isPossible() { return true; diff --git a/server/src/main/java/fr/lnl/game/server/games/action/Direction.java b/server/src/main/java/fr/lnl/game/server/games/action/Direction.java index 852519e..5c7c8cb 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/Direction.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/Direction.java @@ -1,5 +1,8 @@ package fr.lnl.game.server.games.action; +/** + * Enum used to chose where to move, shot, etc. + */ public enum Direction { UP(-1, 0, true), @@ -25,6 +28,11 @@ public enum 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 0b7bea8..c8ae35a 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 @@ -4,12 +4,18 @@ import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.elements.Bomb; import fr.lnl.game.server.games.player.Player; +/** + * Used when player want to drop a {@link Bomb}, bomb explode when someone walks on it and after 3 turns + */ public class DropBomb extends DropObject { public DropBomb(Game game, Player player, Direction direction) throws NotValidDirectionException { super(game, player, direction); } + /** + * Drop a bomb in player's selected direction and decrement its energy + */ @Override public void doAction() { game.getGrid().getBoard().get(point).setB(new Bomb(point, game)); 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 ef27572..926c7d5 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 @@ -4,6 +4,9 @@ import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.grid.elements.Mine; import fr.lnl.game.server.games.player.Player; +/** + * Used when player want to drop a {@link Mine}, Mine only explode when someone walks on it + */ public class DropMine extends DropObject { public DropMine(Game game, Player player, Direction direction) throws NotValidDirectionException { @@ -11,6 +14,9 @@ public class DropMine extends DropObject { } + /** + * Drop a mine in player's selected direction and decrement its energy + */ @Override public void doAction() { game.getGrid().getBoard().get(point).setB(new Mine(player)); 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 8c7aaf9..e6f123b 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 @@ -10,11 +10,19 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +/** + * Super class used by {@link DropMine} and {@link DropBomb} + */ public abstract class DropObject extends AbstractAction { protected final Point point; private final Direction 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, Direction direction) throws NotValidDirectionException { super(game, player); List points = getValidPoint(); @@ -27,11 +35,20 @@ public abstract class DropObject extends AbstractAction { this.direction = direction; } + /** + * + * @return true if player can play this action in current context, false otherwise + */ @Override public boolean isPossible() { return !getValidPoint().isEmpty(); } + /** + * @return a list of point where it's possible to place a bomb of a mine. + * We add a point where there is nothing on the board. + * @see Action#getValidPoint() + */ public List getValidPoint() { List listMoves = new ArrayList<>(); HashMap> board = game.getGrid().getBoard(); 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 bf99450..597cf1c 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 @@ -12,6 +12,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +/** + * Used when the player want to move in a direction, it can move in a direction when there is another player or a wall + */ public class Move extends AbstractAction { private final Point point; @@ -29,6 +32,9 @@ public class Move extends AbstractAction { this.direction = direction; } + /** + * Move player to its new position and decrement its point + */ @Override public void doAction() { game.getGrid().getBoard().get(player.getPosition()).setA(null); @@ -41,11 +47,19 @@ public class Move extends AbstractAction { } } + /** + * @return true if player can play this action in current context, false otherwise + */ @Override public boolean isPossible() { return !getValidPoint().isEmpty(); } + /** + * @return a list of point where it's possible to move. + * We add a point to the list where there is nothing on the board. + * @see Action#getValidPoint() + */ @Override public List getValidPoint() { List listMoves = new ArrayList<>(); diff --git a/server/src/main/java/fr/lnl/game/server/games/action/NoMoreBulletInWeaponException.java b/server/src/main/java/fr/lnl/game/server/games/action/NoMoreBulletInWeaponException.java index b7cdb76..06ecde2 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/NoMoreBulletInWeaponException.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/NoMoreBulletInWeaponException.java @@ -1,5 +1,8 @@ package fr.lnl.game.server.games.action; +/** + * This exception is throw when player has no remaining bullet + */ public class NoMoreBulletInWeaponException extends Exception { public NoMoreBulletInWeaponException() { diff --git a/server/src/main/java/fr/lnl/game/server/games/action/NotValidDirectionException.java b/server/src/main/java/fr/lnl/game/server/games/action/NotValidDirectionException.java index 4958a88..f360c89 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/NotValidDirectionException.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/NotValidDirectionException.java @@ -1,5 +1,8 @@ package fr.lnl.game.server.games.action; +/** + * throw when action instantiated and the chosen direction in constructor isn't valid + */ public class NotValidDirectionException extends Exception { public NotValidDirectionException(String message) { 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 64793a2..c6c2b20 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 @@ -4,16 +4,26 @@ import fr.lnl.game.server.utils.Point; import java.util.List; +/** + * This action is used when player doesn't want to move and/or loose energy + */ public class Nothing extends AbstractAction { public Nothing() { super(null, null); } + /** + * doAction in this context don't execute any operation + */ @Override public void doAction(){ } + /** + * This action is always possible + * @return always true + */ @Override public boolean isPossible() { return true; diff --git a/server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java b/server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java index abcd0f6..553562d 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java @@ -4,6 +4,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +/** + * When we generate action, we generate one per available direction (like in {@link Move}) but to improve human + * readability, we list every same Action here + */ public class ReunionSameAction { private final String actionName; 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 1908ca5..843acd1 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 @@ -29,6 +29,10 @@ public class Shot extends AbstractAction { this.direction = direction; } + /** + * We decrement player's energy and shot on every of its opponents on the chosen direction by decrementing its + * energy too + */ @Override public void doAction() { player.decrementEnergy(player.getClassPlayer().getShootCost()); @@ -36,22 +40,30 @@ public class Shot extends AbstractAction { for(int i=0; i < range; i++) { Point point = new Point(this.point.getA() + (i * direction.getDeltaX()), this.point.getB() + (i * direction.getDeltaY())); - // TODO: 07/12/2021 WARNING -> probleme de nullpointerexeption sur getA car on verif pas la sortie de terrain - Player player = game.getGrid().getBoard().get(point).getA(); - if(player != null) { - player.decrementEnergy(player.getClassPlayer().getPenaltyShoot()); - System.out.println("Not null: " + point); - } else { - System.out.println("null:" + point); + if(game.getGrid().boardPositionIsValid(point)) { + Player player = game.getGrid().getBoard().get(point).getA(); + if(player != null) { + player.decrementEnergy(player.getClassPlayer().getPenaltyShoot()); + } } + } } + /** + * @return true if player can play this action in current context, false otherwise + */ @Override public boolean isPossible() { return !getValidPoint().isEmpty(); } + /** + * @return a list of point where it's possible to shot. + * We add a point to the list where there is a player depending on the direction and the distance the weapon can + * shoot. + * @see Action#getValidPoint() + */ @Override public List getValidPoint() { List listMoves = new ArrayList<>(); @@ -66,7 +78,14 @@ public class Shot extends AbstractAction { return listMoves; } - + /** + * + * @param point player current position + * @param deltaX given by {@link Direction} + * @param deltaY given by {@link Direction} + * @param range given by {@link Weapon#getHorizontalDistance()} or {@link Weapon#getVerticalDistance()} + * @return true if there is a player in the chosen direction, false otherwise + */ public Point seeNeighbour(Point point, int deltaX, int deltaY, int range) { if(range == 0) return null; diff --git a/server/src/main/java/fr/lnl/game/server/games/action/package-info.java b/server/src/main/java/fr/lnl/game/server/games/action/package-info.java new file mode 100644 index 0000000..0ac3993 --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/games/action/package-info.java @@ -0,0 +1,4 @@ +/** + * Package storing all actions a player can do + */ +package fr.lnl.game.server.games.action; \ No newline at end of file