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 bb07de1..bb9e049 100644 --- a/client/src/main/java/fr/lnl/game/client/App.java +++ b/client/src/main/java/fr/lnl/game/client/App.java @@ -41,6 +41,10 @@ public class App extends Application { return new Game(new Grid(12, 12, players), players); } + public static void updateView() { + App.playerList.get(App.game.getCurrentPlayer()).getView().show(); + } + @Override public void start(Stage stage) { try { @@ -52,7 +56,7 @@ public class App extends Application { for (Player player : game.getPlayers()) { playerList.put(player, new ClientPlayer(player, new Window(stage, game, player))); } - playerList.get(game.getCurrentPlayer()).getView().show(); + updateView(); } public static void launchTerminal() { @@ -66,7 +70,7 @@ public class App extends Application { for (Player player : game.getPlayers()) { playerList.put(player, new ClientPlayer(player, new Terminal(game, player))); } - playerList.get(game.getCurrentPlayer()).getView().show(); + updateView(); } public static List parsePlayers() throws IllegalArgumentException, NoSuchMethodException, diff --git a/server/src/main/java/fr/lnl/game/server/model/AbstractModelListening.java b/client/src/main/java/fr/lnl/game/client/listener/AbstractModelListening.java similarity index 54% rename from server/src/main/java/fr/lnl/game/server/model/AbstractModelListening.java rename to client/src/main/java/fr/lnl/game/client/listener/AbstractModelListening.java index 148bf98..d8efd38 100644 --- a/server/src/main/java/fr/lnl/game/server/model/AbstractModelListening.java +++ b/client/src/main/java/fr/lnl/game/client/listener/AbstractModelListening.java @@ -1,13 +1,17 @@ -package fr.lnl.game.server.model; +package fr.lnl.game.client.listener; import java.util.List; public abstract class AbstractModelListening implements ModelListener { List listeners; - public abstract void addListener(ModelListener e); + public void addListener(ModelListener e) { + this.listeners.add(e); + } - public abstract void removalListener(ModelListener e); + public void removalListener(ModelListener e) { + this.listeners.remove(e); + } public void fireChange(){ for(ModelListener e : listeners){ 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 new file mode 100644 index 0000000..2986408 --- /dev/null +++ b/client/src/main/java/fr/lnl/game/client/listener/ButtonListener.java @@ -0,0 +1,24 @@ +package fr.lnl.game.client.listener; + +import fr.lnl.game.client.App; + +public class ButtonListener extends AbstractModelListening{ + + + @Override + public void addListener(ModelListener e) { + this.listeners.add(e); + } + + @Override + public void removalListener(ModelListener e) { + this.listeners.remove(e); + } + + + @Override + public void updateModel(Object event) { + App.game.nextCurrentPlayer(); + App.updateView(); + } +} diff --git a/server/src/main/java/fr/lnl/game/server/model/ModelListener.java b/client/src/main/java/fr/lnl/game/client/listener/ModelListener.java similarity index 72% rename from server/src/main/java/fr/lnl/game/server/model/ModelListener.java rename to client/src/main/java/fr/lnl/game/client/listener/ModelListener.java index 4751679..46d4868 100644 --- a/server/src/main/java/fr/lnl/game/server/model/ModelListener.java +++ b/client/src/main/java/fr/lnl/game/client/listener/ModelListener.java @@ -1,4 +1,4 @@ -package fr.lnl.game.server.model; +package fr.lnl.game.client.listener; public interface ModelListener { //à peut-être revoir diff --git a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java index cca5c80..4cd204a 100644 --- a/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java +++ b/client/src/main/java/fr/lnl/game/client/view/ClientEventHandler.java @@ -1,14 +1,20 @@ package fr.lnl.game.client.view; -import fr.lnl.game.client.App; +import fr.lnl.game.client.listener.ModelListener; +import fr.lnl.game.client.listener.ButtonListener; import javafx.event.ActionEvent; import javafx.event.EventHandler; public class ClientEventHandler implements EventHandler { + private final ModelListener listener; + + public ClientEventHandler(ButtonListener listener) { + this.listener = listener; + } + @Override public void handle(ActionEvent event) { - App.game.nextCurrentPlayer(); - App.playerList.get(App.game.getCurrentPlayer()).getView().show(); + listener.updateModel(event); } } diff --git a/client/src/main/java/fr/lnl/game/client/view/Window.java b/client/src/main/java/fr/lnl/game/client/view/Window.java index aa64a8e..023d289 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Window.java +++ b/client/src/main/java/fr/lnl/game/client/view/Window.java @@ -1,5 +1,6 @@ package fr.lnl.game.client.view; +import fr.lnl.game.client.listener.ButtonListener; import fr.lnl.game.server.games.Game; import fr.lnl.game.server.games.player.Player; import javafx.scene.Scene; @@ -23,7 +24,7 @@ public class Window extends AbstractView { Label l = new Label("Hello, JavaFX version " + javafxVersion + ", running on Java " + javaVersion + "."); Label l2 = new Label("I'm " + player.getClass().getSimpleName() + " num " + player.getId() + " my class is " + player.getClassPlayer().toString()); Button b = new Button("Click to see others players informations"); - b.setOnAction(new ClientEventHandler()); + b.setOnAction(new ClientEventHandler(new ButtonListener())); GridPane grid = new GridPane(); grid.add(l, 0, 0); grid.add(l2, 0, 1); diff --git a/server/src/main/java/fr/lnl/game/server/model/ModelListening.java b/server/src/main/java/fr/lnl/game/server/model/ModelListening.java deleted file mode 100644 index 12128b7..0000000 --- a/server/src/main/java/fr/lnl/game/server/model/ModelListening.java +++ /dev/null @@ -1,21 +0,0 @@ -package fr.lnl.game.server.model; - -public class ModelListening extends AbstractModelListening{ - - - @Override - public void addListener(ModelListener e) { - this.listeners.add(e); - } - - @Override - public void removalListener(ModelListener e) { - this.listeners.remove(e); - } - - - @Override - public void updateModel(Object obj) { - - } -}