Class NetworkEvent
java.lang.Object
it.polimi.ingsw.gc14.Network.NetworkEvent
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AddPlayer, ApplyNextRound, DisconnectedPlayer, DrawLowerBuildingCard, DrawLowerTribeCard, DrawUpperBuildingCard, DrawUpperTribeCard, EndedGame, ReconnectPlayer, SkipTurn, SlotChoice, TotemChoice
Represents an event sent over the network.
A network event contains the information required to identify
the requested action, determine whether it produced an error,
and apply it either to the server-side GameController
or to the client-side MiniModel.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CurrentStateCurrent state of the game associated with the event.Usernames of players currently disconnected from the game.protected ErrorTypeThe error type associated with this event; set when the event failed to apply.protected final EventTypeType of the network event.protected booleanFlag indicating whether the event could not be applied successfully.protected OrderLogicCardOrder logic card used to manage the player turn order.List of all players.Map associating each occupied slot with the corresponding player.protected final StringUsername of the player requesting the event. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNetworkEvent(String username, EventType eventType, boolean isError, ErrorType errorType) Constructs a network event. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanapply(GameController gameController) Applies this event to the specified server-side game controller.abstract voidApplies this event to the specified client-side mini model.voidenrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) Populates this event with the current game state so clients can update their local model after receiving it.Returns the error type associated with this event.Returns the type of this event.Returns the username of the player requesting the event.booleanisError()Returns whether the event represents an error.voidsetData(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> playerList) Sets the game data associated with this network event.voidsetErrorType(ErrorType errorType) Overrides the error type for this event.voidsetIsError(boolean isError) Sets whether the event represents an error.toString()Returns a textual description of the event and its outcome.
-
Field Details
-
errorType
The error type associated with this event; set when the event failed to apply. -
username
Username of the player requesting the event. -
eventType
Type of the network event. -
slotPlayerMap
-
orderLogicCard
Order logic card used to manage the player turn order. -
currentState
Current state of the game associated with the event. -
playerList
-
disconnectedPlayers
-
isError
protected boolean isErrorFlag indicating whether the event could not be applied successfully.
-
-
Constructor Details
-
NetworkEvent
-
-
Method Details
-
getErrorType
Returns the error type associated with this event.- Returns:
- the error type, or
nullif no error occurred.
-
getUsername
Returns the username of the player requesting the event.- Returns:
- the username associated with the event.
-
enrichWithGameState
Populates this event with the current game state so clients can update their local model after receiving it. Subclasses that carry extra state (available totems, etc.) override this method and callsuperfirst.- Parameters:
game- the current game model.disconnectedUsernames- usernames of currently disconnected players.
-
setData
public void setData(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> playerList) Sets the game data associated with this network event.- Parameters:
slotPlayerMap- the map associating each slot with the player occupying it.orderLogicCard- the order logic card used to manage turn order.currentState- the current state of the game.playerList- the list of the actual state of the players
-
getEventType
-
isError
public boolean isError()Returns whether the event represents an error.- Returns:
trueif the event could not be applied successfully,falseotherwise.
-
setIsError
public void setIsError(boolean isError) Sets whether the event represents an error.- Parameters:
isError-trueif the event could not be applied successfully,falseotherwise.
-
setErrorType
Overrides the error type for this event.- Parameters:
errorType- the error type to set.
-
toString
-
apply
Applies this event to the specified server-side game controller.- Parameters:
gameController- the game controller on which the event must be applied.- Returns:
trueif the event is applied successfully,falseotherwise.
-
apply
Applies this event to the specified client-side mini model.- Parameters:
model- the mini model on which the event must be applied.
-