Add: complete javadoc on model and network
This commit is contained in:
@@ -16,6 +16,9 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
*/
|
||||
public class Building0 extends BuildingCard {
|
||||
|
||||
/** Food units granted per newly completed character set. */
|
||||
private static final int FOOD_PER_CHARACTER_SET = 5;
|
||||
|
||||
/**
|
||||
* Indicates whether the building effect has already been initialized
|
||||
* after purchase.
|
||||
@@ -138,7 +141,7 @@ public class Building0 extends BuildingCard {
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.addFood(5*(min_temp-numSet));
|
||||
player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));
|
||||
numSet=min_temp;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class Building10 extends BuildingCard {
|
||||
|
||||
/** Prestige points granted per complete character set at end of game. */
|
||||
private static final int PRESTIGE_PER_CHARACTER_SET = 6;
|
||||
|
||||
/**
|
||||
* Creates a Building10 card with the specified era, price, and prestige value.
|
||||
*
|
||||
@@ -75,7 +78,7 @@ public class Building10 extends BuildingCard {
|
||||
numSet=player.getNType(type);
|
||||
}
|
||||
|
||||
player.addPrestige(6 * numSet);
|
||||
player.addPrestige(PRESTIGE_PER_CHARACTER_SET * numSet);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,9 @@ import it.polimi.ingsw.gc14.Model.Player;
|
||||
*/
|
||||
public class Building13 extends BuildingCard{
|
||||
|
||||
/** Prestige points granted at end of game by this building. */
|
||||
private static final int PRESTIGE_AWARD = 25;
|
||||
|
||||
/**
|
||||
* Creates a Building13 card with the specified era, price, and prestige value.
|
||||
*
|
||||
@@ -58,7 +61,7 @@ public class Building13 extends BuildingCard{
|
||||
public void applyEffect(Player player) throws IllegalArgumentException {
|
||||
if(!player.getBuildingCards().contains(this))
|
||||
throw new IllegalArgumentException();
|
||||
player.addPrestige(25);
|
||||
player.addPrestige(PRESTIGE_AWARD);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,9 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class Building4 extends BuildingCard {
|
||||
|
||||
/** Food units granted per newly completed inventor pair. */
|
||||
private static final int FOOD_PER_INVENTOR_PAIR = 3;
|
||||
|
||||
/**
|
||||
* Indicates whether the building effect has already been initialized
|
||||
* after purchase.
|
||||
@@ -149,7 +152,7 @@ public class Building4 extends BuildingCard {
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.addFood(3*(temp-numPair));
|
||||
player.addFood(FOOD_PER_INVENTOR_PAIR *(temp-numPair));
|
||||
numPair = temp;
|
||||
};
|
||||
}
|
||||
@@ -174,6 +174,7 @@ public class Builder extends Character {
|
||||
*
|
||||
* @param player the player who receives the card.
|
||||
*/
|
||||
@Override
|
||||
public void insert(Player player) {
|
||||
player.getBuilders().add(this);
|
||||
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
|
||||
|
||||
+4
-1
@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
|
||||
* @see EventCard
|
||||
*/
|
||||
public class ShamanicRitual extends EventCard {
|
||||
/** Bonus shaman icons granted per Building 5 owned during this event. */
|
||||
private static final int BUILDING5_BONUS_ICONS = 3;
|
||||
|
||||
/** Prestige points awarded to the player with the most shaman icons. */
|
||||
int prestigeToAdd;
|
||||
|
||||
@@ -73,7 +76,7 @@ public class ShamanicRitual extends EventCard {
|
||||
tmpIcons = player.getShamans().stream().mapToInt(sh -> sh.getIcon()).sum();
|
||||
tmpCount = (int) player.getBuildingCards().stream().filter(b -> b.getEffectId() == 5).count();
|
||||
if (tmpCount >= 1) {
|
||||
tmpIcons = tmpIcons+(3*tmpCount);
|
||||
tmpIcons = tmpIcons+(BUILDING5_BONUS_ICONS *tmpCount);
|
||||
}
|
||||
playerMap.put(player, tmpIcons);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class Sustenance extends EventCard {
|
||||
|
||||
/** Food units covered by each Gatherer during the Sustenance event. */
|
||||
private static final int FOOD_PER_GATHERER = 3;
|
||||
|
||||
/**
|
||||
* The prestige penalty multiplier applied for each unpaid Food unit.
|
||||
*/
|
||||
@@ -80,7 +83,7 @@ public class Sustenance extends EventCard {
|
||||
}
|
||||
|
||||
|
||||
int FoodDebt = NChar - (3 * NGatherers + NCharDiscount);
|
||||
int FoodDebt = NChar - (FOOD_PER_GATHERER * NGatherers + NCharDiscount);
|
||||
|
||||
if(FoodDebt <= 0){
|
||||
continue;
|
||||
|
||||
@@ -471,7 +471,6 @@ public class Game implements Serializable {
|
||||
* @param player the player performing the draw.
|
||||
* @param cardIndex the index of the upper tribe card to draw.
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
* TODO
|
||||
*/
|
||||
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
|
||||
@@ -801,7 +800,14 @@ public class Game implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
/**
|
||||
* Transitions the game to the optional card phase or directly to the next round.
|
||||
*
|
||||
* <p>Builds a queue of non-disconnected players who own Building 12 (optional card effect).
|
||||
* If such players exist, the first one is set as the current player for their optional action.
|
||||
* Otherwise, if the round counter is below 10, the next round begins and the game stage
|
||||
* is set to {@link GameStages#SLOT_CHOICE}; if round 10 has been completed, the game ends.
|
||||
*/
|
||||
private synchronized void transitionToOptionalOrNextRound() {
|
||||
currentState.GameStageUpdate(GameStages.OPT_CARD_E);
|
||||
|
||||
|
||||
@@ -62,7 +62,14 @@ public class MiniModel implements Serializable {
|
||||
public MiniModel() {
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Constructs a mini model with only the card lists populated.
|
||||
*
|
||||
* @param upperListTribeCards the upper row of tribe cards on the board.
|
||||
* @param lowerListTribeCards the lower row of tribe cards on the board.
|
||||
* @param upperListBuildingCards the upper row of building cards on the board.
|
||||
* @param lowerListBuildingCards the lower row of building cards on the board.
|
||||
*/
|
||||
public MiniModel(ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards) {
|
||||
this.upperListTribeCards = upperListTribeCards;
|
||||
this.lowerListTribeCards = lowerListTribeCards;
|
||||
@@ -74,12 +81,16 @@ public class MiniModel implements Serializable {
|
||||
/**
|
||||
* Constructs a complete mini model from the current server-side game data.
|
||||
*
|
||||
*TODO
|
||||
* @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.
|
||||
* @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.
|
||||
* @param upperListTribeCards the upper row of tribe cards on the board.
|
||||
* @param lowerListTribeCards the lower row of tribe cards on the board.
|
||||
* @param upperListBuildingCards the upper row of building cards on the board.
|
||||
* @param lowerListBuildingCards the lower row of building cards on the board.
|
||||
* @param disconnectedPlayers the list of usernames of currently disconnected players.
|
||||
*/
|
||||
public MiniModel(Map<Slot, Player> slotPlayerMap,
|
||||
OrderLogicCard orderLogicCard,
|
||||
@@ -101,7 +112,11 @@ public class MiniModel implements Serializable {
|
||||
setPlayers(players);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Sets the last network event applied to the game state.
|
||||
*
|
||||
* @param lastEvent the most recent event received from the server.
|
||||
*/
|
||||
public void setLastEvent(NetworkEvent lastEvent) {
|
||||
this.lastEvent = lastEvent;
|
||||
}
|
||||
@@ -193,7 +208,11 @@ public class MiniModel implements Serializable {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Sets the list of usernames of currently disconnected players.
|
||||
*
|
||||
* @param disconnectedPlayers the list of disconnected player usernames.
|
||||
*/
|
||||
public void setDisconnectedPlayers (ArrayList<String> disconnectedPlayers){
|
||||
this.disconnectedPlayers=disconnectedPlayers;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ public interface IClient {
|
||||
*/
|
||||
void totemChoice(String playerUsername, String totem);
|
||||
|
||||
//TODO
|
||||
/** Notifies the server of a voluntary disconnection and closes the connection. */
|
||||
void notifyDisconnection();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,13 @@ public class AddPlayer extends NetworkEvent implements Serializable {
|
||||
return gameController.addPlayer(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, updating players,
|
||||
* turn order, game state, and slot map.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -47,7 +47,13 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
|
||||
return gameController.disconnectedPlayer(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this disconnection event to the client-side mini model,
|
||||
* updating player data, turn order, game state, and disconnected player list.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -37,7 +37,13 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable
|
||||
}
|
||||
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, removing the drawn card
|
||||
* from the lower building list and updating players, turn order, game state, and slot map.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -36,7 +36,13 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.drawLowerTribeCard(username, pos);
|
||||
}
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, removing the drawn card
|
||||
* from the lower tribe list and updating players, turn order, game state, and slot map.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -37,7 +37,13 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable
|
||||
return gameController.drawUpperBuildingCard(username, pos);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, removing the drawn card
|
||||
* from the upper building list and updating players, turn order, game state, and slot map.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -36,7 +36,13 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.drawUpperTribeCard(username, pos);
|
||||
}
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, removing the drawn card
|
||||
* from the upper tribe list and updating players, turn order, game state, and slot map.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -31,7 +31,13 @@ public class SkipTurn extends NetworkEvent implements Serializable{
|
||||
return gameController.skipTurn(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, updating players,
|
||||
* turn order, game state, and slot map after a skip turn action.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -37,7 +37,13 @@ public class SlotChoice extends NetworkEvent implements Serializable {
|
||||
return gameController.slotChoice(username, pos);
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Applies this event to the client-side mini model, updating players,
|
||||
* turn order, game state, and slot map after a slot selection.
|
||||
*
|
||||
* @param miniModel the client-side model to update.
|
||||
* @return {@code false} if the event is marked as an error; {@code true} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(MiniModel miniModel){
|
||||
synchronized (miniModel) {
|
||||
|
||||
@@ -228,7 +228,12 @@ public class RMIClient implements IClient {
|
||||
System.out.println("Error during remote slot choice");
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
/**
|
||||
* Sends a totem choice to the server for the specified player via RMI.
|
||||
*
|
||||
* @param playerUsername the username of the player choosing the totem.
|
||||
* @param totem the name of the chosen totem.
|
||||
*/
|
||||
public void totemChoice(String playerUsername,String totem) {
|
||||
try{
|
||||
stub.totemChoice(playerUsername,totem);
|
||||
|
||||
@@ -287,11 +287,20 @@ public class TCPClient implements IClient {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Sends a totem choice event to the server for the specified player.
|
||||
*
|
||||
* @param playerUsername the username of the player choosing the totem.
|
||||
* @param totems the name of the chosen totem.
|
||||
*/
|
||||
public void totemChoice(String playerUsername,String totems) {
|
||||
doEvent(new TotemChoice(playerUsername,totems));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the server of a voluntary disconnection by sending a sentinel value
|
||||
* on the heartbeat channel, then closes the connection.
|
||||
*/
|
||||
public void notifyDisconnection()
|
||||
{
|
||||
synchronized (heartbeatOut)
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ClientHandler implements Runnable {
|
||||
*/
|
||||
List<ClientHandler> clientHandlers;
|
||||
|
||||
//TODO
|
||||
/** Maps each connected player's username to their connection state (true = connected). */
|
||||
LimitedMap<String,Boolean> limitedMap;
|
||||
|
||||
/** Queue containing the events to be applied to the game model */
|
||||
|
||||
Reference in New Issue
Block a user