Fix terminal view + fix dialog incorrect computer id
This commit is contained in:
parent
623e6b5fb3
commit
b6cc8f24f9
@ -52,7 +52,7 @@ public class App extends Application {
|
|||||||
| IllegalAccessException e) {
|
| IllegalAccessException e) {
|
||||||
throw new CrashException(e.getMessage(), e);
|
throw new CrashException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
viewManager = new ViewManager(playerList, game);
|
viewManager = new ViewManager(playerList, game, Window.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void launchTerminal() {
|
public static void launchTerminal() {
|
||||||
@ -62,7 +62,7 @@ public class App extends Application {
|
|||||||
| IllegalAccessException e) {
|
| IllegalAccessException e) {
|
||||||
throw new CrashException(e.getMessage(), e);
|
throw new CrashException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
viewManager = new ViewManager(playerList, game);
|
viewManager = new ViewManager(playerList, game, Terminal.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> parsePlayers() throws IllegalArgumentException, NoSuchMethodException,
|
public static List<Player> parsePlayers() throws IllegalArgumentException, NoSuchMethodException,
|
||||||
|
@ -2,6 +2,7 @@ package fr.lnl.game.client.listener;
|
|||||||
|
|
||||||
import fr.lnl.game.client.App;
|
import fr.lnl.game.client.App;
|
||||||
import fr.lnl.game.server.games.Game;
|
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.AbstractModelListening;
|
||||||
import fr.lnl.game.server.listener.ModelListener;
|
import fr.lnl.game.server.listener.ModelListener;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
@ -29,11 +30,12 @@ public class ButtonListener extends AbstractModelListening {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateModel(Object event) {
|
public void updateModel(Object event) {
|
||||||
|
Player player = game.getCurrentPlayer();
|
||||||
game.play();
|
game.play();
|
||||||
App.viewManager.updateView();
|
App.viewManager.updateView();
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
alert.setTitle("Un joueur ordinateur a joué");
|
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.setContentText("Il a joué l'action: " + game.getSelectedAction());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package fr.lnl.game.client.view;
|
|||||||
import fr.lnl.game.client.ClientPlayer;
|
import fr.lnl.game.client.ClientPlayer;
|
||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
import javafx.util.Duration;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -13,13 +12,27 @@ public class ViewManager {
|
|||||||
private final HashMap<Player, ClientPlayer> players;
|
private final HashMap<Player, ClientPlayer> players;
|
||||||
private final Game game;
|
private final Game game;
|
||||||
|
|
||||||
public ViewManager(HashMap<Player, ClientPlayer> players, Game game) {
|
public ViewManager(HashMap<Player, ClientPlayer> players, Game game, Class<? extends View> viewType) {
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.game = game;
|
this.game = game;
|
||||||
updateView();
|
if(viewType == Terminal.class) {
|
||||||
|
terminalView();
|
||||||
|
} else {
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateView() {
|
public void updateView() {
|
||||||
players.get(game.getCurrentPlayer()).getView().show();
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
package fr.lnl.game.server.listener;
|
package fr.lnl.game.server.listener;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.utils.CrashException;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class GameFinishEvent extends AbstractModelListening {
|
public class GameFinishEvent extends AbstractModelListening {
|
||||||
|
|
||||||
private final Object lock = new Object();
|
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
|
@Override
|
||||||
public void updateModel(Object obj) {
|
public void updateModel(Object obj) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
throw new CrashException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user