Coverage Summary for Class: DisconnectedPlayer (it.polimi.ingsw.gc14.Network.NetworkEvents)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| DisconnectedPlayer |
0%
(0/1)
|
0%
(0/4)
|
0%
(0/2)
|
0%
(0/16)
|
package it.polimi.ingsw.gc14.Network.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.ErrorType;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.Totems;
import java.util.ArrayList;
import java.util.List;
/**
* Network event used to notify all clients that a player has disconnected.
*
* <p>Also carries the updated list of available totems, since a disconnection
* during totem selection may free a totem for other players.
*/
public class DisconnectedPlayer extends NetworkEvent {
/** Updated list of totems available after the disconnection frees any previously chosen totem. */
private List<Totems> availableTotems;
@Override
public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
super.enrichWithGameState(game, disconnectedUsernames);
this.availableTotems = game.getAvailableTotems();
this.disconnectedPlayers = disconnectedUsernames;
}
/**
* Constructs a disconnection event for the specified player.
*
* @param username the username of the player who disconnected.
*/
public DisconnectedPlayer(String username) {
super(username, EventType.DISCONNECTED_PLAYER, false, ErrorType.GENERIC_ERROR);
}
/**
* Applies this disconnection event to the server-side game controller.
*
* @param gameController the game controller on which to apply the event.
* @return {@code true} if the disconnection is handled successfully.
*/
@Override
public boolean apply(GameController gameController){
return gameController.disconnectedPlayer(username);
}
/**
* Applies this disconnection event to the client-side mini model,
* updating player data, turn order, game state, and disconnected player list.
*
* @param miniModel the client-side model to update.
*/
@Override
public void apply(MiniModel miniModel){
synchronized (miniModel) {
if (isError)
return;
miniModel.setPlayers(playerList);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
miniModel.setDisconnectedPlayers(disconnectedPlayers);
miniModel.setAvailableTotems(availableTotems);
miniModel.setLastEvent(this);
}
}
}