Coverage Summary for Class: ReconnectPlayer (it.polimi.ingsw.gc14.Network.NetworkEvents)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| ReconnectPlayer |
0%
(0/1)
|
0%
(0/4)
|
0%
(0/2)
|
0%
(0/14)
|
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.Game;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import java.util.ArrayList;
/**
* Network event used to notify that a player has reconnected to the game.
*/
public class ReconnectPlayer extends NetworkEvent {
@Override
public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
super.enrichWithGameState(game, disconnectedUsernames);
this.disconnectedPlayers = disconnectedUsernames;
}
/**
* Constructs a reconnection event for the specified player.
*
* @param username the username of the player who reconnected.
*/
public ReconnectPlayer(String username) {
super(username, EventType.RECONNECT_PLAYER, false, ErrorType.GENERIC_ERROR);
}
/**
* Applies the reconnection event to the server-side game controller.
*
* @param gameController the game controller on which to apply the event.
* @return {@code true} if the player reconnection is handled successfully,
* {@code false} otherwise.
*/
@Override
public boolean apply(GameController gameController) {
return gameController.reconnectPlayer(username);
}
/**
* Applies the reconnection update to the client-side mini model.
*
* <p>If the event does not represent an error, the player data,
* turn order, current game state, and slot assignments are updated.
*
* @param miniModel the mini model on which to apply the event.
*/
@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.setLastEvent(this);
}
}
}