diff --git a/client/src/main/java/fr/lnl/game/client/listener/DisplayWinnerEvent.java b/client/src/main/java/fr/lnl/game/client/listener/DisplayWinnerEvent.java index 3862cf6..d732f8e 100644 --- a/client/src/main/java/fr/lnl/game/client/listener/DisplayWinnerEvent.java +++ b/client/src/main/java/fr/lnl/game/client/listener/DisplayWinnerEvent.java @@ -5,6 +5,7 @@ import fr.lnl.game.server.listener.AbstractModelListening; public class DisplayWinnerEvent extends AbstractModelListening { + // TODO: 07/12/2021 PROBLEM -> ViewManager retourne null @Override public void updateModel(Object obj) { App.getViewManager().displayWinner(App.getGame().getWinner()); diff --git a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java index 2a83908..7abd96c 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/HumanPlayer.java @@ -1,32 +1,82 @@ package fr.lnl.game.server.games.player; -import fr.lnl.game.server.games.action.Action; +import fr.lnl.game.server.games.action.*; import fr.lnl.game.server.utils.Maths; import fr.lnl.game.server.utils.Point; + +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; public class HumanPlayer extends AbstractPlayer { + private List actions; + public HumanPlayer(Integer id, Point point, ClassPlayer classPlayer) { super(id, point,false, classPlayer); } @Override + // TODO: 07/12/2021 Retirer les scanners pour respecter le MVC public Action choseAction() { - String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + getActions().size(); + actions = new ArrayList<>(); + for (Action a : getActions()) { + ReunionSameAction reunionFilter = actions.stream().filter(r -> r.getActionName().equals(a.getClass().getSimpleName())).findFirst().orElse(null); + if(reunionFilter != null){ + reunionFilter.addAction(a); + } + else{ + actions.add(new ReunionSameAction(a.getClass().getSimpleName(),a)); + } + } + List listActions = choseReunionSameAction().getActions(); Action action = null; + String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + listActions.size(); Scanner scanner = new Scanner(System.in); do{ - System.out.println("Choisissez une action :"); - for (int i = 0; i < getActions().size(); i++) { - System.out.println((i + 1) + " : " + getActions().get(i).getClass().getSimpleName()); + if(listActions.size() == 1){ + return listActions.get(0); + } + System.out.println("Choisissez la cible :"); + for (int i = 0; i < listActions.size(); i++) { + Action a = listActions.get(i); + if(a instanceof Move){ + System.out.println(i + 1 + " : " + ((Move) a).getDirection()); + } + else if(a instanceof DropObject){ + System.out.println(i + 1 + " : " + ((DropObject) a).getDirection()); + } + else if(a instanceof Shot){ + System.out.println(i + 1 + " : " + ((Shot) a).getPoint()); + } + else{ + System.out.println(i + 1 + " : " + a.getClass().getSimpleName()); + } } String entry = scanner.next(); - int value = Maths.testInteger(entry,scanner,error); - if(value >= 1 && value <= getActions().size()){ - action = getActions().get(value - 1); + int value = Maths.testInteger(entry, scanner, error); + if (value >= 1 && value <= listActions.size()) { + action = listActions.get(value - 1); } - }while(action == null); + }while (action == null); return action; } + + public ReunionSameAction choseReunionSameAction(){ + ReunionSameAction reunion = null; + String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + actions.size(); + Scanner scanner = new Scanner(System.in); + do { + System.out.println("Choisissez une action :"); + for (int i = 0; i < actions.size(); i++) { + System.out.println(i + 1 + " : " + actions.get(i).getActionName()); + } + String entry = scanner.next(); + int value = Maths.testInteger(entry, scanner, error); + if (value >= 1 && value <= actions.size()) { + reunion = actions.get(value - 1); + } + }while (reunion == null) ; + return reunion; + } }