From 339e606504518a783fad07f9e84d332a7e368e49 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 18 Apr 2026 17:41:54 +0200 Subject: [PATCH 01/14] Add: Javadoc for BuildingCard --- .../ingsw/gc14/Model/Cards/BuildingCard.java | 96 ++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) 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 9b632f7..5c16e8e 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 @@ -8,24 +8,76 @@ import it.polimi.ingsw.gc14.Model.Player; import java.util.ArrayList; public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect { + + /** + * The price of this building card. + */ private int price; + + /** + * Returns the price of this building card. + * + * @return the price of this building card + */ public int getPrice() { return price; } + + /** + * Indicates whether this building card has already been bought. + */ private boolean bought; + + /** + * The type of effect associated with this building card. + */ protected EffectType effectType; + + /** + * The identifier of the effect associated with this building card. + */ protected int effectId; + + /** + * The prestige value of this building card. + */ private int prestigeValue; + + /** + * Returns the prestige value of this building card. + * + * @return the prestige value of this building card + */ public int getPrestigeValue() { return prestigeValue; } + + /** + * Returns the identifier of the effect associated with this building card. + * + * @return the effect identifier of this building card + */ public int getEffectId() { return effectId; } + + /** + * Returns the type of effect associated with this building card. + * + * @return the effect type of this building card + */ public EffectType getEffectType() { return effectType; } + /** + * Creates a building card with the specified era, price, and prestige value. + * + * @param era the era of the building card + * @param price the price of the building card + * @param prestigeValue the prestige value of the building card + * @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0} + */ public BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{ super(era); if (price > 0) { @@ -41,6 +93,20 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf bought = false; } + + + /** + * Creates a building card with the specified effect identifier, era, price, + * and prestige value. + * The effect type is determined from the given effect identifier. + * + * @param effectId the identifier of the effect associated with the building card + * @param era the era of the building card + * @param price the price of the building card + * @param prestigeValue the prestige value of the building card + * @throws IllegalArgumentException if the effect identifier is not valid, + * if {@code price <= 0}, or if {@code prestigeValue < 0} + */ public BuildingCard(int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{ this.effectId = effectId; switch (effectId){ @@ -72,12 +138,28 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf this(era,price,prestigeValue); } - + /** + * Creates and returns a copy of this building card. + * + * @return a clone of this building card + */ @Override public BuildingCard clone() { return new BuildingCard(effectId,getEra(),getPrice(),getPrestigeValue()); } + + /** + * Attempts to buy this building card for the specified player. + * The purchase succeeds only if the card has not already been bought + * and the player can pay its price in Food. + * If the purchase succeeds, the card is added to the player's building cards + * and marked as bought. + * + * @param player the player attempting to buy the building card + * @return {@code true} if the building card is successfully bought, + * {@code false} otherwise + */ public boolean buy(Player player) { if( bought || !player.removeFood(getPrice())) return false; @@ -85,8 +167,20 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf bought=true; return true; } + + /** + * Applies the effect of this building card to the specified player. + * + * @param player the player to whom the effect is applied + */ + @Override public void applyEffect(Player player){}; + /** + * Returns the string representation of this building card. + * + * @return the string representation of this building card + */ @Override public String toString() { return "Era:"+String.valueOf(getEra())+" Price:"+String.valueOf(getPrice())+" Prestige:"+String.valueOf(getPrestigeValue()); From 2aca523bf0a21786113d76289854a51a2564ae6f Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 18 Apr 2026 17:56:40 +0200 Subject: [PATCH 02/14] Add: Javadoc for Character --- .../Model/Cards/TribeCards/Character.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java index 9717f5b..ea4a22d 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java @@ -3,29 +3,75 @@ package it.polimi.ingsw.gc14.Model.Cards.TribeCards; import it.polimi.ingsw.gc14.Model.Cards.TribeCard; import it.polimi.ingsw.gc14.Model.Player; - +/** + * Abstract base class for all character cards. + * A Character is a {@link TribeCard} that is not an event card and is associated + * with a specific {@link CharacterType}. + */ public abstract class Character extends TribeCard implements Cloneable { + + /** + * The specific type of this character card. + */ private CharacterType type; + + /** + * Returns the type of this character card. + * + * @return the type of this character card + */ public CharacterType getType() { return type; } + /** + * Creates a character card with the specified era and character type. + * + * @param Era the era of the character card + * @param type the type of the character card + */ public Character(int Era, CharacterType type){ super(Era,false ); this.type = type; } + + /** + * Creates a character card with the specified era, character type, + * and minimum number of players. + * + * @param Era the era of the character card + * @param type the type of the character card + * @param nMin the minimum number of players required for the card + */ public Character(int Era, CharacterType type,int nMin){ super(Era,false ,nMin); this.type = type; } + /** + * Returns the string representation of this character card. + * The returned string includes the string representation of the superclass + * and the string representation of the character type. + * + * @return the string representation of this character card + */ @Override public String toString() { return super.toString()+" "+type.toString(); } + /** + * Creates and returns a copy of this character card. + * + * @return a clone of this character card + */ @Override public abstract Character clone(); + /** + * Inserts this character card into the appropriate collection of the specified player. + * + * @param player the player who receives the character card + */ public abstract void insert(Player player); } From 9f8413fdc211377099857d61d9908f68c66e370f Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 18 Apr 2026 18:11:48 +0200 Subject: [PATCH 03/14] Add: Partial Implementation Of TCPServer.java. --- .../gc14/Network/Server/TCP/TCPServer.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/Server/TCP/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/Server/TCP/TCPServer.java index 4403d84..a2e6e80 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/Server/TCP/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/Server/TCP/TCPServer.java @@ -9,11 +9,16 @@ import java.util.List; public class TCPServer { int port = -1; + int ConnectedPlayers = 0; ServerSocket serverTCP = null; GameController gameController; private List clientHandlers; + private int getConnectedPlayers(){ + return ConnectedPlayers; + } + public void start(String args[]){ clientHandlers = new ArrayList<>(); @@ -25,19 +30,26 @@ public class TCPServer { e.printStackTrace(); return; } - System.out.println("Listening on port " + port); + System.out.println("Listening on port: " + port); while(true){ Socket clientSocket = null; - try { + try{ clientSocket = serverTCP.accept(); - } catch (IOException e) { + if(!gameController.addPlayer(clientSocket.getInputStream().toString()) || ConnectedPlayers >= clientHandlers.size()){ + clientSocket.close(); + System.out.println("Player already present or username is invalid. Connection terminated.\n"); + } + } + catch (IOException e){ e.printStackTrace(); } + System.out.println("Accepted"); - ClientHandler clientHandler = new ClientHandler(clientSocket, clientHandlers, this.gameController); + ConnectedPlayers++; + ClientHandler clientHandler = new ClientHandler(clientSocket, clientHandlers, gameController); clientHandlers.add(clientHandler); Thread t = new Thread(clientHandler); t.start(); From 3abc0e14b89d40c36fd34c01f65a1f989e72ff93 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 18 Apr 2026 18:20:46 +0200 Subject: [PATCH 04/14] Add: Javadoc for EventCard --- .../Model/Cards/TribeCards/EventCard.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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 549d5fb..a555aa2 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 @@ -6,13 +6,37 @@ import it.polimi.ingsw.gc14.Model.Player; import java.util.ArrayList; import java.lang.reflect.Array; +/** + * Abstract base class for all event cards. + * An EventCard is a {@link TribeCard} marked as an event card and associated + * with a specific {@link EventType}. + */ public abstract class EventCard extends TribeCard { + // Getters + + /** + * The specific type of this event card. + */ private EventType type; + + /** + * Returns the type of this event card. + * + * @return the type of this event card + */ public EventType getType() { return type; } + // End getters // Constructors + + /** + * Creates an event card with the specified era and event type. + * + * @param Era the era of the event card + * @param type the type of the event card + */ public EventCard(int Era, EventType type) { super(Era,true); this.type = type; @@ -20,15 +44,34 @@ public abstract class EventCard extends TribeCard { // End Constructors // Function + + /** + * Creates and returns a copy of this event card. + * + * @return a clone of this event card + */ @Override public abstract TribeCard clone(); + /** + * Returns the string representation of this event card. + * The returned string includes the string representation of the superclass + * and the string representation of the event type. + * + * @return the string representation of this event card + */ @Override public String toString() { return super.toString()+" "+type.toString(); } + /** + * Activates the effect of this event card on the specified list of players. + * + * @param playerList the list of players affected by the event + */ public abstract void activateEvent (ArrayList playerList); + // End Functions } From 2e806d3987d9627382580d79ec50a387e17be022 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 18 Apr 2026 18:21:01 +0200 Subject: [PATCH 05/14] Add: Javadoc for TribeCard --- .../ingsw/gc14/Model/Cards/TribeCard.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java index 00260f9..38e3364 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java @@ -3,24 +3,71 @@ package it.polimi.ingsw.gc14.Model.Cards; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character; import it.polimi.ingsw.gc14.Model.PlayableCard; +/** + * Abstract base class for all tribe cards. + * A TribeCard is a {@link PlayableCard} that may either be an event card + * or a non-event card, and may optionally specify a minimum number of players. + */ public abstract class TribeCard extends PlayableCard { + + /** + * Indicates whether this tribe card is an event card. + */ private boolean isEventCard; + + /** + * Returns whether this tribe card is an event card. + * + * @return {@code true} if this card is an event card, {@code false} otherwise + */ public boolean IsEventCard() { return isEventCard; } + /** + * The minimum number of players required for this tribe card. + */ private int nMin=0; + + /** + * Returns the minimum number of players required for this tribe card. + * + * @return the minimum number of players required for this tribe card + */ public int getNMin() { return nMin; } + + /** + * Creates a tribe card with the specified era and event-card flag. + * The minimum number of players is set to 0. + * + * @param Era the era of the tribe card + * @param isEventCard whether the card is an event card + */ public TribeCard(int Era,boolean isEventCard) { this(Era,isEventCard,0); } + + /** + * Creates a tribe card with the specified era, event-card flag, + * and minimum number of players. + * + * @param Era the era of the tribe card + * @param isEventCard whether the card is an event card + * @param nMin the minimum number of players required for the card + */ public TribeCard(int Era,boolean isEventCard,int nMin) { super(Era); this.nMin=nMin; this.isEventCard=isEventCard; } + + /** + * Creates and returns a copy of this tribe card. + * + * @return a clone of this tribe card + */ @Override public abstract TribeCard clone(); } From c1e9602b35b174f9d244437fcdd886158fcc67d1 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 18 Apr 2026 19:17:55 +0200 Subject: [PATCH 06/14] Add: Added Partial Logic For Client Connection Handling And Termination In TCPServer.java. --- .../Network/TCP/Server/ClientHandler.java | 25 ++++++++++++------- .../gc14/Network/TCP/Server/TCPServer.java | 11 +++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index a599d19..7000c31 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -12,37 +12,44 @@ public class ClientHandler implements Runnable { PrintWriter out = null; List clientHandlers; GameController gameController; + public ClientHandler(Socket clientSocket, List clientHandlers, GameController gameController) { this.clientSocket = clientSocket; this.clientHandlers = clientHandlers; this.gameController = gameController; } + @Override - public void run() { + public void run(){ clientLoop(); } - private void clientLoop() { - try { + + private void clientLoop(){ + try{ in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - synchronized (out) { + synchronized(out){ out = new PrintWriter(clientSocket.getOutputStream(), true); } - } catch (IOException e) { + } + catch(IOException e){ e.printStackTrace(); } String s = ""; try{ while ((s = in.readLine()) != null) { - System.out.println(s); - out.println(s.toUpperCase()); + synchronized(out){ + System.out.println(s); + out.println(s.toUpperCase()); + } } } catch (IOException e) { e.printStackTrace(); } } - private void notifyEvent(Object event) { - synchronized (out) { + + public void notifyEvent(Object event) { + synchronized(out){ out.println(event.toString()); } } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java index 8a4fe3b..7cafb9e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java @@ -37,16 +37,15 @@ public class TCPServer { try{ clientSocket = serverTCP.accept(); - if(!gameController.addPlayer(clientSocket.getInputStream().toString()) || ConnectedPlayers >= clientHandlers.size()){ + if(!gameController.addPlayer(clientSocket.getInputStream().toString()) || ConnectedPlayers > gameController.getModel().getNPlayers()){ clientSocket.close(); - System.out.println("Player already present or username is invalid. Connection terminated.\n"); + System.out.println("Invalid parameters. Connection terminated.\n"); } } catch (IOException e){ e.printStackTrace(); } - System.out.println("Accepted"); ConnectedPlayers++; ClientHandler clientHandler = new ClientHandler(clientSocket, clientHandlers, gameController); @@ -56,8 +55,12 @@ public class TCPServer { } } - private TCPServer(GameController gameController, int port) { + private TCPServer(GameController gameController, int port){ this.port = port; this.gameController = gameController; } + + public void broadcastUpdate(Object event){ + clientHandlers.forEach((x) -> x.notifyEvent(event)); + } } From 2302671a5ac9ddea9fe6adf6e1175ed8ef8ab504 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sun, 19 Apr 2026 12:15:14 +0200 Subject: [PATCH 07/14] Fixed: Javadoc in BuildingCard.java, Character.java, EventCard.java, and TribeCard.java. --- .../ingsw/gc14/Model/Cards/BuildingCard.java | 32 +++++++++---------- .../ingsw/gc14/Model/Cards/TribeCard.java | 16 +++++----- .../Model/Cards/TribeCards/Character.java | 20 ++++++------ .../Model/Cards/TribeCards/EventCard.java | 14 ++++---- 4 files changed, 41 insertions(+), 41 deletions(-) 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 5c16e8e..ba35960 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 @@ -17,7 +17,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Returns the price of this building card. * - * @return the price of this building card + * @return the price of this building card. */ public int getPrice() { return price; @@ -46,7 +46,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Returns the prestige value of this building card. * - * @return the prestige value of this building card + * @return the prestige value of this building card. */ public int getPrestigeValue() { return prestigeValue; @@ -55,7 +55,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Returns the identifier of the effect associated with this building card. * - * @return the effect identifier of this building card + * @return the effect identifier of this building card. */ public int getEffectId() { return effectId; @@ -64,7 +64,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Returns the type of effect associated with this building card. * - * @return the effect type of this building card + * @return the effect type of this building card. */ public EffectType getEffectType() { return effectType; @@ -73,9 +73,9 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Creates a building card with the specified era, price, and prestige value. * - * @param era the era of the building card - * @param price the price of the building card - * @param prestigeValue the prestige value of the building card + * @param era the era of the building card. + * @param price the price of the building card. + * @param prestigeValue the prestige value of the building card. * @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0} */ public BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{ @@ -100,10 +100,10 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf * and prestige value. * The effect type is determined from the given effect identifier. * - * @param effectId the identifier of the effect associated with the building card - * @param era the era of the building card - * @param price the price of the building card - * @param prestigeValue the prestige value of the building card + * @param effectId the identifier of the effect associated with the building card. + * @param era the era of the building card. + * @param price the price of the building card. + * @param prestigeValue the prestige value of the building card. * @throws IllegalArgumentException if the effect identifier is not valid, * if {@code price <= 0}, or if {@code prestigeValue < 0} */ @@ -141,7 +141,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Creates and returns a copy of this building card. * - * @return a clone of this building card + * @return a clone of this building card. */ @Override public BuildingCard clone() @@ -156,9 +156,9 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf * If the purchase succeeds, the card is added to the player's building cards * and marked as bought. * - * @param player the player attempting to buy the building card + * @param player the player attempting to buy the building card. * @return {@code true} if the building card is successfully bought, - * {@code false} otherwise + * {@code false} otherwise. */ public boolean buy(Player player) { if( bought || !player.removeFood(getPrice())) @@ -171,7 +171,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Applies the effect of this building card to the specified player. * - * @param player the player to whom the effect is applied + * @param player the player to whom the effect is applied. */ @Override public void applyEffect(Player player){}; @@ -179,7 +179,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf /** * Returns the string representation of this building card. * - * @return the string representation of this building card + * @return the string representation of this building card. */ @Override public String toString() { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java index 38e3364..845f68b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java @@ -18,7 +18,7 @@ public abstract class TribeCard extends PlayableCard { /** * Returns whether this tribe card is an event card. * - * @return {@code true} if this card is an event card, {@code false} otherwise + * @return {@code true} if this card is an event card, {@code false} otherwise. */ public boolean IsEventCard() { return isEventCard; @@ -32,7 +32,7 @@ public abstract class TribeCard extends PlayableCard { /** * Returns the minimum number of players required for this tribe card. * - * @return the minimum number of players required for this tribe card + * @return the minimum number of players required for this tribe card. */ public int getNMin() { return nMin; @@ -42,8 +42,8 @@ public abstract class TribeCard extends PlayableCard { * Creates a tribe card with the specified era and event-card flag. * The minimum number of players is set to 0. * - * @param Era the era of the tribe card - * @param isEventCard whether the card is an event card + * @param Era the era of the tribe card. + * @param isEventCard whether the card is an event card. */ public TribeCard(int Era,boolean isEventCard) { this(Era,isEventCard,0); @@ -53,9 +53,9 @@ public abstract class TribeCard extends PlayableCard { * Creates a tribe card with the specified era, event-card flag, * and minimum number of players. * - * @param Era the era of the tribe card - * @param isEventCard whether the card is an event card - * @param nMin the minimum number of players required for the card + * @param Era the era of the tribe card. + * @param isEventCard whether the card is an event card. + * @param nMin the minimum number of players required for the card. */ public TribeCard(int Era,boolean isEventCard,int nMin) { super(Era); @@ -66,7 +66,7 @@ public abstract class TribeCard extends PlayableCard { /** * Creates and returns a copy of this tribe card. * - * @return a clone of this tribe card + * @return a clone of this tribe card. */ @Override public abstract TribeCard clone(); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java index ea4a22d..9cdb9ae 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java @@ -5,7 +5,7 @@ import it.polimi.ingsw.gc14.Model.Player; /** * Abstract base class for all character cards. - * A Character is a {@link TribeCard} that is not an event card and is associated + * A Character is a {@link TribeCard} that is not an event card and is associated. * with a specific {@link CharacterType}. */ public abstract class Character extends TribeCard implements Cloneable { @@ -18,7 +18,7 @@ public abstract class Character extends TribeCard implements Cloneable { /** * Returns the type of this character card. * - * @return the type of this character card + * @return the type of this character card. */ public CharacterType getType() { return type; @@ -27,8 +27,8 @@ public abstract class Character extends TribeCard implements Cloneable { /** * Creates a character card with the specified era and character type. * - * @param Era the era of the character card - * @param type the type of the character card + * @param Era the era of the character card. + * @param type the type of the character card. */ public Character(int Era, CharacterType type){ super(Era,false ); @@ -39,9 +39,9 @@ public abstract class Character extends TribeCard implements Cloneable { * Creates a character card with the specified era, character type, * and minimum number of players. * - * @param Era the era of the character card - * @param type the type of the character card - * @param nMin the minimum number of players required for the card + * @param Era the era of the character card. + * @param type the type of the character card. + * @param nMin the minimum number of players required for the card. */ public Character(int Era, CharacterType type,int nMin){ super(Era,false ,nMin); @@ -53,7 +53,7 @@ public abstract class Character extends TribeCard implements Cloneable { * The returned string includes the string representation of the superclass * and the string representation of the character type. * - * @return the string representation of this character card + * @return the string representation of this character card. */ @Override public String toString() { @@ -63,7 +63,7 @@ public abstract class Character extends TribeCard implements Cloneable { /** * Creates and returns a copy of this character card. * - * @return a clone of this character card + * @return a clone of this character card. */ @Override public abstract Character clone(); @@ -71,7 +71,7 @@ public abstract class Character extends TribeCard implements Cloneable { /** * Inserts this character card into the appropriate collection of the specified player. * - * @param player the player who receives the character card + * @param player the player who receives the character card. */ public abstract void insert(Player player); } 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 a555aa2..a85898b 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 @@ -8,7 +8,7 @@ import java.lang.reflect.Array; /** * Abstract base class for all event cards. - * An EventCard is a {@link TribeCard} marked as an event card and associated + * An EventCard is a {@link TribeCard} marked as an event card and associated. * with a specific {@link EventType}. */ public abstract class EventCard extends TribeCard { @@ -23,7 +23,7 @@ public abstract class EventCard extends TribeCard { /** * Returns the type of this event card. * - * @return the type of this event card + * @return the type of this event card. */ public EventType getType() { return type; } @@ -34,8 +34,8 @@ public abstract class EventCard extends TribeCard { /** * Creates an event card with the specified era and event type. * - * @param Era the era of the event card - * @param type the type of the event card + * @param Era the era of the event card. + * @param type the type of the event card. */ public EventCard(int Era, EventType type) { super(Era,true); @@ -48,7 +48,7 @@ public abstract class EventCard extends TribeCard { /** * Creates and returns a copy of this event card. * - * @return a clone of this event card + * @return a clone of this event card. */ @Override public abstract TribeCard clone(); @@ -58,7 +58,7 @@ public abstract class EventCard extends TribeCard { * The returned string includes the string representation of the superclass * and the string representation of the event type. * - * @return the string representation of this event card + * @return the string representation of this event card. */ @Override public String toString() { @@ -68,7 +68,7 @@ public abstract class EventCard extends TribeCard { /** * Activates the effect of this event card on the specified list of players. * - * @param playerList the list of players affected by the event + * @param playerList the list of players affected by the event. */ public abstract void activateEvent (ArrayList playerList); From c2500292f08d5c00a237b67539930b6ee11da6f6 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sun, 19 Apr 2026 15:29:28 +0200 Subject: [PATCH 08/14] Add: Javadoc for Slot class --- .../java/it/polimi/ingsw/gc14/Model/Slot.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java index 083e9f9..4f41da4 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java @@ -1,26 +1,79 @@ package it.polimi.ingsw.gc14.Model; +/** + * Represents a slot with a specific identifier and associated values + * for upper cards, lower cards, food, and minimum number of players. + * The slot configuration depends on the specified slot identifier. + */ public class Slot { // Getters + + /** + * The identifier of this slot. + */ private char slotId; + + /** + * Returns the identifier of this slot. + * + * @return the identifier of this slot. + */ public char getSlotId() { return slotId; } + + /** + * The number of upper cards associated with this slot. + */ private int NUpper; + /** + * Returns the number of upper cards associated with this slot. + * + * @return the number of upper cards associated with this slot. + */ public int getNUpper(){ return NUpper; } + + /** + * The minimum number of players required for this slot. + */ private int nMinPlayer; + + /** + * Returns the minimum number of players required for this slot. + * + * @return the minimum number of players required for this slot. + */ public int getNMinPlayer() { return nMinPlayer; } + + /** + * The number of lower cards associated with this slot. + */ private int NLower; + + /** + * Returns the number of lower cards associated with this slot. + * + * @return the number of lower cards associated with this slot. + */ public int getNLower(){ return NLower; } + /** + * The amount of Food associated with this slot. + */ private int Food; + + /** + * Returns the amount of Food associated with this slot. + * + * @return the amount of Food associated with this slot. + */ public int getFood(){ return Food; } @@ -28,7 +81,17 @@ public class Slot { // Setters // End setters + // Constructors + + /** + * Creates a slot with the specified identifier. + * The slot values for Food, NLower, NUpper, and minimum number of players + * are determined by the given slot identifier. + * + * @param slotId the identifier of the slot. + * @throws IllegalArgumentException if the specified slot identifier is not valid. + */ public Slot(char slotId) throws IllegalArgumentException { this.slotId = slotId; @@ -78,6 +141,14 @@ public class Slot { } } + + /** + * Returns the string representation of this slot. + * The returned string includes the slot identifier, number of upper cards, + * number of lower cards, food value, and minimum number of players. + * + * @return the string representation of this slot. + */ @Override public String toString() { return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n"); From ec9c236932e85153a166a9e61adfa1acbf216013 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sun, 19 Apr 2026 15:34:49 +0200 Subject: [PATCH 09/14] Add: Javadoc for PlayableCard class --- .../polimi/ingsw/gc14/Model/PlayableCard.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java index 7d3b418..6df2330 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java @@ -1,10 +1,31 @@ package it.polimi.ingsw.gc14.Model; +/** + * Abstract base class for all playable cards. + * A PlayableCard is characterized by an era value. + */ public abstract class PlayableCard { + + /** + * The era associated with this playable card. + */ private int Era; + + /** + * Returns the era of this playable card. + * + * @return the era of this playable card. + */ public int getEra(){ return Era; } + + /** + * Creates a playable card with the specified era. + * + * @param Era the era of the playable card. + * @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}. + */ public PlayableCard (int Era) throws IllegalArgumentException{ if (Era>0 && Era<4) { this.Era = Era; @@ -13,6 +34,11 @@ public abstract class PlayableCard { } } + /** + * Returns the string representation of this playable card. + * + * @return the string representation of this playable card. + */ @Override public String toString() { return "Era:"+String.valueOf(Era); From 9809a409a4bd099cee668901a36015aa90df533c Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sun, 19 Apr 2026 15:45:14 +0200 Subject: [PATCH 10/14] Add: Javadoc for OrderLogicCard class --- .../ingsw/gc14/Model/OrderLogicCard.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/OrderLogicCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/OrderLogicCard.java index cfb298d..52fbf2b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/OrderLogicCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/OrderLogicCard.java @@ -4,25 +4,75 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import java.util.*; +/** + * Abstract base class for all order logic cards. + * An OrderLogicCard manages a queue of players and defines the effects + * applied when players are pushed back into the queue. + */ public abstract class OrderLogicCard { + + /** + * The queue of players associated with this order logic card. + */ private Queue players; + + /** + * Creates an order logic card with the specified list of players. + * The input list is shuffled before being inserted into the queue. + * + * @param players the list of players associated with this order logic card. + */ public OrderLogicCard(ArrayList players) { Collections.shuffle(players); this.players = new LinkedList<>(players); } + + /** + * Applies the effect associated with the current queue position of the player + * and then adds the player to the end of the queue. + * + * @param player the player to be pushed into the queue. + */ public void push(Player player){ effect(player,players.size()); players.add(player); } + + /** + * Removes and returns the first player in the queue. + * + * @return the first player in the queue, or {@code null} if the queue is empty. + */ public Player pull(){ return players.poll(); } + + /** + * Returns the first player in the queue without removing it. + * + * @return the first player in the queue, or {@code null} if the queue is empty. + */ public Player getFirst() { return players.peek(); } + + /** + * Applies the effect associated with the specified player and queue position. + * + * @param player the player to whom the effect is applied. + * @param index the queue position index associated with the effect. + * @throws IndexOutOfBoundsException if the specified index is not valid. + */ protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException; + /** + * Applies the building-related effect to the specified player. + * For each building card owned by the player with effect id equal to 3, + * the player gains 1 Food. + * + * @param player the player to whom the building effect is applied. + */ protected void buildingEffect(Player player) { for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList()) From e9e0bc7405c16fb37e8589934e523d3f5a40efcc Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sun, 19 Apr 2026 16:02:03 +0200 Subject: [PATCH 11/14] Add: Javadoc for CurrentState class --- .../gc14/Model/GamePackage/CurrentState.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentState.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentState.java index c1039b7..0d171f0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentState.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentState.java @@ -4,39 +4,108 @@ import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Slot; import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; +/** + * Represents the current state of the game. + * A CurrentState object stores the current player, slot, era, round, + * remaining upper and lower cards, and the current game stage. + */ public class CurrentState { // region Getters + + /** + * The current player associated with the game state. + */ private Player player; + + /** + * Returns the current player. + * + * @return the current player. + */ public Player getCurrentPlayer(){ return player; } + /** + * The current slot associated with the game state. + */ private Slot slot; + + /** + * Returns the current slot. + * + * @return the current slot. + */ public Slot getSlot(){ return slot; } + /** + * The current era of the game. + */ private int Era; + + /** + * Returns the current era of the game. + * + * @return the current era of the game. + */ public int getEra(){ return Era; } + /** + * The current round of the game. + */ private int round; + + /** + * Returns the current round of the game. + * + * @return the current round of the game. + */ public int getRound(){ return round; } + /** + * The number of upper cards currently available. + */ private int NUpper; + + /** + * Returns the number of upper cards currently available. + * + * @return the number of upper cards currently available. + */ public int getNUpper(){ return NUpper; } + /** + * The number of lower cards currently available. + */ private int NLower; + + /** + * Returns the number of lower cards currently available. + * + * @return the number of lower cards currently available. + */ public int getNLower(){ return NLower; } + /** + * The current stage of the game. + */ private GameStages GameStage; + + /** + * Returns the current stage of the game. + * + * @return the current stage of the game. + */ public GameStages getGameStage(){ return GameStage; } @@ -44,28 +113,52 @@ public class CurrentState { // endregion getters // region Setters + + /** + * Increments the current era by 1. + */ public void EraUpdate(){ Era++; } + /** + * Increments the current round by 1. + */ public void RoundUpdate(){ round++; } + /** + * Decrements the number of upper cards by 1. + */ public void UpperDrawn(){ NUpper--; } + /** + * Decrements the number of lower cards by 1. + */ public void LowerDrawn(){ NLower--; } + /** + * Updates the current game stage. + * + * @param GameStage the new game stage. + */ public void GameStageUpdate(GameStages GameStage){ this.GameStage = GameStage; } // endregion setters // region Constructors + + /** + * Creates a new CurrentState object with default initial values. + * The initial player and slot are {@code null}, the era and round are set to 1, + * the number of upper and lower cards is set to 0, and the game stage is set to {@code WAITING}. + */ public CurrentState(){ this.player = null; this.slot = null; @@ -78,6 +171,15 @@ public class CurrentState { // endregion constructors // region Functions + + /** + * Updates the current player and slot. + * If the specified slot is {@code null}, the numbers of upper and lower cards are both set to 0. + * Otherwise, the numbers of upper and lower cards are updated using the values of the specified slot. + * + * @param player the new current player. + * @param slot the new current slot. + */ public void PlayerUpdate(Player player, Slot slot){ this.player = player; this.slot = slot; From 4b732139ea62d7056fb7d5c6ae2d455542296dd5 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sun, 19 Apr 2026 16:07:05 +0200 Subject: [PATCH 12/14] Add: Added Partial Logic For Client-Server Serialized Message Handling. --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 3 +- .../Network/TCP/Server/ClientHandler.java | 32 ++++++++++--------- .../gc14/Network/TCP/Server/TCPServer.java | 23 +++++++++++-- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index 4091090..98507e0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -14,10 +14,11 @@ import it.polimi.ingsw.gc14.Model.Orders.Order4; import it.polimi.ingsw.gc14.Model.Orders.Order5; import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; +import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; -public class Game { +public class Game implements Serializable { private ArrayList playersList; private CurrentState currentState; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index 7000c31..6ac06de 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -8,11 +8,15 @@ import java.util.List; public class ClientHandler implements Runnable { private Socket clientSocket; - BufferedReader in = null; - PrintWriter out = null; + public ObjectInputStream in = null; + public ObjectOutputStream out = null; List clientHandlers; GameController gameController; + public Socket getClientSocket() { + return clientSocket; + } + public ClientHandler(Socket clientSocket, List clientHandlers, GameController gameController) { this.clientSocket = clientSocket; this.clientHandlers = clientHandlers; @@ -25,21 +29,11 @@ public class ClientHandler implements Runnable { } private void clientLoop(){ - try{ - in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - synchronized(out){ - out = new PrintWriter(clientSocket.getOutputStream(), true); - } - } - catch(IOException e){ - e.printStackTrace(); - } String s = ""; try{ while ((s = in.readLine()) != null) { synchronized(out){ - System.out.println(s); - out.println(s.toUpperCase()); + //do something } } } @@ -48,9 +42,17 @@ public class ClientHandler implements Runnable { } } - public void notifyEvent(Object event) { + public void notifyEvent(Object event){ synchronized(out){ - out.println(event.toString()); + try{ + out = new ObjectOutputStream(clientSocket.getOutputStream()); + out.writeObject(gameController.getModel()); + } + catch(IOException e){ + e.printStackTrace(); + } } } } + + diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java index 7cafb9e..0614f7b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java @@ -2,7 +2,7 @@ package it.polimi.ingsw.gc14.Network.TCP.Server; import it.polimi.ingsw.gc14.Controller.GameController; -import java.io.IOException; +import java.io.*; import java.net.*; import java.util.ArrayList; import java.util.List; @@ -15,6 +15,8 @@ public class TCPServer { private List clientHandlers; + + private int getConnectedPlayers(){ return ConnectedPlayers; } @@ -46,10 +48,27 @@ public class TCPServer { e.printStackTrace(); } - System.out.println("Accepted"); + System.out.println("Accepted player: " + gameController.getModel().getPlayerByUsername(clientSocket.getInetAddress().toString())); + ConnectedPlayers++; ClientHandler clientHandler = new ClientHandler(clientSocket, clientHandlers, gameController); clientHandlers.add(clientHandler); + + //Sending model to clients + if(ConnectedPlayers == gameController.getModel().getNPlayers()){ + for (ClientHandler handler : clientHandlers) { + try { + synchronized(handler.out){ + ObjectOutputStream socketTx = new ObjectOutputStream(handler.getClientSocket().getOutputStream()); + socketTx.writeObject(gameController.getModel()); + } + } + catch(IOException e){ + e.printStackTrace(); + } + } + } + Thread t = new Thread(clientHandler); t.start(); } From d14c97c1d4308f252a5d1a4d187bfeefba05865b Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sun, 19 Apr 2026 16:40:25 +0200 Subject: [PATCH 13/14] Add: Finished Implementation For TCP Server. --- .../Network/TCP/Server/ClientHandler.java | 28 +++++++++++++++---- .../gc14/Network/TCP/Server/TCPServer.java | 4 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index 6ac06de..1a3b94f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -1,6 +1,8 @@ package it.polimi.ingsw.gc14.Network.TCP.Server; import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; import java.io.*; import java.net.*; @@ -8,10 +10,12 @@ import java.util.List; public class ClientHandler implements Runnable { private Socket clientSocket; + private TCPServer server; public ObjectInputStream in = null; public ObjectOutputStream out = null; List clientHandlers; GameController gameController; + private EventType eventType; public Socket getClientSocket() { return clientSocket; @@ -29,12 +33,26 @@ public class ClientHandler implements Runnable { } private void clientLoop(){ - String s = ""; try{ - while ((s = in.readLine()) != null) { - synchronized(out){ - //do something + NetworkEvent input = null; + synchronized(in){ + in = new ObjectInputStream(clientSocket.getInputStream()); + } + while(true){ + try{ + input = (NetworkEvent)(in.readObject()); + if(input.apply(gameController)){ + server.broadcastUpdate(input); + } } + catch(java.io.IOException e){ + e.printStackTrace(); + } + catch (ClassNotFoundException e){ + throw new RuntimeException(e); + } + + } } catch (IOException e) { @@ -42,7 +60,7 @@ public class ClientHandler implements Runnable { } } - public void notifyEvent(Object event){ + public void notifyEvent(NetworkEvent event){ synchronized(out){ try{ out = new ObjectOutputStream(clientSocket.getOutputStream()); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java index 0614f7b..38fafe1 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java @@ -1,6 +1,7 @@ package it.polimi.ingsw.gc14.Network.TCP.Server; import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; import java.io.*; import java.net.*; @@ -43,6 +44,7 @@ public class TCPServer { clientSocket.close(); System.out.println("Invalid parameters. Connection terminated.\n"); } + // gestione di ADD_PLAYER } catch (IOException e){ e.printStackTrace(); @@ -79,7 +81,7 @@ public class TCPServer { this.gameController = gameController; } - public void broadcastUpdate(Object event){ + public void broadcastUpdate(NetworkEvent event){ clientHandlers.forEach((x) -> x.notifyEvent(event)); } } From 47ef913a432ce8e5b4ee16dd701026d8d4ac529c Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sun, 19 Apr 2026 16:57:51 +0200 Subject: [PATCH 14/14] Add: Added Event Methods For Client-Server Event Execution. --- .../NetworkEvents/DrawLowerBuildingCard.java | 29 +++++++++++++++++++ .../TCP/NetworkEvents/DrawLowerTribeCard.java | 29 +++++++++++++++++++ .../NetworkEvents/DrawUpperBuildingCard.java | 29 +++++++++++++++++++ .../TCP/NetworkEvents/DrawUpperTribeCard.java | 29 +++++++++++++++++++ .../PickOptionalBuildingCard.java | 29 +++++++++++++++++++ .../NetworkEvents/PickOptionalTribeCard.java | 29 +++++++++++++++++++ .../Network/TCP/NetworkEvents/SlotChoice.java | 29 +++++++++++++++++++ 7 files changed, 203 insertions(+) create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerBuildingCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerTribeCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperBuildingCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperTribeCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalBuildingCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalTribeCard.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/SlotChoice.java diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerBuildingCard.java new file mode 100644 index 0000000..8e7fc80 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerBuildingCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public DrawLowerBuildingCard(String username, int pos){ + this.username = username; + this.eventType = EventType.DRAW_LOWER_BUILD; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.drawLowerBuildingCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerTribeCard.java new file mode 100644 index 0000000..17848d1 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawLowerTribeCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class DrawLowerTribeCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public DrawLowerTribeCard(String username, int pos){ + this.username = username; + this.eventType = EventType.DRAW_LOWER_TRIBE; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.drawLowerTribeCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperBuildingCard.java new file mode 100644 index 0000000..a39bbb1 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperBuildingCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public DrawUpperBuildingCard(String username, int pos){ + this.username = username; + this.eventType = EventType.DRAW_UPPER_BUILD; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.drawUpperBuildingCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperTribeCard.java new file mode 100644 index 0000000..6f261ed --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/DrawUpperTribeCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class DrawUpperTribeCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public DrawUpperTribeCard(String username, int pos){ + this.username = username; + this.eventType = EventType.DRAW_UPPER_TRIBE; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.drawUpperTribeCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalBuildingCard.java new file mode 100644 index 0000000..1946be3 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalBuildingCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public PickOptionalBuildingCard(String username, int pos){ + this.username = username; + this.eventType = EventType.PICK_OPTIONAL_BUILD; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.pickOptionalBuildingCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalTribeCard.java new file mode 100644 index 0000000..5620976 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/PickOptionalTribeCard.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class PickOptionalTribeCard extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public PickOptionalTribeCard(String username, int pos){ + this.username = username; + this.eventType = EventType.PICK_OPTIONAL_TRIBE; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.pickOptionalTribeCard(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/SlotChoice.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/SlotChoice.java new file mode 100644 index 0000000..2c6caa1 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/NetworkEvents/SlotChoice.java @@ -0,0 +1,29 @@ +package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.TCP.EventType; +import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +public class SlotChoice extends NetworkEvent implements Serializable{ + private String username; + private EventType eventType; + private int pos; + + public SlotChoice(String username, int pos){ + this.username = username; + this.eventType = EventType.SLOT_CHOICE; + this.pos = pos; + } + + @Override + public boolean apply(GameController gameController){ + return gameController.slotChoice(username, pos); + } + + public String apply(IView gameController){ + return gameController.toString(); + } +}