Add: complete JavaDoc for networking, heartbeat, totem flow and game events

This commit is contained in:
MatteoPellegrino05
2026-05-18 18:52:29 +02:00
parent 07e7028ac9
commit e28e7bab6d
26 changed files with 890 additions and 199 deletions
@@ -4,5 +4,34 @@ package it.polimi.ingsw.gc14.Model.Cards.Building;
* Represents the possible effect types of building cards.
*/
public enum EffectType {
FINAL, CARD_SET, INVENTOR_PAIR, ON_EVENT, ON_END_TURN, ON_ROUND_END
}
/**
* Effect applied during the final scoring phase.
*/
FINAL,
/**
* Effect based on collecting a specific set of cards.
*/
CARD_SET,
/**
* Effect based on pairs of Inventor cards.
*/
INVENTOR_PAIR,
/**
* Effect triggered when an event card is resolved.
*/
ON_EVENT,
/**
* Effect triggered at the end of a player's turn.
*/
ON_END_TURN,
/**
* Effect triggered at the end of a round.
*/
ON_ROUND_END
}
@@ -4,5 +4,34 @@ package it.polimi.ingsw.gc14.Model.Cards.TribeCards;
* Represents the different types of character cards available in the game.
*/
public enum CharacterType {
INVENTOR, BUILDER, GATHERER, ARTIST, SHAMAN, HUNTER
/**
* Character card representing an Inventor.
*/
INVENTOR,
/**
* Character card representing a Builder.
*/
BUILDER,
/**
* Character card representing a Gatherer.
*/
GATHERER,
/**
* Character card representing an Artist.
*/
ARTIST,
/**
* Character card representing a Shaman.
*/
SHAMAN,
/**
* Character card representing a Hunter.
*/
HUNTER
}
@@ -4,5 +4,24 @@ package it.polimi.ingsw.gc14.Model.Cards.TribeCards;
* Represents the different types of event cards available in the game.
*/
public enum EventType {
SUSTENANCE, SHAMANIC_RITUAL, CAVE_PAINTINGS, HUNT
}
/**
* Event card representing Sustenance.
*/
SUSTENANCE,
/**
* Event card representing the Shamanic Ritual.
*/
SHAMANIC_RITUAL,
/**
* Event card representing Cave Paintings.
*/
CAVE_PAINTINGS,
/**
* Event card representing the Hunt.
*/
HUNT
}
@@ -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.containsValue(x)||!disconnetedPlayers.get(x)).toList().get(0);
currentState.GameStageUpdate(GameStages.ENDED);
@@ -4,5 +4,43 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
* Represents the possible stages of a game.
*/
public enum GameStages {
WAITING,TOTEM_CHOICE, SLOT_CHOICE, RES_ACTIONS, OPT_CARD_E, RES_EVENT, ENDING, ENDED
}
/**
* Stage in which the game is waiting for players to join.
*/
WAITING,
/**
* Stage in which players choose their totems.
*/
TOTEM_CHOICE,
/**
* Stage in which players select their action slots.
*/
SLOT_CHOICE,
/**
* Stage in which the mandatory actions associated with the chosen slots are resolved.
*/
RES_ACTIONS,
/**
* Stage in which an optional card effect can be resolved.
*/
OPT_CARD_E,
/**
* Stage in which an event card is being resolved.
*/
RES_EVENT,
/**
* Stage in which end-of-round or end-of-game operations are processed.
*/
ENDING,
/**
* Stage indicating that the game has ended.
*/
ENDED
}
@@ -1,5 +1,32 @@
package it.polimi.ingsw.gc14.Model;
/**
* Represents the different totem colors available in the game.
*/
public enum Totems {
YELLOW, BLUE, ORANGE, WHITE, PURPLE
/**
* Yellow totem.
*/
YELLOW,
/**
* Blue totem.
*/
BLUE,
/**
* Orange totem.
*/
ORANGE,
/**
* White totem.
*/
WHITE,
/**
* Purple totem.
*/
PURPLE
}