diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..40155f0
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java
index 5e02464..2094aba 100644
--- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java
+++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java
@@ -5,28 +5,67 @@ import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
import it.polimi.ingsw.gc14.View.TUI.TUI;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Scanner;
+/**
+ * Entry point for the TUI-based game client.
+ * Handles the initial setup by asking the user for a username, the desired number of players,
+ * and the preferred network protocol (RMI or TCP).
+ * Once connected to the server, it continuously reads and dispatches user input to the controller.
+ */
public class ClientLauncherTUI {
- //TODO Javadoc
+
+ List admissibleChar=new ArrayList<>();
+
+ /**
+ * The TUI view associated with this client.
+ */
+ TUI view;
+
+ /**
+ * Starts the TUI client.
+ * Prompts the user for a username, the desired number of players, and the network protocol.
+ * Attempts to connect to the server using either RMI or TCP depending on the selection.
+ * If the connection is successful, enters a loop to continuously read and process user input.
+ *
+ * @throws InterruptedException if the thread is interrupted while waiting.
+ */
public void main() throws InterruptedException {
- TUI view=new TUI(null);
+ view = new TUI(null);
+ admissibleChar.add("0");
+ admissibleChar.add("1");
+ admissibleChar.add("2");
+ admissibleChar.add("3");
+ admissibleChar.add("4");
+ admissibleChar.add("5");
+ admissibleChar.add("6");
+ admissibleChar.add("7");
+ admissibleChar.add("8");
+ admissibleChar.add("9");
+ admissibleChar.add("A");
+ admissibleChar.add("B");
+ admissibleChar.add("C");
+ admissibleChar.add("a");
+ admissibleChar.add("b");
+ admissibleChar.add("c");
+
ClientController controller = new ClientController(view);
-
Scanner scanner = new Scanner(System.in);
- System.out.println("Selezionare nome utente: ");
+ System.out.println("Insert username: ");
String username = scanner.next();
- System.out.println("Selezionare numero di giocatori desiderato: ");
+ view.setUsername(username);
+ System.out.println("Insert preferred number of players: ");
int proposedNumPlayers = scanner.nextInt();
- System.out.println("Selezionare RMI[0] o TCP[1]: ");
+ System.out.println("Select RMI[0] o TCP[1]: ");
int networkType = scanner.nextInt();
-
-
-
+ System.out.println("Insert server IP: ");
+ String IP = scanner.next();
// RMI
if (networkType == 0) {
// Connect
- RMIClient client = new RMIClient(controller, "localhost", 1099);
+ RMIClient client = new RMIClient(controller, IP, 1099);
if (client.connect(username, proposedNumPlayers)) {
System.out.println("Succesfully connected to RMI server\n\n");
} else {
@@ -34,20 +73,13 @@ public class ClientLauncherTUI {
return;
}
controller.setClient(client);
-
- // Play
- //while(controller.localController.getModel()==null){
- // scanner.nextInt();
- //}
- while(true) {
+ while (true) {
getInput(scanner, controller, username);
}
-
-
- // TCP
+ // TCP
} else if (networkType == 1) {
// Connect
- TCPClient client = new TCPClient(controller, "localhost", 8080);
+ TCPClient client = new TCPClient(controller, IP, 8080);
if (client.connect(username, proposedNumPlayers)) {
System.out.println("Succesfully connected to TCP server\n\n");
} else {
@@ -55,31 +87,75 @@ public class ClientLauncherTUI {
return;
}
controller.setClient(client);
-
// Play
- while(true) {
+ while (true) {
getInput(scanner, controller, username);
}
}
-
scanner.close();
}
-
-
+ /**
+ * Reads a single action from the user and dispatches it to the controller.
+ * The action is identified by a string code. Most actions also require a position index
+ * (e.g. the index of the card to draw from a list), which is read as a second input.
+ * Actions that do not require a position (7, 8, 9, A, B, C) skip the position prompt.
+ *
+ * Available actions:
+ *
+ *
{@code 0} - Choose a slot by index.
+ *
{@code 1} - Draw an upper building card by index.
+ *
{@code 2} - Draw an upper tribe card by index.
+ *
{@code 3} - Draw a lower building card by index.
+ *
{@code 4} - Draw a lower tribe card by index.
+ *
{@code 5} - Pick an optional tribe card by index.
+ *
{@code 6} - Pick an optional building card by index.
+ *
{@code 7} - Skip the optional card choice.
+ *
{@code 8} - Skip the upper draw.
+ *
{@code 9} - Skip the lower draw.
+ *
{@code A} - Render the full game view.
+ *
{@code B} - Render the board view.
+ *
{@code C} - Render the player view.
+ *
+ *
+ * @param scanner the scanner used to read user input.
+ * @param controller the client controller to which actions are dispatched.
+ * @param username the username of the current player.
+ */
private void getInput(Scanner scanner, ClientController controller, String username) {
- int action = scanner.nextInt();
- int pos = scanner.nextInt();
+ String action = scanner.next();
+ int pos = -1;
- switch(action) {
- case 1 -> controller.drawLowerBuildingCard(username, pos);
- case 2 -> controller.drawLowerTribeCard(username, pos);
- case 3 -> controller.drawUpperBuildingCard(username, pos);
- case 4 -> controller.drawUpperTribeCard(username, pos);
- case 5 -> controller.pickOptionalBuildingCard(username, pos);
- case 6 -> controller.slotChoice(username, pos);
+ if(admissibleChar.contains(username))
+ {
+ if (!action.equals("7") && !action.equals("8") && !action.equals("9") && !action.equals("A") && !action.equals("B") && !action.equals("C")) {
+ try {
+ System.out.println("Insert the required position:");
+ pos = scanner.nextInt();
+ } catch (Exception e) {
+ System.out.println("ERROR: Invalid input(expected number)");
+ }
+ }
+ switch (action) {
+ case "0" -> controller.slotChoice(username, pos);
+ case "1" -> controller.drawUpperTribeCard(username, pos);
+ case "2" -> controller.drawUpperBuildingCard(username, pos);
+ case "3" -> controller.drawLowerTribeCard(username, pos);
+ case "4" -> controller.drawLowerBuildingCard(username, pos);
+ case "5" -> controller.pickOptionalTribeCard(username, pos);
+ case "6" -> controller.pickOptionalBuildingCard(username, pos);
+ case "7" -> controller.noOptionalCard(username);
+ case "8" -> controller.skipUpper(username);
+ case "9" -> controller.skipLower(username);
+ case "A", "a" -> view.fullRender();
+ case "B", "b" -> view.renderBoard();
+ case "C", "c" -> view.renderPlayer();
+ default -> {}
+ }
+ }
+ else
+ {
+ System.out.println("ERROR: Invalid input(action not valid)");
}
-
- return;
}
}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
index 63da09f..5c2070b 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
@@ -1,116 +1,164 @@
package it.polimi.ingsw.gc14.Controller;
import it.polimi.ingsw.gc14.Model.Game;
-import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
-import it.polimi.ingsw.gc14.Network.Observer;
import it.polimi.ingsw.gc14.View.IView;
-//TODO Javadoc
+/**
+ * Controller class that holds all the components of the client, such as view, network client and Game Controller.
+ * It provides methods to set the client components and to execute requested actions.
+ */
public class ClientController {
+ /** Game Controller of the client */
public GameController localController;
- //TODO Javadoc
- public IView view=null;
+ /** View of the client */
+ public IView view;
+
+ /** Network client (either TCP or RMI) */
private IClient client;
+
+ /**
+ * Constructs the ClientController.
+ * Initializes all attributes.
+ * @param view the client view (either TUI or GUI)
+ */
public ClientController(IView view) {
this.view = view;
this.localController = new GameController();
+ this.client = null;
}
+
+
+ /**
+ * Sets the network client.
+ * @param client the client to set (either TCP or RMI)
+ */
public void setClient(IClient client) {
this.client = client;
}
+
+
+ /**
+ * Sets the model in the GameController and updates the view.
+ * @param model the model to set
+ */
public void setModel(Game model) {
localController.setModel(model);
view.update(localController.getModel());
}
+
+ /**
+ * Displays an error message in the view.
+ * @param message the error message to display
+ */
public void onError(String message) {
view.showError(message);
}
+
/**
- * Attempts to draw an upper tribe card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the upper tribe card to draw.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the draw operation fails.
+ * Requests to draw a tribe card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
- public void drawUpperTribeCard(String playerUsername,int pos) {
+ public void drawUpperTribeCard(String playerUsername, int pos) {
client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
}
+
/**
- * Attempts to draw a lower tribe card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the lower tribe card to draw.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the draw operation fails.
+ * Requests to draw a tribe card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
public void drawLowerTribeCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerTribeCard(playerUsername,pos));
}
+
/**
- * Attempts to draw an upper building card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the upper building card to draw.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the draw operation fails.
+ * Requests to draw a building card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
public void drawUpperBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
}
+
/**
- * Attempts to draw a lower building card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the lower building card to draw.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the draw operation fails.
+ * Requests to draw a building card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
public void drawLowerBuildingCard(String playerUsername,int pos) {
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
}
+
/**
- * Attempts to pick an optional tribe card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the optional tribe card to pick.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the pick operation fails.
+ * Requests to skip drawing from the upper list.
+ * This action is available only when the upper list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipUpper(String playerUsername) {
+ client.doEvent(new SkipUpper(playerUsername));
+ }
+
+
+ /**
+ * Requests to skip drawing from the lower list.
+ * This action is available only when the lower list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));}
+
+
+ /**
+ * Used to draw a tribe card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
}
+
/**
- * Attempts to pick an optional building card for the specified player from the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the optional building card to pick.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the pick operation fails.
+ * Used to draw a building card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
}
+
/**
- * Attempts to perform the slot choice action for the specified player at the specified position.
- *
- * @param playerUsername the username of the player performing the action.
- * @param pos the position of the chosen slot.
- * @return {@code true} if the action succeeds, {@code false} if the player does not exist
- * or if the slot choice operation fails.
+ * Used to skip the action of drawing a card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void noOptionalCard(String playerUsername) {
+ client.doEvent(new NoOptionalCard(playerUsername));
+ }
+
+
+ /**
+ * Used to perform the slot choice action for the specified player at the specified position.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the selected slot
*/
public void slotChoice(String playerUsername,int pos) {
client.doEvent(new SlotChoice(playerUsername,pos));
diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java
index ca65067..556e97f 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java
@@ -1,6 +1,7 @@
package it.polimi.ingsw.gc14.Controller;
import it.polimi.ingsw.gc14.Model.Game;
+import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import it.polimi.ingsw.gc14.Model.Player;
/**
@@ -118,6 +119,20 @@ public class GameController {
return model.DrawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
}
+ public boolean SkipUpperDrawing(String playerUsername) {
+ Player player= model.getPlayerByUsername(playerUsername);
+ if(player==null)
+ return false;
+ return model.SkipUpperDrawing(model.getPlayerByUsername(playerUsername));
+ }
+
+ public boolean SkipLowerDrawing(String playerUsername) {
+ Player player= model.getPlayerByUsername(playerUsername);
+ if(player==null)
+ return false;
+ return model.SkipLowerDrawing(model.getPlayerByUsername(playerUsername));
+ }
+
/**
* Attempts to pick an optional tribe card for the specified player from the specified position.
*
@@ -147,6 +162,18 @@ public class GameController {
return false;
return model.PickOptionalBuildingCard(model.getPlayerByUsername(playerUsername), pos);
}
+ /**
+ * Refuse to pick an optional building card for the specified player.
+ * @param playerUsername the username of the player performing the action.
+ * @return {@code true} if the action succeeds, {@code false} if the player does not exist
+ * or if the pick operation fails.
+ */
+ public boolean noOptionalCard(String playerUsername) {
+ Player player= model.getPlayerByUsername(playerUsername);
+ if(player==null)
+ return false;
+ return model.NoOptionalCard(model.getPlayerByUsername(playerUsername));
+ }
/**
* Attempts to perform the slot choice action for the specified player at the specified position.
diff --git a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java
index ad351d0..5ac39ff 100644
--- a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java
+++ b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java
@@ -1,22 +1,42 @@
package it.polimi.ingsw.gc14;
-
import java.util.ArrayList;
-//TODO Javadoc
+/**
+ * An {@link ArrayList} with a configurable size limit and an associated action.
+ * When the number of elements reaches or exceeds the limit, the specified action is automatically triggered.
+ *
+ * @param the type of elements held in this list.
+ */
public class LimitedList extends ArrayList {
- //TODO Javadoc
+
+ /**
+ * The maximum number of elements allowed in the list before the action is triggered.
+ */
private int limit;
- //TODO Javadoc
+ /**
+ * The action to execute when the list size reaches or exceeds the limit.
+ */
private Runnable action;
- //TODO Javadoc
+ /**
+ * Creates a new {@code LimitedList} with the specified limit and action.
+ *
+ * @param limit the maximum number of elements before the action is triggered.
+ * @param action the action to execute when the limit is reached.
+ */
public LimitedList(int limit, Runnable action) {
this.limit = limit;
this.action = action;
}
- //TODO Javadoc
+ /**
+ * Adds the specified element to the list.
+ * If the list size reaches or exceeds the limit after the insertion, the configured action is triggered.
+ *
+ * @param element the element to add.
+ * @return {@code true} if the element was successfully added.
+ */
@Override
public boolean add(T element) {
boolean result = super.add(element);
@@ -26,16 +46,30 @@ public class LimitedList extends ArrayList {
return result;
}
- //TODO Javadoc
+ /**
+ * Sets a new size limit for this list.
+ *
+ * @param num the new limit.
+ */
public void setLimit(int num) {
- this.limit=num;
+ this.limit = num;
}
- //TODO Javadoc
- public int getLimit(){return limit;}
+ /**
+ * Returns the current size limit of this list.
+ *
+ * @return the current limit.
+ */
+ public int getLimit() {
+ return limit;
+ }
- //TODO Javadoc
+ /**
+ * Sets a new action to execute when the list size reaches or exceeds the limit.
+ *
+ * @param action the new action to set.
+ */
public void setAction(Runnable action) {
- this.action=action;
+ this.action = action;
}
}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java
index 8fbe48c..c8ddda2 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java
@@ -1,5 +1,5 @@
package it.polimi.ingsw.gc14.Model.Cards.Building;
public enum EffectType {
- FINAL, CARD_SET,INVENTOR_PAIR, ON_EVENT , ON_END_TURN, ON_ROUND_END
+ FINAL, CARD_SET, INVENTOR_PAIR, ON_EVENT, ON_END_TURN, ON_ROUND_END
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
index d67017d..0c4db48 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
@@ -42,7 +42,7 @@ public class Building8 extends BuildingCard {
if(!player.buildingCards.contains(this))
throw new IllegalArgumentException();
for (Builder builder : player.builders) {
- player.addPrestige(builder.getPrestigeValue() * 2);
+ player.addPrestige(builder.getPrestigeValue());
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
index 24e41a1..d6ab676 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
@@ -159,8 +159,16 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @return {@code true} if the building card is successfully bought,
* {@code false} otherwise.
*/
+ // sum reduction value builder=> sconto
public boolean buy(Player player) {
- if( bought || !player.removeFood(getPrice()))
+ int discount = 0;
+ discount = player.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
+
+ if(discount > this.price){
+ discount = this.price;
+ }
+
+ if(bought || !player.removeFood(this.price - discount))
return false;
player.buildingCards.add(this);
bought=true;
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java
index bd4869c..5df0d9e 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java
@@ -1,5 +1,5 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards;
public enum CharacterType {
- INVENTOR,BUILDER, GATHERER,ARTIST,SHAMAN,HUNTER
+ INVENTOR, BUILDER, GATHERER, ARTIST, SHAMAN, HUNTER
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java
index 5254216..5fd0d9a 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java
@@ -98,6 +98,9 @@ public class Hunter extends Character {
@Override
public void insert(Player player) {
player.hunters.add(this);
+ if(this.getIcon()){
+ player.addFood(player.hunters.size());
+ }
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java
index 5f8fdbc..e8cd013 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java
@@ -62,7 +62,7 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toString() {
- return super.toString()+" "+type.toString();
+ return super.toString()+"(Event)"+type.toString();
}
/**
@@ -77,7 +77,7 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toStringBoard() {
- return super.toString()+" "+type.toString();
+ return super.toString()+"(Event)"+type.toString();
}
/**
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
index 164f779..add51ff 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
@@ -43,7 +43,7 @@ public class Sustenance extends EventCard {
* If the resulting Food debt is positive, the player must pay it with available Food.
* If the player does not have enough Food, all remaining Food is removed and the player
* loses Prestige equal to the unpaid Food debt multiplied by {@code PrestigeDebt}.
- * This event is intended to be executed last among event effects.
+ * This event is intended to be executed last among event effects.
*
* @param playerList the list of players affected by the event.
* @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}.
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java b/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java
index 4b7388a..971b545 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java
@@ -15,10 +15,19 @@ import java.io.*;
import java.lang.reflect.Type;
import java.util.*;
-//TODO javadoc
+/**
+ * Utility class responsible for loading and creating decks of cards and slots for the game.
+ * Cards are loaded from JSON resource files and instantiated according to their type and parameters.
+ */
public class DecksCreator {
- //TODO javadoc
+ /**
+ * Loads the tribe card deck for the specified era from the corresponding JSON resource file.
+ *
+ * @param era the era number (1, 2, or 3).
+ * @return a list of {@link TribeCard} objects for the specified era.
+ * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3.
+ */
public static List loadTribeDeckByEra(int era) throws IllegalArgumentException
{
return switch (era) {
@@ -29,7 +38,13 @@ public class DecksCreator {
};
}
- //TODO javadoc
+ /**
+ * Loads a tribe card deck from the specified JSON resource file path.
+ *
+ * @param resourcePath the path to the JSON resource file.
+ * @return a list of {@link TribeCard} objects defined in the resource file.
+ * @throws RuntimeException if the resource file is not found or an error occurs while reading it.
+ */
public static List loadTribeDeck(String resourcePath) {
Gson gson = new Gson();
Type listType = new com.google.gson.reflect.TypeToken>(){}.getType();
@@ -51,14 +66,26 @@ public class DecksCreator {
}
}
- //TODO javadoc
- public static List loadBuildingDeckByEra(int era) throws IllegalArgumentException
+ /**
+ * Loads the building card deck for the specified era, filtering cards from the global building deck.
+ *
+ * @param era the era number (1, 2, or 3).
+ * @return a list of {@link BuildingCard} objects belonging to the specified era.
+ * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3.
+ */
+ public static List loadBuildingDeckByEra(int era) throws IllegalArgumentException
{
if(era<=0 || era>3) throw new IllegalArgumentException();
return loadBuildingDeck("/Cards/buildingCards.json").stream().filter(x->x.getEra()==era).toList();
}
- //TODO javadoc
+ /**
+ * Loads the full building card deck from the specified JSON resource file path.
+ *
+ * @param resourcePath the path to the JSON resource file.
+ * @return a list of {@link BuildingCard} objects defined in the resource file.
+ * @throws RuntimeException if the resource file is not found or an error occurs while reading it.
+ */
public static List loadBuildingDeck(String resourcePath) {
Gson gson = new Gson();
Type listType = new com.google.gson.reflect.TypeToken>(){}.getType();
@@ -80,7 +107,12 @@ public class DecksCreator {
}
}
- //TODO javadoc
+ /**
+ * Creates and returns the list of slots used as the game board.
+ * Slots are labeled with the letters A through G.
+ *
+ * @return a list of {@link Slot} objects representing the game board.
+ */
public static List loadSlotDeck()
{
List slots = new ArrayList<>();
@@ -90,7 +122,15 @@ public class DecksCreator {
return slots;
}
- //TODO javadoc
+ /**
+ * Instantiates a {@link TribeCard} from the given definition.
+ * Depending on whether the card is an event or a character, the appropriate subclass is created
+ * using the type and parameters specified in the definition.
+ *
+ * @param def the {@link TribeCardDefinition} containing the card's type, era, and parameters.
+ * @return the instantiated {@link TribeCard}.
+ * @throws IllegalArgumentException if the card type is unknown or the parameters are invalid.
+ */
private static TribeCard createCard(TribeCardDefinition def) {
int era = def.era;
@@ -138,7 +178,14 @@ public class DecksCreator {
};
}
- //TODO javadoc
+ /**
+ * Instantiates a {@link BuildingCard} from the given definition.
+ * The appropriate subclass is selected based on the effect ID specified in the definition.
+ * If no specific subclass matches the effect ID, a base {@link BuildingCard} is created.
+ *
+ * @param def the {@link BuildingCardDefinition} containing the card's effect ID, era, price, prestige value, and parameters.
+ * @return the instantiated {@link BuildingCard}.
+ */
private static BuildingCard createCard(BuildingCardDefinition def) {
return switch (def.effectId) {
case 0 -> new Building0(def.era, def.price, def.prestigeValue);
@@ -153,7 +200,11 @@ public class DecksCreator {
}
- //TODO javadoc
+ /**
+ * Internal data class representing the raw definition of a tribe card as loaded from a JSON file.
+ * Contains the card type, era, whether it is armed, whether it is an event card,
+ * and a list of additional parameters.
+ */
private static class TribeCardDefinition {
String type;
int era;
@@ -162,7 +213,10 @@ public class DecksCreator {
List