Add human terminal choseAction
This commit is contained in:
parent
a6b9b69d9b
commit
2e5fcd2a05
@ -5,6 +5,7 @@ import fr.lnl.game.server.listener.AbstractModelListening;
|
|||||||
|
|
||||||
public class DisplayWinnerEvent extends AbstractModelListening {
|
public class DisplayWinnerEvent extends AbstractModelListening {
|
||||||
|
|
||||||
|
// TODO: 07/12/2021 PROBLEM -> ViewManager retourne null
|
||||||
@Override
|
@Override
|
||||||
public void updateModel(Object obj) {
|
public void updateModel(Object obj) {
|
||||||
App.getViewManager().displayWinner(App.getGame().getWinner());
|
App.getViewManager().displayWinner(App.getGame().getWinner());
|
||||||
|
@ -1,32 +1,82 @@
|
|||||||
package fr.lnl.game.server.games.player;
|
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.Maths;
|
||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class HumanPlayer extends AbstractPlayer {
|
public class HumanPlayer extends AbstractPlayer {
|
||||||
|
|
||||||
|
private List<ReunionSameAction> actions;
|
||||||
|
|
||||||
public HumanPlayer(Integer id, Point point, ClassPlayer classPlayer) {
|
public HumanPlayer(Integer id, Point point, ClassPlayer classPlayer) {
|
||||||
super(id, point,false, classPlayer);
|
super(id, point,false, classPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// TODO: 07/12/2021 Retirer les scanners pour respecter le MVC
|
||||||
public Action choseAction() {
|
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<Action> listActions = choseReunionSameAction().getActions();
|
||||||
Action action = null;
|
Action action = null;
|
||||||
|
String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + listActions.size();
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
do{
|
do{
|
||||||
System.out.println("Choisissez une action :");
|
if(listActions.size() == 1){
|
||||||
for (int i = 0; i < getActions().size(); i++) {
|
return listActions.get(0);
|
||||||
System.out.println((i + 1) + " : " + getActions().get(i).getClass().getSimpleName());
|
}
|
||||||
|
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();
|
String entry = scanner.next();
|
||||||
int value = Maths.testInteger(entry, scanner, error);
|
int value = Maths.testInteger(entry, scanner, error);
|
||||||
if(value >= 1 && value <= getActions().size()){
|
if (value >= 1 && value <= listActions.size()) {
|
||||||
action = getActions().get(value - 1);
|
action = listActions.get(value - 1);
|
||||||
}
|
}
|
||||||
}while (action == null);
|
}while (action == null);
|
||||||
return action;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user