add javadoc to actions, delete gradle.properties

This commit is contained in:
Quentin Legot 2021-12-08 16:08:33 +01:00
parent 938eefe387
commit 03be6c2a78
16 changed files with 127 additions and 29 deletions

View File

@ -5,7 +5,4 @@ subprojects {
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
}
compileJava {
// options.encoding = "UTF-8"
}
}

View File

@ -1,2 +0,0 @@
# org.gradle.jvmargs='-Dfile.encoding=UTF-8'
systemProp.file.encoding=UTF-8

View File

@ -17,19 +17,4 @@ public abstract class AbstractAction implements Action {
this.player = player;
}
protected Point choseRandomPoint(List<Point> 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;
}
}

View File

@ -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<Point> getValidPoint();
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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));

View File

@ -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));

View File

@ -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<Point> 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<Point> getValidPoint() {
List<Point> listMoves = new ArrayList<>();
HashMap<Point, Pair<Player, Box>> board = game.getGrid().getBoard();

View File

@ -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<Point> getValidPoint() {
List<Point> listMoves = new ArrayList<>();

View File

@ -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() {

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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<Point> getValidPoint() {
List<Point> 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;

View File

@ -0,0 +1,4 @@
/**
* Package storing all actions a player can do
*/
package fr.lnl.game.server.games.action;