add javadoc to client.listener

This commit is contained in:
Quentin Legot 2021-12-09 16:30:11 +01:00
parent fb408a3f78
commit 1b556e5ac8
6 changed files with 41 additions and 17 deletions

View File

@ -4,9 +4,15 @@ import fr.lnl.game.server.listener.ModelListener;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
public record ClientEventHandler( /**
ModelListener listener) implements EventHandler<ActionEvent> { * implementation of a listener from JavaFX {@link EventHandler}
*/
public record ClientEventHandler(ModelListener listener) implements EventHandler<ActionEvent> {
/**
* This method is call by JavaFX when we click to the button
* @param event event class created when clicking on the element
*/
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
listener.updateModel(event); listener.updateModel(event);

View File

@ -4,8 +4,15 @@ import fr.lnl.game.client.App;
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.AbstractModelListening;
/**
* Used to display the winner of the game
*/
public class DisplayWinnerEvent extends AbstractModelListening { public class DisplayWinnerEvent extends AbstractModelListening {
/**
* This method is call when the game is over
* @param obj contains the winner of the game, can be null
*/
@Override @Override
public void updateModel(Object obj) { public void updateModel(Object obj) {
Player winner = (Player) obj; Player winner = (Player) obj;

View File

@ -7,9 +7,12 @@ 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;
/**
* This method is call when the current player have selected an action to play (or if it's a computer player, will
* select it), then we call {@link Game#play()} and we update the view
*/
public class NextPlayerButtonListener extends AbstractModelListening { public class NextPlayerButtonListener extends AbstractModelListening {
private final Game game; private final Game game;
private final DisplayWinnerEvent displayWinnerEvent; private final DisplayWinnerEvent displayWinnerEvent;
@ -18,17 +21,10 @@ public class NextPlayerButtonListener extends AbstractModelListening {
this.displayWinnerEvent = new DisplayWinnerEvent(); this.displayWinnerEvent = new DisplayWinnerEvent();
} }
@Override /**
public void addListener(ModelListener e) { * Call when clicking on "SUIVANT" button if current player is a computer player or after the human player selected
this.listeners.add(e); * action it want to play
} */
@Override
public void removalListener(ModelListener e) {
this.listeners.remove(e);
}
@Override @Override
public void updateModel(Object event) { public void updateModel(Object event) {
// Player player = game.getCurrentPlayer(); // Player player = game.getCurrentPlayer();

View File

@ -6,6 +6,9 @@ import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.action.ReunionSameAction; import fr.lnl.game.server.games.action.ReunionSameAction;
import fr.lnl.game.server.listener.AbstractModelListening; import fr.lnl.game.server.listener.AbstractModelListening;
/**
* Used when the human player select type of action it want to play
*/
public class SelectActionButton extends AbstractModelListening { public class SelectActionButton extends AbstractModelListening {
private final Window window; private final Window window;
@ -18,6 +21,10 @@ public class SelectActionButton extends AbstractModelListening {
this.reunionSameAction = reunionSameAction; this.reunionSameAction = reunionSameAction;
} }
/**
* This method is call when the player select the type of action it want to play
* @param obj contain information about the event like the button where the player clicked
*/
@Override @Override
public void updateModel(Object obj) { public void updateModel(Object obj) {
if(reunionSameAction.getActions().size() == 1){ if(reunionSameAction.getActions().size() == 1){
@ -27,8 +34,5 @@ public class SelectActionButton extends AbstractModelListening {
window.setSelectedReunionAction(reunionSameAction); window.setSelectedReunionAction(reunionSameAction);
App.getViewManager().updateView(); // update screen App.getViewManager().updateView(); // update screen
} }
} }
} }

View File

@ -6,6 +6,9 @@ import fr.lnl.game.server.games.action.Action;
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;
/**
* Call when the player selected the direction where it wants to play it
*/
public class SelectDirectionListener extends AbstractModelListening { public class SelectDirectionListener extends AbstractModelListening {
private final Game game; private final Game game;
@ -18,6 +21,10 @@ public class SelectDirectionListener extends AbstractModelListening {
this.action = action; this.action = action;
} }
/**
* This method is call when the player click on the button to select the direction of the previously selected action
* @param obj contain information about the event like the button where the player clicked
*/
@Override @Override
public void updateModel(Object obj) { public void updateModel(Object obj) {
game.setSelectedAction(action); game.setSelectedAction(action);

View File

@ -0,0 +1,4 @@
/**
* Package that contains every view listeners
*/
package fr.lnl.game.client.listener;