Merge pull request #85 from rubenpirreram/javadoc-fixes

Fix and complete JavaDoc comments
This commit is contained in:
rubenpirreram
2026-05-06 17:36:46 +02:00
committed by GitHub
35 changed files with 384 additions and 58 deletions
@@ -119,6 +119,13 @@ public class GameController {
return model.DrawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
}
/**
* Skips the upper card drawing action for the specified player.
*
* @param playerUsername the username of the player who wants to skip the upper drawing action.
* @return {@code true} if the skip action is valid and successfully performed;
* {@code false} if the player does not exist or the action is not valid.
*/
public boolean SkipUpperDrawing(String playerUsername) {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
@@ -126,6 +133,13 @@ public class GameController {
return model.SkipUpperDrawing(model.getPlayerByUsername(playerUsername));
}
/**
* Skips the lower card drawing action for the specified player.
*
* @param playerUsername the username of the player who wants to skip the lower drawing action.
* @return {@code true} if the skip action is valid and successfully performed;
* {@code false} if the player does not exist or the action is not valid.
*/
public boolean SkipLowerDrawing(String playerUsername) {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
@@ -7,7 +7,17 @@ import javafx.stage.Stage;
import java.io.IOException;
/**
* JavaFX application entry point used to start the graphical interface.
*/
public class HelloApplication extends Application {
/**
* Starts the JavaFX application and loads the initial FXML view.
*
* @param stage the primary stage of the application.
* @throws IOException if the FXML file cannot be loaded.
*/
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
@@ -3,10 +3,16 @@ package it.polimi.ingsw.gc14;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
/**
* Controller for the initial JavaFX view.
*/
public class HelloController {
@FXML
private Label welcomeText;
/**
* Handles the click on the hello button.
*/
@FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
@@ -2,6 +2,18 @@ package it.polimi.ingsw.gc14.Model.Cards.Building;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Defines the effect behavior of a building card.
*
* <p>Classes implementing this interface provide the specific effect
* applied to a player when the building card is activated.
*/
public interface BuildingEffect {
public void applyEffect(Player player);
/**
* Applies the building effect to the specified player.
*
* @param player the player affected by the building effect.
*/
void applyEffect(Player player);
}
@@ -1,5 +1,10 @@
package it.polimi.ingsw.gc14.Model.Cards.Building;
/**
* Represents the possible effect types of building cards.
/**
* Represents the possible effect types of building cards.
*/
public enum EffectType {
FINAL, CARD_SET, INVENTOR_PAIR, ON_EVENT, ON_END_TURN, ON_ROUND_END
}
@@ -7,6 +7,11 @@ import it.polimi.ingsw.gc14.Model.Player;
import java.util.HashMap;
/**
* Represents the building card number 10.
*
* <p>This class defines the specific behavior and effects of building card 10.
*/
public class Building10 extends BuildingCard {
/**
@@ -5,6 +5,11 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents the building card number 11.
*
* <p>This class defines the specific behavior and effects of building card 11.
*/
public class Building11 extends BuildingCard {
/**
@@ -4,7 +4,13 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents the building card number 13.
*
* <p>This class defines the specific behavior and effects of building card 13.
*/
public class Building13 extends BuildingCard{
/**
* Creates a Building13 card with the specified era, price, and prestige value.
*
@@ -6,8 +6,16 @@ import it.polimi.ingsw.gc14.Model.PlayableCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Represents a generic building card in the game.
*
* <p>A building card is a playable card with a price and a specific building
* effect. Concrete building cards extend this class to define their own
* behavior.
*/
public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect, Serializable {
/**
* The price of this building card.
*/
@@ -1,5 +1,10 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards;
/**
* Represents the different types of character cards available in the game.
/**
* Represents the different types of character cards available in the game.
*/
public enum CharacterType {
INVENTOR, BUILDER, GATHERER, ARTIST, SHAMAN, HUNTER
}
@@ -4,12 +4,18 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents an Artist character card.
*
* <p>An Artist is a specific type of {@link Character} initialized with
* {@link CharacterType#ARTIST}.
*/
public class Artist extends Character {
/**
* Creates an Artist character card with the specified era.
*
* @param Era the era of the Artist card
* @param Era the era of the Artist card.
*/
public Artist(int Era) {
super(Era, CharacterType.ARTIST);
@@ -18,8 +24,8 @@ public class Artist extends Character {
/**
* Creates an Artist character card with the specified Era and minimum number of players required to play it.
*
* @param Era the era of the Artist card
* @param nMin the minimum number of players required for the card
* @param Era the era of the Artist card.
* @param nMin the minimum number of players required for the card.
*/
public Artist(int Era,int nMin) {
super(Era, CharacterType.ARTIST,nMin);
@@ -4,7 +4,14 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents a Builder character card.
*
* <p>A Builder is a specific type of {@link Character} that provides
* a reduction value when buying building cards.
*/
public class Builder extends Character {
/**
* The reduction value provided by this Builder card.
*/
@@ -4,7 +4,14 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents a Gatherer character card.
*
* <p>A Gatherer is a specific type of {@link Character} initialized with
* {@link CharacterType#GATHERER}.
*/
public class Gatherer extends Character {
/**
* Creates a Gatherer character card with the specified era.
*
@@ -4,6 +4,12 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents a Hunter character card.
*
* <p>A Hunter is a specific type of {@link Character} initialized with
* {@link CharacterType#HUNTER}.
*/
public class Hunter extends Character {
/**
@@ -3,6 +3,12 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents an Inventor character card.
*
* <p>An Inventor is a specific type of {@link Character} initialized with
* {@link CharacterType#INVENTOR}.
*/
public class Inventor extends Character {
/**
* The {@code Icons}'s ID. There are a total of 10 different Icons.
@@ -1,10 +1,15 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Represents a Shaman character card.
*
* <p>A Shaman is a specific type of {@link Character} initialized with
* {@link CharacterType#SHAMAN}.
*/
public class Shaman extends Character {
/**
* The number of star {@code Icons} the card possesses.
@@ -1,5 +1,10 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards;
/**
* Represents the different types of event cards available in the game.
/**
* Represents the different types of event cards available in the game.
*/
public enum EventType {
SUSTENANCE, SHAMANIC_RITUAL, CAVE_PAINTINGS, HUNT
}
@@ -10,6 +10,11 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.ArrayList;
/**
* Represents a Cave Paintings event card.
*
* <p>This class defines the specific behavior of the Cave Paintings event.
*/
public class CavePaintings extends EventCard {
/**
@@ -36,9 +36,9 @@ public class Hunt extends EventCard {
* Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
*
* Buildings influence:
* Building 7: you take 1 Food and 1 additional Prestige Point for each Hunter
* Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter.
*
* @param playerList contains all the players in the game
* @param playerList the list of all players in the game.
*/
@Override
public void activateEvent (ArrayList <Player> playerList){
@@ -8,6 +8,11 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.ArrayList;
/**
* Represents a Sustenance event card.
*
* <p>This class defines the specific behavior of the Sustenance event.
*/
public class Sustenance extends EventCard {
/**
@@ -34,7 +34,8 @@ public class Game implements Serializable {
/**
* Returns the list of players participating in the game.
* @return
*
* @return a copy of the list of players currently participating in the game.
*/
public List<Player> getPlayers() {
return playersList;
@@ -141,6 +142,7 @@ public class Game implements Serializable {
*
* @param Username the username of the player to search for.
* @return the player with the specified username, or {@code null} if no such player exists.
* @throws IndexOutOfBoundsException if an index access error occurs.
*/
public Player getPlayerByUsername(String Username) throws IndexOutOfBoundsException {
return playersList.stream().filter(x->x.getUserName().equals(Username)).findFirst().orElse(null);
@@ -50,9 +50,9 @@ public class Board implements Serializable {
private int era;
/**
* Creates and returns a new list containing the slots (tiles) of the game
* Creates and returns a new list containing the slots (tiles) of the game.
*
* @return a copy of the slot list
* @return a copy of the slot list.
*/
public List<Slot> getSlotList(){
return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList());
@@ -73,13 +73,13 @@ public class Board implements Serializable {
/**
* Creates and initializes a new board:
* - Generate the slotList using a method of DecksCreator
* - Generate the tribeDeck
* - Populate the lower list (if there is an event card, it's added to the upper list)
* - Populate the upper list
* - Generate the buildingDeck using a method of DecksCreator
* - Generate the slotList using a method of DecksCreator.
* - Generate the tribeDeck.
* - Populate the lower list (if there is an event card, it's added to the upper list).
* - Populate the upper list.
* - Generate the buildingDeck using a method of DecksCreator.
*
* @param nTotem the number of players
* @param nTotem the number of players.
*/
public Board(int nTotem) {
this.nTotem = nTotem;
@@ -157,12 +157,12 @@ public class Board implements Serializable {
* Creates the tribeDeck. Loads the cards from each era, shuffle them, and then combine them in the final deck.
* In the end, two special events (Sustenance and ShamanicRitual) are added.
*
* @param nPlayers the number of players
* @param nPlayers the number of players.
* @return a queue containing the cards in this order:
* - Era 1
* - Era 2
* - Era 3
* - Special events
* - Era 1.
* - Era 2.
* - Era 3.
* - Special events.
*/
private Queue<TribeCard> generateTribeDeck(int nPlayers) {
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
@@ -187,40 +187,40 @@ public class Board implements Serializable {
}
/**
* Take the selected card from the upper tribe list of the board
* Take the selected card from the upper tribe list of the board.
*
* @param tribeCard is the card to remove
* @return true if the card is succesfully removed
* @param tribeCard is the card to remove.
* @return true if the card is succesfully removed.
*/
public boolean removeUpperTribeCard(TribeCard tribeCard) {
return upperListTribe.remove(tribeCard);
}
/**
* Take the selected card from the lower tribe list of the board
* Take the selected card from the lower tribe list of the board.
*
* @param tribeCard is the card to remove
* @return true if succeed in removing the card
* @param tribeCard is the card to remove.
* @return true if succeed in removing the card.
*/
public boolean removeLowerTribeCard(TribeCard tribeCard) {
return lowerListTribe.remove(tribeCard);
}
/**
* Take the selected card from the upper building list of the board
* Take the selected card from the upper building list of the board.
*
* @param buildingCard is the card to remove
* @return true if succeed in removing the card
* @param buildingCard is the card to remove.
* @return true if succeed in removing the card.
*/
public boolean removeUpperBuildingCard(BuildingCard buildingCard) {
return upperListBuilding.remove(buildingCard);
}
/**
* Take the selected card from the lower building list of the board
* Take the selected card from the lower building list of the board.
*
* @param buildingCard is the card to remove
* @return true if succeed in removing the card
* @param buildingCard is the card to remove.
* @return true if succeed in removing the card.
*/
public boolean removeLowerBuildingCard(BuildingCard buildingCard) {
return lowerListBuilding.remove(buildingCard);
@@ -228,10 +228,11 @@ public class Board implements Serializable {
/**
* Goes to the next round.
* - Clear the lower tribe row
* - Moves the upper tribe row to the lower one
* - Populate the upper tribe row
* - Clear the lower tribe row.
* - Moves the upper tribe row to the lower one.
* - Populate the upper tribe row.
*
* @return the current era after moving to the next round.
*/
public int nextRound() {
lowerListTribe.clear();
@@ -253,9 +254,9 @@ public class Board implements Serializable {
/**
* Changes the era of the game:
* - Increase the era attribute
* - Clear the lower building list and replace it with the upper building list
* - Repopulate the upper building list
* - Increase the era attribute.
* - Clear the lower building list and replace it with the upper building list.
* - Repopulate the upper building list.
*/
private void nextEra() {
era=era+1;
@@ -1,5 +1,10 @@
package it.polimi.ingsw.gc14.Model.GamePackage;
/**
* Represents the possible stages of a game.
/**
* Represents the possible stages of a game.
*/
public enum GameStages {
WAITING, SLOT_CHOICE, RES_ACTIONS, OPT_CARD_E, RES_EVENT, ENDING, ENDED
}
@@ -9,6 +9,12 @@ import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
/**
* Abstract base class for all order logic cards.
*
* <p>An order logic card manages the turn order of the players and defines
* the behavior used to update the order during the game.
*/
public abstract class OrderLogicCard implements Serializable {
/**
@@ -8,6 +8,12 @@ import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.util.*;
import java.util.stream.IntStream;
/**
* Represents the order logic card used in a two-player game.
*
* <p>This class defines the specific turn-order behavior for games with
* two players.
*/
public class Order2 extends OrderLogicCard {
/**
@@ -9,6 +9,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Represents the order logic card used in a three-player game.
*
* <p>This class defines the specific turn-order behavior for games with
* three players.
*/
public class Order3 extends OrderLogicCard {
/**
@@ -9,6 +9,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Represents the order logic card used in a four-player game.
*
* <p>This class defines the specific turn-order behavior for games with
* four players.
*/
public class Order4 extends OrderLogicCard {
/**
@@ -9,6 +9,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Represents the order logic card used in a five-player game.
*
* <p>This class defines the specific turn-order behavior for games with
* five players.
*/
public class Order5 extends OrderLogicCard {
/**
@@ -5,21 +5,40 @@ import it.polimi.ingsw.gc14.Model.Player;
import java.io.Serializable;
/**
* Abstract base class for all order {@code logic cards}.
* An {@code OrderLogicCard} manages a queue of {@code players} and defines the effects
* applied when they are pushed back into the queue.
* @see it.polimi.ingsw.gc14.Model.Player Player
* Represents a player entry in an order logic card.
*
* <p>Each entry stores the player and whether that player has already
* performed an action in the current order sequence.
*/
public class OrderPlayer implements Serializable {
/**
* The player associated with this order entry.
*/
public Player player;
/**
* Indicates whether the player has already played.
*/
public boolean played;
/**
* Creates an order entry for the specified player.
*
* @param player the player associated with this order entry.
* @param played {@code true} if the player has already played;
* {@code false} otherwise.
*/
public OrderPlayer(Player player, boolean played) {
this.player = player;
this.played = played;
}
/**
* @return the string containing the username and whether it played or not.
* Returns a string containing the player's username and whether the player
* has already played.
*
* @return the string containing the username and whether the player has played.
*/
@Override
public String toString() {
@@ -1,5 +1,16 @@
package it.polimi.ingsw.gc14.Network;
/**
* Represents the possible actions requested by a client and handled by the
* server during the game.
*
* <p>Each value identifies a specific user action, such as adding a player,
* choosing a slot, drawing a card, picking an optional card, or skipping an
* optional action.
/**
* Represents the different types of network events that can be sent between
* client and server.
*/
public enum EventType {
ADD_PLAYER,
SLOT_CHOICE,
@@ -6,7 +6,28 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import java.io.Serializable;
import java.rmi.*;
/**
* Callback interface used by the server to notify an RMI client about
* game updates and incoming network actions.
*
* <p>Implementations of this interface are remotely accessible and
* serializable.
*/
public interface IClientCallback extends Remote, Serializable {
/**
* Notifies the client that the game model has been initialized or updated.
*
* @param model the current game model.
* @throws RemoteException if an RMI communication error occurs.
*/
void onGameInit(Game model) throws RemoteException;
/**
* Notifies the client about a network action to process.
*
* @param action the network event received from the server.
* @throws RemoteException if an RMI communication error occurs.
*/
void onAction(NetworkEvent action) throws RemoteException;
}
@@ -4,9 +4,31 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import java.rmi.*;
/**
* Remote interface used by RMI clients to interact with the game server.
*/
public interface IGameServer extends Remote {
/**
* Adds a player to the game through the remote server.
*
* @param username the username of the player joining the game.
* @param preferredInt the preferred player number or slot selected by the client.
* @param callback the client callback used by the server to send updates.
* @return {@code true} if the player successfully joins the game;
* {@code false} otherwise.
* @throws RemoteException if an RMI communication error occurs.
*/
boolean joinGame(String username,int preferredInt, IClientCallback callback) throws RemoteException;
/**
* Sends a network event to the game server.
*
* @param event the event to be processed by the server.
* @return {@code true} if the event is accepted and processed;
* {@code false} otherwise.
* @throws RemoteException if an RMI communication error occurs.
*/
boolean doEvent(NetworkEvent event) throws RemoteException;
void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException;
@@ -43,9 +43,12 @@ public class ClientHandler implements Runnable {
/**
* Class constructor that initializes the attributes.
* @param clientSocket The socket representing the client's TCP connection
* @param clientHandlers The shared list of all active client handlers
* @param actionQueue The queue containing incoming events
*
* @param clientSocket the socket representing the client's TCP connection.
* @param out the output stream used to send data to the client.
* @param in the input stream used to receive data from the client.
* @param clientHandlers the shared list of all active client handlers.
* @param actionQueue the queue containing incoming events.
*/
public ClientHandler(String username, Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List<ClientHandler> clientHandlers, BlockingQueue<NetworkEvent> actionQueue) {
this.username=username;
@@ -139,7 +139,11 @@ public class TCPServer {
}
/** Sends an action to all TCP clients */
/**
* Sends an action to all TCP clients.
*
* @param event the network event to send to all connected TCP clients.
*/
public void notifyAll(NetworkEvent event){
clientHandlers.forEach((x) -> {
if(!event.getIsError()||(event.getIsError()&& event.getUsername().equals(x.getUsername())))
@@ -148,7 +152,11 @@ public class TCPServer {
}
/** Sends a game model to all TCP clients */
/**
* Sends a game model to all TCP clients.
*
* @param model the game model to send to all connected TCP clients.
*/
public void notifyAll(Game model){
clientHandlers.forEach((x) -> x.notifyModel(model));
}
@@ -1,11 +1,28 @@
package it.polimi.ingsw.gc14.View.TUI;
/**
* Defines the available border styles used to render {@link AsciiTable}
* instances in the text-based user interface.
*
* <p>Each style stores the characters needed to draw table corners,
* horizontal and vertical lines, and junctions.
*/
public enum BorderStyle {
//UNICODE("","","","","","","","","","","","","","",""),
UNICODE ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+"),
ROUNDED ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+");
//ROUNDED("","","","","","","","","","","","","","","");
/**
* Unicode box-drawing border style.
*/
UNICODE("","","","","","","","","","","","","","",""),
/**
* Plain ASCII border style.
*/
ASCII ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+"),
/**
* Rounded Unicode border style.
*/
ROUNDED("","","","","","","","","","","","","","","");
private final String tl,tr,bl,br,h,v,ml,mr,mt,mb,x,sl,sr,sh,sx;
@@ -23,19 +40,78 @@ public enum BorderStyle {
this.sh = sh; this.sx = sx;
}
/**
* @return the top-left corner character.
*/
public String tl() { return tl; }
/**
* @return the top-right corner character.
*/
public String tr() { return tr; }
/**
* @return the bottom-left corner character.
*/
public String bl() { return bl; }
/**
* @return the bottom-right corner character.
*/
public String br() { return br; }
/**
* @return the horizontal line character.
*/
public String h() { return h; }
/**
* @return the vertical line character.
*/
public String v() { return v; }
/**
* @return the middle-left junction character.
*/
public String ml() { return ml; }
/**
* @return the middle-right junction character.
*/
public String mr() { return mr; }
/**
* @return the top-middle junction character.
*/
public String mt() { return mt; }
/**
* @return the bottom-middle junction character.
*/
public String mb() { return mb; }
/**
* @return the center junction character.
*/
public String x() { return x; }
/**
* @return the separator-left junction character.
*/
public String sl() { return sl; }
/**
* @return the separator-right junction character.
*/
public String sr() { return sr; }
/**
* @return the separator horizontal line character.
*/
public String sh() { return sh; }
/**
* @return the separator center junction character.
*/
public String sx() { return sx; }
}