diff --git a/client/src/main/java/fr/lnl/game/client/App.java b/client/src/main/java/fr/lnl/game/client/App.java index 574a030..4e7cfa5 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -52,7 +52,7 @@ public class App extends Application { | IllegalAccessException e) { throw new CrashException(e.getMessage(), e); } - viewManager = new ViewManager(playerList, game); + viewManager = new ViewManager(playerList, game, Window.class); } public static void launchTerminal() { @@ -62,7 +62,7 @@ public class App extends Application { | IllegalAccessException e) { throw new CrashException(e.getMessage(), e); } - viewManager = new ViewManager(playerList, game); + viewManager = new ViewManager(playerList, game, Terminal.class); } public static List parsePlayers() throws IllegalArgumentException, NoSuchMethodException, diff --git a/client/src/main/java/fr/lnl/game/client/listener/ButtonListener.java b/client/src/main/java/fr/lnl/game/client/listener/ButtonListener.java index 4d8e7f4..e557008 100644 --- a/client/src/main/java/fr/lnl/game/client/listener/ButtonListener.java +++ b/client/src/main/java/fr/lnl/game/client/listener/ButtonListener.java @@ -2,6 +2,7 @@ package fr.lnl.game.client.listener; import fr.lnl.game.client.App; import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.listener.AbstractModelListening; import fr.lnl.game.server.listener.ModelListener; import javafx.scene.control.Alert; @@ -29,11 +30,12 @@ public class ButtonListener extends AbstractModelListening { @Override public void updateModel(Object event) { + Player player = game.getCurrentPlayer(); game.play(); App.viewManager.updateView(); Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Un joueur ordinateur a joué"); - alert.setHeaderText("Le joueur ordinateur numéro" + game.getCurrentPlayer().getId() + " a joué"); + alert.setHeaderText("Le joueur ordinateur numéro" + player.getId() + " a joué"); alert.setContentText("Il a joué l'action: " + game.getSelectedAction()); alert.showAndWait(); } diff --git a/client/src/main/java/fr/lnl/game/client/view/ViewManager.java b/client/src/main/java/fr/lnl/game/client/view/ViewManager.java index c71bfd3..de0f468 100644 --- a/client/src/main/java/fr/lnl/game/client/view/ViewManager.java +++ b/client/src/main/java/fr/lnl/game/client/view/ViewManager.java @@ -3,7 +3,6 @@ package fr.lnl.game.client.view; import fr.lnl.game.client.ClientPlayer; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.player.Player; -import javafx.util.Duration; import java.util.HashMap; @@ -13,13 +12,27 @@ public class ViewManager { private final HashMap players; private final Game game; - public ViewManager(HashMap players, Game game) { + public ViewManager(HashMap players, Game game, Class viewType) { this.players = players; this.game = game; - updateView(); + if(viewType == Terminal.class) { + terminalView(); + } else { + updateView(); + } } public void updateView() { players.get(game.getCurrentPlayer()).getView().show(); } + + public void terminalView() { + while(true) { + Player player = game.getCurrentPlayer(); + players.get(game.getCurrentPlayer()).getView().show(); + game.play(); + System.out.println("Le joueur ordinateur numéro" + player.getId() + " a joué"); + System.out.println("Il a joué l'action: " + game.getSelectedAction()); + } + } } diff --git a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java index 183b1ea..c706c06 100644 --- a/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java +++ b/server/src/main/java/fr/lnl/game/server/listener/GameFinishEvent.java @@ -1,16 +1,21 @@ package fr.lnl.game.server.listener; +import fr.lnl.game.server.utils.CrashException; + +import java.util.concurrent.TimeUnit; + public class GameFinishEvent extends AbstractModelListening { private final Object lock = new Object(); + // TODO: 02/12/2021 méthode a revoir, notamment surement mettre un dialog sur la view Window et fermer dès que l'utilisateur a cliqué sur ok @Override public void updateModel(Object obj) { synchronized (lock) { try { - Thread.sleep(1000); + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); } catch (InterruptedException e) { - e.printStackTrace(); + throw new CrashException(e.getMessage(), e); } } System.exit(0);