add dialog when game finish (#1)
This commit is contained in:
parent
db2e2e1f7a
commit
c07266a763
@ -1,5 +1,6 @@
|
|||||||
package fr.lnl.game.client;
|
package fr.lnl.game.client;
|
||||||
|
|
||||||
|
import fr.lnl.game.client.listener.DisplayWinnerEvent;
|
||||||
import fr.lnl.game.client.view.AbstractView;
|
import fr.lnl.game.client.view.AbstractView;
|
||||||
import fr.lnl.game.client.view.Terminal;
|
import fr.lnl.game.client.view.Terminal;
|
||||||
import fr.lnl.game.client.view.ViewManager;
|
import fr.lnl.game.client.view.ViewManager;
|
||||||
@ -22,8 +23,8 @@ public class App extends Application {
|
|||||||
|
|
||||||
private static LinkedList<String> argsList;
|
private static LinkedList<String> argsList;
|
||||||
public static HashMap<Player, ClientPlayer> playerList = new HashMap<>();
|
public static HashMap<Player, ClientPlayer> playerList = new HashMap<>();
|
||||||
public static Game game;
|
private static Game game;
|
||||||
public static ViewManager viewManager;
|
private static ViewManager viewManager;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
argsList = new LinkedList<>(Arrays.asList(args));
|
argsList = new LinkedList<>(Arrays.asList(args));
|
||||||
@ -46,7 +47,7 @@ public class App extends Application {
|
|||||||
List<Player> players = parsePlayers();
|
List<Player> players = parsePlayers();
|
||||||
Grid grid = new Grid(12, 12, players);
|
Grid grid = new Grid(12, 12, players);
|
||||||
BuildStrategy buildStrategy = new LockStrategy(grid, 0.80F, 0.95F);
|
BuildStrategy buildStrategy = new LockStrategy(grid, 0.80F, 0.95F);
|
||||||
game = new Game(buildStrategy, players, new GameFinishEvent());
|
game = new Game(buildStrategy, players, new DisplayWinnerEvent());
|
||||||
for (Player player : game.getPlayers()) {
|
for (Player player : game.getPlayers()) {
|
||||||
playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
||||||
}
|
}
|
||||||
@ -135,4 +136,12 @@ public class App extends Application {
|
|||||||
}
|
}
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ViewManager getViewManager() {
|
||||||
|
return viewManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Game getGame() {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,7 @@ public class ButtonListener extends AbstractModelListening {
|
|||||||
public void updateModel(Object event) {
|
public void updateModel(Object event) {
|
||||||
Player player = game.getCurrentPlayer();
|
Player player = game.getCurrentPlayer();
|
||||||
game.play();
|
game.play();
|
||||||
/*
|
/* 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" + player.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()); */
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package fr.lnl.game.client.listener;
|
||||||
|
|
||||||
|
import fr.lnl.game.client.App;
|
||||||
|
import fr.lnl.game.server.listener.AbstractModelListening;
|
||||||
|
|
||||||
|
public class DisplayWinnerEvent extends AbstractModelListening {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateModel(Object obj) {
|
||||||
|
App.getViewManager().displayWinner(App.getGame().getWinner());
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,12 @@ public class Terminal extends AbstractView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
// TODO: 26/10/2021
|
|
||||||
System.out.println(game.getGrid().toString());
|
System.out.println(game.getGrid().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayWinner(Player winner) {
|
||||||
|
System.out.println("Le joueur " + winner + " a gagné la partie");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.games.player.Player;
|
||||||
|
|
||||||
public interface View {
|
public interface View {
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
|
void displayWinner(Player winner);
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,8 @@ public class ViewManager {
|
|||||||
System.out.println("Il a joué l'action: " + game.getSelectedAction());
|
System.out.println("Il a joué l'action: " + game.getSelectedAction());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayWinner(Player winner) {
|
||||||
|
players.get(game.getCurrentPlayer()).getView().displayWinner(winner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
|
import fr.lnl.game.client.App;
|
||||||
import fr.lnl.game.client.listener.ButtonListener;
|
import fr.lnl.game.client.listener.ButtonListener;
|
||||||
import fr.lnl.game.client.listener.ClientEventHandler;
|
import fr.lnl.game.client.listener.ClientEventHandler;
|
||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
@ -10,6 +11,7 @@ import fr.lnl.game.server.utils.Pair;
|
|||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
@ -42,6 +44,16 @@ public class Window extends AbstractView {
|
|||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayWinner(Player winner) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle("Fin du jeu");
|
||||||
|
alert.setHeaderText("La partie est terminé");
|
||||||
|
alert.setContentText("Un joueur " + winner + " a gagné");
|
||||||
|
App.getViewManager().updateView();
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
private Parent createContent() {
|
private Parent createContent() {
|
||||||
Pane principalPane = new Pane();
|
Pane principalPane = new Pane();
|
||||||
principalPane.setPrefSize(width * cellSize, height * cellSize); // TODO: 04/12/2021 A corriger -> doit plutôt s'adapter à la taille de la grid (grid.getRow() et grid.getColumn())
|
principalPane.setPrefSize(width * cellSize, height * cellSize); // TODO: 04/12/2021 A corriger -> doit plutôt s'adapter à la taille de la grid (grid.getRow() et grid.getColumn())
|
||||||
@ -55,12 +67,12 @@ public class Window extends AbstractView {
|
|||||||
for (int i = 0; i < grid.getRow(); i++) {
|
for (int i = 0; i < grid.getRow(); i++) {
|
||||||
for (int j = 0; j < grid.getColumn(); j++) {
|
for (int j = 0; j < grid.getColumn(); j++) {
|
||||||
Pair<Player, Box> value = grid.getBoard().get(new Point(i, j));
|
Pair<Player, Box> value = grid.getBoard().get(new Point(i, j));
|
||||||
|
if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Explosive) {
|
||||||
|
addToPrincipalPanel(value.getB(), principalPane, i, j);
|
||||||
|
}
|
||||||
if (value.getA() != null) {
|
if (value.getA() != null) {
|
||||||
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
||||||
}
|
}
|
||||||
if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Mine || value.getB() instanceof Bomb) {
|
|
||||||
addToPrincipalPanel(value.getB(), principalPane, i, j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
putStatePlayerPane(principalPane);
|
putStatePlayerPane(principalPane);
|
||||||
|
@ -6,6 +6,8 @@ import fr.lnl.game.server.games.grid.build.BuildStrategy;
|
|||||||
import fr.lnl.game.server.games.grid.elements.CountdownBox;
|
import fr.lnl.game.server.games.grid.elements.CountdownBox;
|
||||||
import fr.lnl.game.server.games.player.ComputerPlayer;
|
import fr.lnl.game.server.games.player.ComputerPlayer;
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
|
import fr.lnl.game.server.listener.AbstractModelListening;
|
||||||
|
import fr.lnl.game.server.listener.GameFinishEvent;
|
||||||
import fr.lnl.game.server.listener.ModelListener;
|
import fr.lnl.game.server.listener.ModelListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,10 +21,11 @@ public class Game {
|
|||||||
private final Grid grid;
|
private final Grid grid;
|
||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
private final ModelListener gameFinishEvent;
|
private final ModelListener gameFinishEvent;
|
||||||
|
private final AbstractModelListening displayWinnerEvent;
|
||||||
private Player currentPlayer;
|
private Player currentPlayer;
|
||||||
private Action selectedAction = null;
|
private Action selectedAction = null;
|
||||||
|
|
||||||
public Game(BuildStrategy buildStrategy, List<Player> players, ModelListener gameFinishEvent) throws IllegalArgumentException {
|
public Game(BuildStrategy buildStrategy, List<Player> players, AbstractModelListening displayWinnerEvent) throws IllegalArgumentException {
|
||||||
this.grid = buildStrategy.getGrid();
|
this.grid = buildStrategy.getGrid();
|
||||||
if(players.size() < 2)
|
if(players.size() < 2)
|
||||||
throw new IllegalArgumentException("The game need 2 or more player to start");
|
throw new IllegalArgumentException("The game need 2 or more player to start");
|
||||||
@ -32,7 +35,8 @@ public class Game {
|
|||||||
this.buildStrategy = buildStrategy;
|
this.buildStrategy = buildStrategy;
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.currentPlayer = players.get(0);
|
this.currentPlayer = players.get(0);
|
||||||
this.gameFinishEvent = gameFinishEvent;
|
this.gameFinishEvent = new GameFinishEvent(this);
|
||||||
|
this.displayWinnerEvent = displayWinnerEvent;
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,4 +126,8 @@ public class Game {
|
|||||||
public Action getSelectedAction() {
|
public Action getSelectedAction() {
|
||||||
return selectedAction;
|
return selectedAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractModelListening getDisplayWinnerEvent() {
|
||||||
|
return displayWinnerEvent;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package fr.lnl.game.server.listener;
|
package fr.lnl.game.server.listener;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.utils.CrashException;
|
import fr.lnl.game.server.utils.CrashException;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -7,17 +8,16 @@ 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();
|
||||||
|
private final Game game;
|
||||||
|
|
||||||
|
public GameFinishEvent(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
// 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) {
|
game.getDisplayWinnerEvent().updateModel(null);
|
||||||
try {
|
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new CrashException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.lnl.game.server.listener;
|
package fr.lnl.game.server.listener;
|
||||||
|
|
||||||
public interface ModelListener {
|
public interface ModelListener {
|
||||||
//à peut-être revoir
|
|
||||||
void updateModel(Object obj);
|
void updateModel(Object obj);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class Mock {
|
|||||||
|
|
||||||
public Mock(List<Player> players) {
|
public Mock(List<Player> players) {
|
||||||
this.buildStrategy = new LockStrategy(new Grid(16,16, players),0.80F, 0.95F);
|
this.buildStrategy = new LockStrategy(new Grid(16,16, players),0.80F, 0.95F);
|
||||||
game = new Game(buildStrategy, players, new GameFinishEvent());
|
game = new Game(buildStrategy, players, new MockDisplayWinner());
|
||||||
this.grid = buildStrategy.getGrid();
|
this.grid = buildStrategy.getGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.lnl.game.server;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.listener.AbstractModelListening;
|
||||||
|
|
||||||
|
public class MockDisplayWinner extends AbstractModelListening {
|
||||||
|
@Override
|
||||||
|
public void updateModel(Object obj) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user