Add: JavaDOC to all NetworkEvent

This commit is contained in:
2026-05-02 18:36:26 +02:00
parent 06162a243f
commit ec4fe1cf44
13 changed files with 196 additions and 53 deletions
@@ -4,39 +4,60 @@ import it.polimi.ingsw.gc14.Controller.GameController;
import java.io.Serializable;
//TODO javadoc
/**
* Represents an event sent over the network
*/
public abstract class NetworkEvent implements Serializable {
//TODO javadoc
/** Username of the player requesting the event */
protected String username;
//TODO javadoc
/**
* @return the username of the player requesting the event
*/
public String getUsername() {
return username;
}
//TODO javadoc
/** EventType of the event */
protected EventType eventType;
//TODO javadoc
/**
* @return the type of the event
*/
public EventType getEventType() {return eventType;}
//TODO javadoc
/** Flag signaling whether the event could not be applied to the server model */
protected boolean isError;
//TODO javadoc
/**
* @return the flag signaling whether the event could be applied to the server model
*/
public boolean getIsError() {return isError;}
//TODO javadoc
/**
* Set the isError flag.
* @param isError the value to set
*/
public void setIsError(boolean isError) {this.isError = isError;}
//TODO javadoc
/**
* Class constructor.
* Initializes all attributes.
* @param username the username of the player requesting the event
* @param eventType the type of the event
* @param isError the flag signaling if the event could be applied to the server model
*/
protected NetworkEvent(String username, EventType eventType, boolean isError) {
this.username = username;
this.eventType = eventType;
this.isError = isError;
}
//TODO javadoc
/**
* @return a string describing the name of the event and whether it is an error or not
*/
@Override
public String toString() {
if(isError) {
@@ -46,6 +67,10 @@ public abstract class NetworkEvent implements Serializable {
}
}
//TODO javadoc
/**
* The method to apply the current event to the specified Game Controller.
* @param gameController the Game Controller on which to apply the event
* @return true if the event could be applied; false otherwise
*/
public abstract boolean apply(GameController gameController);
}
@@ -7,23 +7,35 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to add a player.
*/
public class AddPlayer extends NetworkEvent implements Serializable {
//TODO javadoc
/** Number of proposed players to add to the match */
private int proposedNPlayer;
//TODO javadoc
/**
* @return the number of proposed players to add to the match
*/
public int getProposedNPlayer() {
return proposedNPlayer;
}
//TODO javadoc
/**
* Class constructor.
* Initializes all the attributes.
* @param username the name of the player requesting the event
* @param proposedNPlayer the number of proposed players to add to the match
*/
public AddPlayer(String username, int proposedNPlayer) {
super(username, EventType.ADD_PLAYER, false);
this.proposedNPlayer = proposedNPlayer;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could be added to the match, false otherwise
*/
@Override
public boolean apply(GameController gameController)
{
@@ -7,18 +7,28 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to draw a building card from the lower card list.
*/
public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public DrawLowerBuildingCard(String username, int pos){
super(username, EventType.DRAW_LOWER_BUILD, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.drawLowerBuildingCard(username, pos);
@@ -7,17 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
/**
* NetworkEvent to draw a tribe card from the lower card list.
*/
public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public DrawLowerTribeCard(String username, int pos){
super(username, EventType.DRAW_LOWER_TRIBE, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.drawLowerTribeCard(username, pos);
@@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to draw a building card from the upper card list.
*/
public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public DrawUpperBuildingCard(String username, int pos){
super(username, EventType.DRAW_UPPER_BUILD, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.drawUpperBuildingCard(username, pos);
@@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to draw a tribe card from the upper card list.
*/
public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public DrawUpperTribeCard(String username, int pos){
super(username, EventType.DRAW_UPPER_TRIBE, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.drawUpperTribeCard(username, pos);
@@ -7,14 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to avoid drawing a card from the upper list (see the effect of Building 12)
*/
public class NoOptionalCard extends NetworkEvent implements Serializable{
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
*/
public NoOptionalCard(String username){
super(username, EventType.NO_OPTIONAL_CARD, false);
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.noOptionalCard(username);
@@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to draw a building card from the upper list (see the effect of Building 12)
*/
public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public PickOptionalBuildingCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_BUILD, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.pickOptionalBuildingCard(username, pos);
@@ -7,19 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to draw a tribe card from the upper list (see the effect of Building 12)
*/
public class PickOptionalTribeCard extends NetworkEvent implements Serializable{
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public PickOptionalTribeCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_TRIBE, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.pickOptionalTribeCard(username, pos);
@@ -7,14 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to avoid drawing a card from the lower card list
*/
public class SkipLower extends NetworkEvent implements Serializable{
//TODO javadoc
/**
* Class constructor.
* Initializes all the attributes.
* @param username the name of the player requesting the event
*/
public SkipLower(String username){
super(username, EventType.SKIP_LOWER, false);
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.SkipLowerDrawing(username);
@@ -7,15 +7,24 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to avoid drawing a card from the upper card list
*/
public class SkipUpper extends NetworkEvent implements Serializable{
//TODO javadoc
/**
* Class constructor.
* Initializes all the attributes.
* @param username the name of the player requesting the event
*/
public SkipUpper(String username){
super(username, EventType.SKIP_UPPER, false);
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.SkipUpperDrawing(username);
@@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
//TODO javadoc
/**
* NetworkEvent to select a slot where to place the player totem.
*/
public class SlotChoice extends NetworkEvent implements Serializable {
//TODO javadoc
/** Index of the card to draw */
private int pos;
//TODO javadoc
/**
* Class constructor.
* Initializes all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public SlotChoice(String username, int pos) {
super(username, EventType.SLOT_CHOICE, false);
this.pos = pos;
}
//TODO javadoc
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController) {
return gameController.slotChoice(username, pos);
@@ -8,6 +8,7 @@ import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
/**
* Client RMI. Uses the methods exposed by the server RMI.