Fixed: Standing Order When Forfeit (MiniModel & Network)

This commit is contained in:
rubenpirreram
2026-05-16 10:31:21 +02:00
parent 93320b69bf
commit a9bc9c08f8
4 changed files with 12 additions and 7 deletions
@@ -31,7 +31,7 @@ public class Game implements Serializable {
private ArrayList<Player> playerStanding; private ArrayList<Player> playerStanding;
public List<Player> getPlayerStanding() { public ArrayList<Player> getPlayerStanding() {
return playerStanding; return playerStanding;
} }
/** /**
@@ -992,12 +992,13 @@ public class Game implements Serializable {
return true; return true;
} }
public void EndGameForFeit(Player winner) { public void EndGameForFeit() {
Player winner=playersList.stream().filter(x->!disconnetedPlayers.containsValue(x)||!disconnetedPlayers.get(x)).toList().get(0);
currentState.GameStageUpdate(GameStages.ENDED); currentState.GameStageUpdate(GameStages.ENDED);
playerStanding=new ArrayList<>(playersList); playerStanding=new ArrayList<>(playersList);
playerStanding.remove(winner); playerStanding.remove(winner);
playerStanding.sort((y,x)->x.getPrestigeValue()==y.getPrestigeValue()?Integer.compare(x.getFoodValue(),y.getFoodValue()):Integer.compare(x.getPrestigeValue(),y.getPrestigeValue())); playerStanding.sort((y,x)->x.getPrestigeValue()==y.getPrestigeValue()?Integer.compare(x.getFoodValue(),y.getFoodValue()):Integer.compare(x.getPrestigeValue(),y.getPrestigeValue()));
playerStanding.addFirst(winner); playerStanding.add(0,winner);
} }
@@ -74,7 +74,7 @@ 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) { public void setStandingPlayers(ArrayList<Player> standingPlayers) {
this.standingPlayers = standingPlayers; this.standingPlayers = standingPlayers;
} }
@@ -11,6 +11,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView; import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -19,9 +20,9 @@ import java.util.Map;
*/ */
public class EndedGame extends NetworkEvent implements Serializable{ public class EndedGame extends NetworkEvent implements Serializable{
List<Player> players; ArrayList<Player> players;
//TODO //TODO
public EndedGame(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players){ public EndedGame(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, ArrayList<Player> players){
super("SERVER",EventType.ENDED_GAME,false); super("SERVER",EventType.ENDED_GAME,false);
this.slotPlayerMap = slotPlayerMap; this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard; this.orderLogicCard = orderLogicCard;
@@ -164,10 +164,13 @@ public class ServerLauncher {
disconnectionTimer.cancel(false); disconnectionTimer.cancel(false);
} }
disconnectionTimer = timerExecutor.schedule(() -> { disconnectionTimer = timerExecutor.schedule(() -> {
game.EndGameForFeit(game.getPlayerByUsername(playerList.keySet().stream().toList().getFirst())); game.EndGameForFeit();
serverRMI.notifyAll(new EndedGame(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayerStanding())); serverRMI.notifyAll(new EndedGame(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayerStanding()));
serverTCP.notifyAll(new EndedGame(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayerStanding())); serverTCP.notifyAll(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.");
if(!this.deleteSave()){
System.out.println("\n!!! Couldn't delete save !!!\n");
}
}, 1, TimeUnit.MINUTES); }, 1, TimeUnit.MINUTES);
} }
return !event.getIsError(); return !event.getIsError();