Add: Endgame event creation end sending
This commit is contained in:
@@ -18,6 +18,7 @@ public class MiniModel implements Serializable {
|
|||||||
public CurrentState currentState;
|
public CurrentState currentState;
|
||||||
public Map<String, Player> players;
|
public Map<String, Player> players;
|
||||||
public List<Totems> availableTotems;
|
public List<Totems> availableTotems;
|
||||||
|
public List<Player> standingPlayers;
|
||||||
|
|
||||||
// --- Costruttori ---
|
// --- Costruttori ---
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ public class MiniModel implements Serializable {
|
|||||||
this.currentState = currentState;
|
this.currentState = currentState;
|
||||||
this.players = new HashMap<>();
|
this.players = new HashMap<>();
|
||||||
this.availableTotems = availableTotems;
|
this.availableTotems = availableTotems;
|
||||||
|
this.standingPlayers = new ArrayList<>();
|
||||||
setPlayers(players);
|
setPlayers(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +74,9 @@ public class MiniModel implements Serializable {
|
|||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
players.put(player.getUserName(), player);
|
players.put(player.getUserName(), player);
|
||||||
}
|
}
|
||||||
|
public void setStandingPlayers(List<Player> standingPlayers) {
|
||||||
|
this.standingPlayers = standingPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getPositionByUsername(String username) {
|
public int getPositionByUsername(String username) {
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ public enum EventType {
|
|||||||
DISCONNECTED_PLAYER,
|
DISCONNECTED_PLAYER,
|
||||||
RECONNECT_PLAYER,
|
RECONNECT_PLAYER,
|
||||||
NEXT_ROUND,
|
NEXT_ROUND,
|
||||||
|
ENDED_GAME,
|
||||||
NO_OPTIONAL_CARD
|
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();
|
e.printStackTrace();
|
||||||
break;
|
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) {
|
if (read instanceof NetworkEvent event) {
|
||||||
controller.setModel(model);
|
if (event.getIsError()) {
|
||||||
|
controller.view.showError(event.toString());
|
||||||
|
} else {
|
||||||
|
synchronized (controller) {
|
||||||
|
event.apply(controller.miniModel);
|
||||||
|
}
|
||||||
controller.view.render();
|
controller.view.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (read instanceof MiniModel model) {
|
||||||
|
synchronized (controller) {
|
||||||
|
controller.setModel(model);
|
||||||
|
}
|
||||||
|
controller.view.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import it.polimi.ingsw.gc14.Network.EventType;
|
|||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.ApplyNextRound;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.ApplyNextRound;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.EndedGame;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.TotemChoice;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.TotemChoice;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||||
@@ -119,15 +120,21 @@ public class ServerLauncher {
|
|||||||
Game game=gameController.getModel();
|
Game game=gameController.getModel();
|
||||||
if(!event.getIsError())
|
if(!event.getIsError())
|
||||||
{
|
{
|
||||||
if(event.getEventType().equals(EventType.DISCONNECTED_PLAYER)&& game.getCurrentState().getGameStage().equals(GameStages.WAITING))
|
if(game.getCurrentState().getGameStage().equals(GameStages.ENDED))
|
||||||
{
|
{
|
||||||
playerList.remove(event.getUsername());
|
actionQueue.offer(new EndedGame(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayerStanding()));
|
||||||
}else {
|
}
|
||||||
event.setData(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayerByUsername(event.getUsername()));
|
else {
|
||||||
if (event.getEventType().equals(EventType.TOTEM_CHOICE)) {
|
if(event.getEventType().equals(EventType.DISCONNECTED_PLAYER)&& game.getCurrentState().getGameStage().equals(GameStages.WAITING))
|
||||||
((TotemChoice) event).setAvailableTotems(gameController.getModel().getAvailableTotems());
|
{
|
||||||
} else if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && game.getCurrentState().equals(GameStages.WAITING)) {
|
|
||||||
playerList.remove(event.getUsername());
|
playerList.remove(event.getUsername());
|
||||||
|
}else {
|
||||||
|
event.setData(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayerByUsername(event.getUsername()));
|
||||||
|
if (event.getEventType().equals(EventType.TOTEM_CHOICE)) {
|
||||||
|
((TotemChoice) event).setAvailableTotems(gameController.getModel().getAvailableTotems());
|
||||||
|
} else if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && game.getCurrentState().equals(GameStages.WAITING)) {
|
||||||
|
playerList.remove(event.getUsername());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,6 +168,7 @@ public class ServerLauncher {
|
|||||||
}
|
}
|
||||||
disconnectionTimer = timerExecutor.schedule(() -> {
|
disconnectionTimer = timerExecutor.schedule(() -> {
|
||||||
game.EndGameForFeit(game.getPlayerByUsername(playerList.keySet().stream().toList().getFirst()));
|
game.EndGameForFeit(game.getPlayerByUsername(playerList.keySet().stream().toList().getFirst()));
|
||||||
|
actionQueue.offer(new EndedGame(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayerStanding()));
|
||||||
System.out.println("Timer expired: no player reconnected in 60s.");
|
System.out.println("Timer expired: no player reconnected in 60s.");
|
||||||
}, 1, TimeUnit.MINUTES);
|
}, 1, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user