Add useful functions and class

This commit is contained in:
Katchan 2021-12-07 21:37:16 +01:00
parent bf37f32407
commit 4958c7688e
5 changed files with 58 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import java.util.List;
public abstract class DropObject extends AbstractAction { public abstract class DropObject extends AbstractAction {
protected final Point point; protected final Point point;
private final Direction direction;
public DropObject(Game game, Player player, Direction direction) throws NotValidDirectionException { public DropObject(Game game, Player player, Direction direction) throws NotValidDirectionException {
super(game, player); super(game, player);
@ -23,6 +24,7 @@ public abstract class DropObject extends AbstractAction {
throw new NotValidDirectionException(direction + " isn't a valid position"); throw new NotValidDirectionException(direction + " isn't a valid position");
} }
this.point = dropDirection; this.point = dropDirection;
this.direction = direction;
} }
@Override @Override
@ -48,5 +50,8 @@ public abstract class DropObject extends AbstractAction {
return listMoves; return listMoves;
} }
public Direction getDirection() {
return direction;
}
} }

View File

@ -15,6 +15,7 @@ import java.util.List;
public class Move extends AbstractAction { public class Move extends AbstractAction {
private final Point point; private final Point point;
private final Direction direction;
public Move(Game game, Player player, Direction direction) throws NotValidDirectionException { public Move(Game game, Player player, Direction direction) throws NotValidDirectionException {
super(game, player); super(game, player);
@ -25,6 +26,7 @@ public class Move extends AbstractAction {
throw new NotValidDirectionException(direction + " isn't a valid position"); throw new NotValidDirectionException(direction + " isn't a valid position");
} }
this.point = newPosition; this.point = newPosition;
this.direction = direction;
} }
@Override @Override
@ -64,4 +66,10 @@ public class Move extends AbstractAction {
} }
return listMoves; return listMoves;
} }
public Direction getDirection() {
return direction;
}
} }

View File

@ -0,0 +1,38 @@
package fr.lnl.game.server.games.action;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ReunionSameAction {
private final String actionName;
private List<Action> actions;
public ReunionSameAction(String actionName){
this.actionName = actionName;
this.actions = new ArrayList<>();
}
public ReunionSameAction(String actionName, Action action){
this(actionName);
this.actions = new ArrayList<>(List.of(action));
}
public List<Action> getActions() {
return actions;
}
public String getActionName() {
return actionName;
}
public Action getAction(int value) {
return getActions().get(value);
}
public void addAction(Action action) {
this.actions.add(action);
}
}

View File

@ -36,6 +36,7 @@ public class Shot extends AbstractAction {
for(int i=0; i < range; i++) { for(int i=0; i < range; i++) {
Point point = new Point(this.point.getA() + (i * direction.getDeltaX()), Point point = new Point(this.point.getA() + (i * direction.getDeltaX()),
this.point.getB() + (i * direction.getDeltaY())); 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(); Player player = game.getGrid().getBoard().get(point).getA();
if(player != null) { if(player != null) {
player.decrementEnergy(player.getClassPlayer().getPenaltyShoot()); player.decrementEnergy(player.getClassPlayer().getPenaltyShoot());
@ -83,4 +84,8 @@ public class Shot extends AbstractAction {
} }
return null; return null;
} }
public Point getPoint() {
return point;
}
} }

View File

@ -12,9 +12,9 @@ public class Maths {
return Integer.parseInt(entry); return Integer.parseInt(entry);
} }
public static float testFloat(String entry, Scanner scanner) { public static float testFloat(String entry, Scanner scanner, String error) {
while (!isFloat(entry)) { while (!isFloat(entry)) {
System.out.println("\033[0;31mErreur de saisie\033[0m : Veuillez rentrer une valeur correcte !"); System.out.println(Error.Entry_Error_Message + error);
entry = scanner.next(); entry = scanner.next();
} }
return Integer.parseInt(entry); return Integer.parseInt(entry);