@@ -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.containsKey(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,37 +1,86 @@
|
||||
package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Lightweight representation of the game model shared with clients.
|
||||
*
|
||||
* <p>The mini model contains only the information required by the client-side
|
||||
* view and controllers to render the current match state and process incoming
|
||||
* network updates.
|
||||
*/
|
||||
public class MiniModel implements Serializable {
|
||||
|
||||
/**
|
||||
* Current game board.
|
||||
*/
|
||||
public Board board;
|
||||
|
||||
/**
|
||||
* Map associating each occupied slot with the corresponding player.
|
||||
*/
|
||||
public Map<Slot, Player> slotPlayerMap;
|
||||
|
||||
/**
|
||||
* Card used to manage the player turn order.
|
||||
*/
|
||||
public OrderLogicCard orderLogicCard;
|
||||
|
||||
/**
|
||||
* Current state of the game.
|
||||
*/
|
||||
public CurrentState currentState;
|
||||
|
||||
/**
|
||||
* Map of players indexed by username.
|
||||
*/
|
||||
public Map<String, Player> players;
|
||||
|
||||
/**
|
||||
* List of totems still available for selection.
|
||||
*/
|
||||
public List<Totems> availableTotems;
|
||||
|
||||
/**
|
||||
* Final standing of the players at the end of the game.
|
||||
*/
|
||||
public List<Player> standingPlayers;
|
||||
|
||||
// --- Costruttori ---
|
||||
|
||||
/**
|
||||
* Constructs an empty mini model.
|
||||
*/
|
||||
public MiniModel() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a mini model containing only the game board.
|
||||
*
|
||||
* @param board the current game board.
|
||||
*/
|
||||
public MiniModel(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
public MiniModel(Board board, Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard,
|
||||
CurrentState currentState, List<Player> players, List<Totems> availableTotems) {
|
||||
/**
|
||||
* Constructs a complete mini model from the current server-side game data.
|
||||
*
|
||||
* @param board the current game board.
|
||||
* @param slotPlayerMap the map associating occupied slots with players.
|
||||
* @param orderLogicCard the card managing player turn order.
|
||||
* @param currentState the current state of the game.
|
||||
* @param players the list of players in the match.
|
||||
* @param availableTotems the list of totems still available for selection.
|
||||
*/
|
||||
public MiniModel(Board board,
|
||||
Map<Slot, Player> slotPlayerMap,
|
||||
OrderLogicCard orderLogicCard,
|
||||
CurrentState currentState,
|
||||
List<Player> players,
|
||||
List<Totems> availableTotems) {
|
||||
this.board = board;
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
@@ -42,43 +91,90 @@ public class MiniModel implements Serializable {
|
||||
setPlayers(players);
|
||||
}
|
||||
|
||||
|
||||
// --- Setter ---
|
||||
|
||||
/**
|
||||
* Sets the current game board.
|
||||
*
|
||||
* @param board the board to assign.
|
||||
*/
|
||||
public void setBoard(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of totems still available for selection.
|
||||
*
|
||||
* @param availableTotems the available totems.
|
||||
*/
|
||||
public void setAvailableTotems(List<Totems> availableTotems) {
|
||||
this.availableTotems = availableTotems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the map associating occupied slots with players.
|
||||
*
|
||||
* @param slotPlayerMap the slot-player map to assign.
|
||||
*/
|
||||
public void setSlotPlayerMap(Map<Slot, Player> slotPlayerMap) {
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the card used to manage the player turn order.
|
||||
*
|
||||
* @param orderLogicCard the order logic card to assign.
|
||||
*/
|
||||
public void setOrderLogicCard(OrderLogicCard orderLogicCard) {
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current state of the game.
|
||||
*
|
||||
* @param currentState the current game state.
|
||||
*/
|
||||
public void setCurrentState(CurrentState currentState) {
|
||||
this.currentState = currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces or updates the players stored in the mini model.
|
||||
*
|
||||
* <p>Each player is indexed by username.
|
||||
*
|
||||
* @param players the list of players to store.
|
||||
*/
|
||||
public void setPlayers(List<Player> players) {
|
||||
for (Player player : players) {
|
||||
this.players.put(player.getUserName(), player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or updates a single player in the mini model.
|
||||
*
|
||||
* @param player the player to store.
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
players.put(player.getUserName(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the final standing of the players.
|
||||
*
|
||||
* @param standingPlayers the final ordered list of players.
|
||||
*/
|
||||
public void setStandingPlayers(ArrayList<Player> standingPlayers) {
|
||||
this.standingPlayers = standingPlayers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the position of the player with the specified username
|
||||
* within the player collection.
|
||||
*
|
||||
* @param username the username of the player to search for.
|
||||
* @return the zero-based position of the player, or {@code -1}
|
||||
* if no matching username is found.
|
||||
*/
|
||||
public int getPositionByUsername(String username) {
|
||||
int i = 0;
|
||||
for (Player player : players.values()) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user