@@ -29,11 +29,20 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class Game implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* The final ranking of players at the end of the game.
|
||||
*/
|
||||
private ArrayList<Player> playerStanding;
|
||||
|
||||
/**
|
||||
* Returns the final ranking of players.
|
||||
*
|
||||
* @return the list of players ordered according to their final standing.
|
||||
*/
|
||||
public ArrayList<Player> getPlayerStanding() {
|
||||
return playerStanding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of players participating in the game.
|
||||
*
|
||||
@@ -42,16 +51,38 @@ public class Game implements Serializable {
|
||||
public List<Player> getPlayers() {
|
||||
return playersList;
|
||||
}
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* Returns the list of totems that have not yet been assigned to any player.
|
||||
*
|
||||
* @return the list of currently available totems.
|
||||
*/
|
||||
public List<Totems>getAvailableTotems() {
|
||||
List<Totems> totems=new ArrayList<>(List.of(Totems.values()));
|
||||
playersList.forEach(player -> {if(player.totem!=null)totems.remove(player.totem);});
|
||||
return totems;
|
||||
}
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* Queue containing the players who still have to choose their totem.
|
||||
*/
|
||||
private Queue<Player> totemChoiceQueue = new LinkedList<>();
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Assigns the selected totem to the specified player during the totem choice phase.
|
||||
*
|
||||
* <p>The choice is accepted only if the game is currently in the
|
||||
* {@link GameStages#TOTEM_CHOICE} stage, the player is the current one,
|
||||
* and the selected totem is still available.
|
||||
*
|
||||
* <p>After a valid choice, the method advances to the next player in the queue.
|
||||
* If all players have completed the selection, the game moves to the slot choice phase.
|
||||
* Disconnected players are automatically assigned a random available totem.
|
||||
*
|
||||
* @param player the player making the totem choice.
|
||||
* @param totem the selected totem.
|
||||
* @return {@code true} if the choice is applied successfully, {@code false} otherwise.
|
||||
*/
|
||||
public boolean TotemChoice(Player player,Totems totem) {
|
||||
if(!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE))
|
||||
return false;
|
||||
@@ -87,9 +118,23 @@ public class Game implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Map tracking the players who are currently disconnected.
|
||||
*/
|
||||
public Map<Player,Boolean> disconnetedPlayers = new HashMap<>();
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* Marks the specified player as disconnected and updates the game flow accordingly.
|
||||
*
|
||||
* <p>If the player disconnects during the waiting phase, they are removed from
|
||||
* the player list and from the totem choice queue. If the disconnected player is
|
||||
* the current one, the game advances to the next suitable player or, during the
|
||||
* totem choice phase, handles the remaining selection flow automatically.
|
||||
*
|
||||
* @param player the player who disconnected.
|
||||
* @return {@code true} if the disconnection is handled successfully,
|
||||
* {@code false} if the player was already marked as disconnected.
|
||||
*/
|
||||
public boolean DisconnectedPlayer(Player player)
|
||||
{
|
||||
if(disconnetedPlayers.containsKey(player) && disconnetedPlayers.get(player))
|
||||
@@ -121,7 +166,17 @@ public class Game implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Marks the specified player as reconnected.
|
||||
*
|
||||
* <p>If the player reconnects during the slot choice phase, they are removed
|
||||
* from the disconnected players map and reinserted into the order logic card
|
||||
* when necessary.
|
||||
*
|
||||
* @param player the player who reconnected.
|
||||
* @return {@code true} if the reconnection is handled successfully,
|
||||
* {@code false} if the player was not previously marked as disconnected.
|
||||
*/
|
||||
public boolean ReconnectPlayer(Player player)
|
||||
{
|
||||
if(!disconnetedPlayers.containsKey(player))
|
||||
@@ -140,12 +195,14 @@ public class Game implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Totem
|
||||
//TODO
|
||||
/**
|
||||
* Clears the collection of disconnected players.
|
||||
*/
|
||||
public void ClearDisconnected()
|
||||
{
|
||||
disconnetedPlayers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of players participating in the game.
|
||||
* @return the current number of players.
|
||||
@@ -195,7 +252,12 @@ public class Game implements Serializable {
|
||||
* The board associated with this game.
|
||||
*/
|
||||
private Board board;
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* Returns the game board.
|
||||
*
|
||||
* @return the board associated with the game.
|
||||
*/
|
||||
public Board getBoard() {return board;}
|
||||
|
||||
/**
|
||||
@@ -925,6 +987,13 @@ public class Game implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the game by forfeit and determines the final player standing.
|
||||
*
|
||||
* <p>The player who is still connected is declared the winner and placed
|
||||
* in the first position of the final ranking. The remaining players are
|
||||
* ordered by prestige value and, in case of a tie, by food value.
|
||||
*/
|
||||
public void EndGameForFeit() {
|
||||
Player winner=playersList.stream().filter(x->!disconnetedPlayers.containsKey(x)||!disconnetedPlayers.get(x)).toList().get(0);
|
||||
currentState.GameStageUpdate(GameStages.ENDED);
|
||||
|
||||
Reference in New Issue
Block a user