Add: Endgame event creation end sending
This commit is contained in:
@@ -18,5 +18,6 @@ public enum EventType {
|
||||
DISCONNECTED_PLAYER,
|
||||
RECONNECT_PLAYER,
|
||||
NEXT_ROUND,
|
||||
ENDED_GAME,
|
||||
NO_OPTIONAL_CARD
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* NetworkEvent to draw a tribe card from the lower card list.
|
||||
*/
|
||||
public class EndedGame extends NetworkEvent implements Serializable{
|
||||
|
||||
List<Player> players;
|
||||
//TODO
|
||||
public EndedGame(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players){
|
||||
super("SERVER",EventType.ENDED_GAME,false);
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
this.currentState = currentState;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 false;
|
||||
}
|
||||
public boolean apply(MiniModel miniModel)
|
||||
{
|
||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||
miniModel.setOrderLogicCard(orderLogicCard);
|
||||
miniModel.setCurrentState(currentState);
|
||||
miniModel.setPlayers(players);
|
||||
miniModel.setStandingPlayers(players);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,20 +156,24 @@ public class TCPClient implements IClient {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
synchronized (controller) {
|
||||
if (read instanceof NetworkEvent event) {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.toString());
|
||||
} else {
|
||||
event.apply(controller.miniModel);
|
||||
controller.view.render();
|
||||
}
|
||||
|
||||
} else if (read instanceof MiniModel model) {
|
||||
controller.setModel(model);
|
||||
if (read instanceof NetworkEvent event) {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.toString());
|
||||
} else {
|
||||
synchronized (controller) {
|
||||
event.apply(controller.miniModel);
|
||||
}
|
||||
controller.view.render();
|
||||
}
|
||||
|
||||
} else if (read instanceof MiniModel model) {
|
||||
synchronized (controller) {
|
||||
controller.setModel(model);
|
||||
}
|
||||
controller.view.render();
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user