From 4958c7688ea2ba2011319b32f71596577ba18096 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Tue, 7 Dec 2021 21:37:16 +0100 Subject: [PATCH] Add useful functions and class --- .../game/server/games/action/DropObject.java | 5 +++ .../fr/lnl/game/server/games/action/Move.java | 8 ++++ .../games/action/ReunionSameAction.java | 38 +++++++++++++++++++ .../fr/lnl/game/server/games/action/Shot.java | 5 +++ .../java/fr/lnl/game/server/utils/Maths.java | 4 +- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java 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 b4123fe..8c7aaf9 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 @@ -13,6 +13,7 @@ import java.util.List; public abstract class DropObject extends AbstractAction { protected final Point point; + private final Direction direction; public DropObject(Game game, Player player, Direction direction) throws NotValidDirectionException { super(game, player); @@ -23,6 +24,7 @@ public abstract class DropObject extends AbstractAction { throw new NotValidDirectionException(direction + " isn't a valid position"); } this.point = dropDirection; + this.direction = direction; } @Override @@ -48,5 +50,8 @@ public abstract class DropObject extends AbstractAction { return listMoves; } + public Direction getDirection() { + return direction; + } } 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 c1516fe..bf99450 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 @@ -15,6 +15,7 @@ import java.util.List; public class Move extends AbstractAction { private final Point point; + private final Direction direction; public Move(Game game, Player player, Direction direction) throws NotValidDirectionException { super(game, player); @@ -25,6 +26,7 @@ public class Move extends AbstractAction { throw new NotValidDirectionException(direction + " isn't a valid position"); } this.point = newPosition; + this.direction = direction; } @Override @@ -64,4 +66,10 @@ public class Move extends AbstractAction { } return listMoves; } + + public Direction getDirection() { + return direction; + } + + } 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 new file mode 100644 index 0000000..abcd0f6 --- /dev/null +++ b/server/src/main/java/fr/lnl/game/server/games/action/ReunionSameAction.java @@ -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 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 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); + } +} 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 9a1c704..1908ca5 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 @@ -36,6 +36,7 @@ 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()); @@ -83,4 +84,8 @@ public class Shot extends AbstractAction { } return null; } + + public Point getPoint() { + return point; + } } diff --git a/server/src/main/java/fr/lnl/game/server/utils/Maths.java b/server/src/main/java/fr/lnl/game/server/utils/Maths.java index eceb872..059c55f 100644 --- a/server/src/main/java/fr/lnl/game/server/utils/Maths.java +++ b/server/src/main/java/fr/lnl/game/server/utils/Maths.java @@ -12,9 +12,9 @@ public class Maths { 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)) { - 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(); } return Integer.parseInt(entry);