From 39e06886a331f3758c6d656199852a575783d3e7 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:01:45 +0200 Subject: [PATCH 01/21] Fixed: No Drawable Logic --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 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 add7416..42b5261 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -318,6 +318,44 @@ public class Game implements Serializable { return true; } + public boolean SkipUpperDrawing(Player player) { + if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + { + return false; + } + if(!player.equals(currentState.getCurrentPlayer())) + { + return false; + } + if(currentState.getNUpper() <1) + return false; + if(hasDrawableUp()) + return false; + currentState.UpperDrawn(); + if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(getUpperListBuilding().isEmpty()))) + nextPlayerSetup(); + return true; + } + + public boolean SkipLowerDrawing(Player player) { + if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + { + return false; + } + if(!player.equals(currentState.getCurrentPlayer())) + { + return false; + } + if(currentState.getNUpper() <1) + return false; + if(hasDrawableDown()) + return false; + currentState.LowerDrawn(); + if((currentState.getNLower() ==0 ||( getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp()&&getUpperListBuilding().isEmpty()))) + nextPlayerSetup(); + return true; + } + /** * Attempts to draw the lower tribe card at the specified index for the specified player. * The operation succeeds only if the index is valid, the game stage is {@code RESOLVING_ACTIONS}, @@ -569,7 +607,7 @@ public class Game implements Serializable { for (Slot s : slotMap.keySet()) { if (slotMap.get(s) != null) { currentState.PlayerUpdate(slotMap.get(s), s); - if(!((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))) + if(!((currentState.getNLower() ==0 ||(!hasDrawableDown() && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().size()==0)))) break; else { @@ -587,7 +625,7 @@ public class Game implements Serializable { for (Slot s : slotMap.keySet()) { if (slotMap.get(s) != null) { currentState.PlayerUpdate(slotMap.get(s), s); - if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0))) { + if((currentState.getNLower() ==0 ||(!hasDrawableDown() && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( !hasDrawableUp() && getUpperListBuilding().size()==0))) { orderLogicCard.push(currentState.getCurrentPlayer()); slotMap.put(currentState.getSlot(), null); @@ -661,7 +699,14 @@ public class Game implements Serializable { } } - + private boolean hasDrawableUp() + { + return getUpperListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0; + } + private boolean hasDrawableDown() + { + return getLowerListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0; + } /** * Resolves all pending event cards if the current game stage is {@code RESOLVING_EVENT}. * All pending events are activated on the player list. From d608aaf098369590e8d3fcaa6316b7c4d199c6a8 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:03:51 +0200 Subject: [PATCH 02/21] Added: SkipUpper and SkipLower Controller Move --- .../ingsw/gc14/Controller/GameController.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 dd6b120..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. * From 09ee692f900900c0e8ce2ea02ac1c54d54c86c68 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:15:55 +0200 Subject: [PATCH 03/21] Added: SkipUpper and Lower -> TUI,NETWORK --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 20 +++++++++------- .../gc14/Controller/ClientController.java | 7 ++++++ .../polimi/ingsw/gc14/Network/EventType.java | 2 ++ .../gc14/Network/NetworkEvents/SkipLower.java | 23 ++++++++++++++++++ .../gc14/Network/NetworkEvents/SkipUpper.java | 24 +++++++++++++++++++ .../it/polimi/ingsw/gc14/View/TUI/TUI.java | 18 +++++++------- 6 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 06d0fdf..6d2d854 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -72,7 +72,7 @@ public class ClientLauncherTUI { private void getInput(Scanner scanner, ClientController controller, String username) { String action = scanner.next(); int pos=-1; - if(!action.equals("8")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")&&!action.equals("D")) { + 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:"); @@ -84,14 +84,16 @@ public class ClientLauncherTUI { } } switch(action) { - case "1" -> controller.slotChoice(username, pos); - case "2" -> controller.drawUpperBuildingCard(username, pos); - case "3" -> controller.drawUpperTribeCard(username, pos); - case "4" -> controller.drawLowerBuildingCard(username, pos); - case "5" -> controller.drawLowerTribeCard(username, pos); - case "6" -> controller.pickOptionalTribeCard(username, pos); - case "7" -> controller.pickOptionalBuildingCard(username, pos); - case "8" -> controller.noOptionalCard(username); + case "0" -> controller.slotChoice(username, pos); + case "1" -> controller.drawUpperBuildingCard(username, pos); + case "2" -> controller.drawUpperTribeCard(username, pos); + case "3" -> controller.drawLowerBuildingCard(username, pos); + case "4" -> controller.drawLowerTribeCard(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" -> view.fullRender(); case "B" -> view.renderBoard(); case "C" -> view.renderPlayer(); 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 1b96cd4..c6b64bf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -80,6 +80,13 @@ public class ClientController { client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); } + public void skipUpper(String playerUsername) { + client.doEvent(new SkipUpper(playerUsername)); + } + + public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));} + + /** * Attempts to pick an optional tribe card for the specified player from the specified position. * diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java index 0f8f03c..33d5efb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java @@ -9,5 +9,7 @@ public enum EventType { DRAW_LOWER_BUILD, PICK_OPTIONAL_TRIBE, PICK_OPTIONAL_BUILD, + SKIP_UPPER, + SKIP_LOWER, NO_OPTIONAL_CARD } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java new file mode 100644 index 0000000..e962398 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java @@ -0,0 +1,23 @@ +package it.polimi.ingsw.gc14.Network.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.EventType; +import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +//TODO javadoc +public class SkipLower extends NetworkEvent implements Serializable{ + //TODO javadoc + public SkipLower(String username){ + super(username, EventType.SKIP_LOWER, false); + } + + //TODO javadoc + @Override + public boolean apply(GameController gameController){ + return gameController.SkipLowerDrawing(username); + } + +} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java new file mode 100644 index 0000000..3faee82 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java @@ -0,0 +1,24 @@ +package it.polimi.ingsw.gc14.Network.NetworkEvents; + +import it.polimi.ingsw.gc14.Controller.GameController; +import it.polimi.ingsw.gc14.Network.EventType; +import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.View.IView; + +import java.io.Serializable; + +//TODO javadoc +public class SkipUpper extends NetworkEvent implements Serializable{ + + //TODO javadoc + public SkipUpper(String username){ + super(username, EventType.SKIP_UPPER, false); + } + + //TODO javadoc + @Override + public boolean apply(GameController gameController){ + return gameController.SkipUpperDrawing(username); + } + +} diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index 1b0ca3f..e97f1ad 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -100,14 +100,16 @@ public class TUI implements IView { { var table=new AsciiTable(BorderStyle.ROUNDED,2); table.addHeader( "Menu Options","Render Options"); - table.addRow( List.of("1-SlotChoice(pos)","A-Full Render")); - table.addRow(List.of("2-DrawUpperTribe(pos)","B-Board Render")); - table.addRow(List.of("3-DrawUpperBuilding(pos)","C-Players Render")); - table.addRow(List.of("4-DrawLowerTribe(pos)","")); - table.addRow(List.of("5-DrawLowerBuilding(pos)","")); - table.addRow(List.of("6-PickOptionalTribe(pos)","")); - table.addRow(List.of("7-PickOptionalBuilding(pos)","")); - table.addRow(List.of("8-NoOptional","")); + table.addRow( List.of("0-SlotChoice(pos)","A-Full Render")); + table.addRow(List.of("1-DrawUpperTribe(pos)","B-Board Render")); + table.addRow(List.of("2-DrawUpperBuilding(pos)","C-Players Render")); + table.addRow(List.of("3-DrawLowerTribe(pos)","")); + table.addRow(List.of("4-DrawLowerBuilding(pos)","")); + table.addRow(List.of("5-PickOptionalTribe(pos)","")); + table.addRow(List.of("6-PickOptionalBuilding(pos)","")); + table.addRow(List.of("7-NoOptional","")); + table.addRow(List.of("8-NoUpperCard","")); + table.addRow(List.of("9-NoLowerCard","")); return table.build(); } From 215e75aac68f4fe4b48e210bc276d26c4b56c7ee Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:33:55 +0200 Subject: [PATCH 04/21] Fixed: hasDrawable in Game --- src/main/java/it/polimi/ingsw/gc14/Model/Game.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 42b5261..7c9afcf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -701,11 +701,11 @@ public class Game implements Serializable { } private boolean hasDrawableUp() { - return getUpperListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0; + return getUpperListTribeCards().stream().filter(x-> !x.IsEventCard()).count()!=0; } private boolean hasDrawableDown() { - return getLowerListTribeCards().stream().filter(x-> !x.IsEventCard()).count()==0; + return getLowerListTribeCards().stream().filter(x-> !x.IsEventCard()).count()!=0; } /** * Resolves all pending event cards if the current game stage is {@code RESOLVING_EVENT}. From a15a40fddb085456bf1db46f792713c73a08a8f0 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 15:42:34 +0200 Subject: [PATCH 05/21] Fix: Hunter.java Now Correctly Adds 1 Food For Each Hunter Card In The Deck (If The Given Card Has An Icon). --- .../ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java | 3 +++ 1 file changed, 3 insertions(+) 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()); + } } } From 1a7100a35afd3508823ecb836e81cccf37c6f889 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 15:52:09 +0200 Subject: [PATCH 06/21] Fix: Fixed "toString" & "insert" Methods In HunterTest.java. --- .../TribeCards/Characters/HunterTest.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java index 7917289..9da7e97 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java @@ -21,8 +21,10 @@ class HunterTest { String s = h.toString(); assertNotNull(s); - assertTrue(s.contains(CharacterType.HUNTER.toString())); - assertTrue(s.contains("Icon: true")); + assertTrue(s.contains(" I")); + + Hunter h2 = new Hunter(3, false); + assertTrue(!h2.toString().contains("I")); } @Test @@ -55,6 +57,20 @@ class HunterTest { assertEquals(2, p.hunters.size()); assertTrue(p.hunters.contains(h2)); + + Player p2 = new Player("test2"); + Hunter h3 = new Hunter(1, true); + + assertEquals(0, p2.getFoodValue()); + h.insert(p2); + + assertEquals(1, p2.getFoodValue()); + h2.insert(p2); + + assertEquals(1, p2.getFoodValue()); + h3.insert(p2); + + assertEquals(4, p2.getFoodValue()); } @Test From 28d371b87fcf6a081c564a264b6208077032390d Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 16:07:43 +0200 Subject: [PATCH 07/21] Fix: Fixed "toString" Method In Building11Test.java. --- .../Building/Effects/Building11Test.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java index 620233a..a3d907a 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java @@ -96,7 +96,7 @@ class Building11Test { p3.addFood(b3.getPrice()); assertTrue(b3.buy(p3)); p4.addFood(b3.getPrice()); - assertEquals(false, b3.buy(p4)); + assertFalse(b3.buy(p4)); } @@ -112,22 +112,33 @@ class Building11Test { @Test @DisplayName("toString") void testToString(){ - Building11 b11 = new Building11(1,2,3, CharacterType.INVENTOR, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b11.toString()); + int era = 1; + int price = 1; + int prestigeValue = 3; + CharacterType ct = CharacterType.ARTIST; + int pm = 5; - b11 = new Building11(1,2,3, CharacterType.BUILDER, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b11.toString()); + Building11 b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); - b11 = new Building11(1,2,3, CharacterType.GATHERER, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b11.toString()); + ct = CharacterType.BUILDER; + b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); - b11 = new Building11(1,2,3, CharacterType.ARTIST, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b11.toString()); + ct = CharacterType.GATHERER; + b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); - b11 = new Building11(1,2,3, CharacterType.SHAMAN, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b11.toString()); + ct = CharacterType.HUNTER; + b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); - b11 = new Building11(1,2,3, CharacterType.HUNTER, 1); - assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b11.toString()); + ct = CharacterType.INVENTOR; + b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); + + ct = CharacterType.SHAMAN; + b11 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); } } \ No newline at end of file From 670b4fcf84edd34649030a6c5c3c8c663d9017a4 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 16:15:10 +0200 Subject: [PATCH 08/21] Fix: SkipLower(Game.java) --- src/main/java/it/polimi/ingsw/gc14/Model/Game.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7c9afcf..15f09ad 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -346,7 +346,7 @@ public class Game implements Serializable { { return false; } - if(currentState.getNUpper() <1) + if(currentState.getNLower() <1) return false; if(hasDrawableDown()) return false; From e2c48ae59d04709c1cd6f0b4c1b2ec29f0d84546 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 17:06:16 +0200 Subject: [PATCH 09/21] Fix: ClientContrioller JavaDOC --- .../gc14/Controller/ClientController.java | 129 +++++++++++------- 1 file changed, 79 insertions(+), 50 deletions(-) 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 c6b64bf..b3cc2fc 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -7,127 +7,156 @@ 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; + + /** + * Constructor of the class. Initializes all attributes. + * @param view The client view to set (either TUI or GUI). + */ public ClientController(IView view) { this.view = view; this.localController = new GameController(); + this.client = null; } + + + /** + * Method to set the network client. + * @param client The client to sei (either TCP or RMI) + */ public void setClient(IClient client) { this.client = client; } + + + /** + * Method to set the model in the Game Controller and in the view. + * @param model The model to set + */ public void setModel(Game model) { localController.setModel(model); view.update(localController.getModel()); } + + /** + * Method to show an error in the view. + * @param message The error message to show in the view + */ 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. + * Used to draw a tribe card from the upper list. + * Create a NetworkEvent and then sends it through the network client. + * @param playerUsername The name of the player who requested to perform the action + * @param pos 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. + * Used to draw a tribe card from the lower list. + * Create a NetworkEvent and then sends it through the network client. + * @param playerUsername The name of the player who requested to perform the action + * @param pos 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. + * Used to draw a building card from the upper list. + * Create a NetworkEvent and then sends it through the network client. + * @param playerUsername The name of the player who requested to perform the action + * @param pos 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. + * Used to draw a building card from the lower list. + * Create a NetworkEvent and then sends it through the network client. + * @param playerUsername The name of the player who requested to perform the action + * @param pos Index of the card to draw */ public void drawLowerBuildingCard(String playerUsername,int pos) { client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); } + + /** + * Used to skip the drawing action from the upper list. + * Available only when the upper list is empty (or the player can't draw any card). + * @param playerUsername The name of the player who requested to perform the action + */ public void skipUpper(String playerUsername) { client.doEvent(new SkipUpper(playerUsername)); } + + /** + * Used to skip the drawing action from the lower list. + * Available only when the lower list is empty (or the player can't draw any card). + * @param playerUsername The name of the player who requested to perform the action + */ public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));} /** - * 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. + * 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 who requested to perform the action + * @param pos 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 who requested to perform the action + * @param pos Index of the card to draw */ public void pickOptionalBuildingCard(String playerUsername,int pos) { client.doEvent(new PickOptionalBuildingCard(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. + * 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 who requested to perform the action */ public void noOptionalCard(String playerUsername) { client.doEvent(new NoOptionalCard(playerUsername)); } + /** - * 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 sperform the slot choiche action for the specified player at the specified position. + * @param playerUsername The name of the player who requested to perform the action + * @param pos Index of the selected slot */ public void slotChoice(String playerUsername,int pos) { client.doEvent(new SlotChoice(playerUsername,pos)); From b8c6c86d9261c969c8b8e705f422b3b5ef6c18bc Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 17:19:16 +0200 Subject: [PATCH 10/21] Fix: ClientContrioller JavaDOC more fluid --- .../gc14/Controller/ClientController.java | 80 ++++++++++--------- 1 file changed, 42 insertions(+), 38 deletions(-) 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 b3cc2fc..144435f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -24,8 +24,9 @@ public class ClientController { /** - * Constructor of the class. Initializes all attributes. - * @param view The client view to set (either TUI or GUI). + * Constructs the ClientController. + * Initializes all attributes. + * @param view the client view (either TUI or GUI) */ public ClientController(IView view) { this.view = view; @@ -35,8 +36,8 @@ public class ClientController { /** - * Method to set the network client. - * @param client The client to sei (either TCP or RMI) + * Sets the network client. + * @param client the client to set (either TCP or RMI) */ public void setClient(IClient client) { this.client = client; @@ -44,8 +45,8 @@ public class ClientController { /** - * Method to set the model in the Game Controller and in the view. - * @param model The model to set + * Sets the model in the GameController and updates the view. + * @param model the model to set */ public void setModel(Game model) { localController.setModel(model); @@ -54,8 +55,8 @@ public class ClientController { /** - * Method to show an error in the view. - * @param message The error message to show in the view + * Displays an error message in the view. + * @param message the error message to display */ public void onError(String message) { view.showError(message); @@ -63,10 +64,10 @@ public class ClientController { /** - * Used to draw a tribe card from the upper list. - * Create a NetworkEvent and then sends it through the network client. - * @param playerUsername The name of the player who requested to perform the action - * @param pos Index of the card to draw + * 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) { client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); @@ -74,30 +75,32 @@ public class ClientController { /** - * Used to draw a tribe card from the lower list. - * Create a NetworkEvent and then sends it through the network client. - * @param playerUsername The name of the player who requested to perform the action - * @param pos Index of the card to draw + * 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)); } + /** - * Used to draw a building card from the upper list. - * Create a NetworkEvent and then sends it through the network client. - * @param playerUsername The name of the player who requested to perform the action - * @param pos Index of the card to draw + * 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)); } + /** - * Used to draw a building card from the lower list. - * Create a NetworkEvent and then sends it through the network client. - * @param playerUsername The name of the player who requested to perform the action - * @param pos Index of the card to draw + * 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)); @@ -105,9 +108,9 @@ public class ClientController { /** - * Used to skip the drawing action from the upper list. - * Available only when the upper list is empty (or the player can't draw any card). - * @param playerUsername The name of the player who requested to perform the action + * 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)); @@ -115,9 +118,9 @@ public class ClientController { /** - * Used to skip the drawing action from the lower list. - * Available only when the lower list is empty (or the player can't draw any card). - * @param playerUsername The name of the player who requested to perform the action + * 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));} @@ -125,8 +128,8 @@ public class ClientController { /** * 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 who requested to perform the action - * @param pos Index of the card to draw + * @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)); @@ -136,17 +139,18 @@ public class ClientController { /** * 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 who requested to perform the action - * @param pos Index of the card to draw + * @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)); } + /** * 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 who requested to perform the action + * @param playerUsername the name of the player performing the action */ public void noOptionalCard(String playerUsername) { client.doEvent(new NoOptionalCard(playerUsername)); @@ -154,9 +158,9 @@ public class ClientController { /** - * Used to sperform the slot choiche action for the specified player at the specified position. - * @param playerUsername The name of the player who requested to perform the action - * @param pos Index of the selected slot + * 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)); From 06162a243fdf7af0b4504c2094d293971f387479 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 17:29:40 +0200 Subject: [PATCH 11/21] Add: toString methods JavaDOC --- .../polimi/ingsw/gc14/Model/Cards/Building/EffectType.java | 2 +- .../ingsw/gc14/Model/Cards/TribeCards/CharacterType.java | 2 +- .../it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java | 2 +- src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java | 6 +++++- src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order3.java | 5 +++++ src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order4.java | 5 +++++ src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order5.java | 5 +++++ .../java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayer.java | 4 ++++ 8 files changed, 27 insertions(+), 4 deletions(-) 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/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/GamePackage/GameStages.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java index b001fe3..97e8fa3 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java @@ -1,5 +1,5 @@ package it.polimi.ingsw.gc14.Model.GamePackage; public enum GameStages { - WAITING,SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT,ENDING,ENDED + WAITING, SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT, ENDING, ENDED } diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java index 589ac3d..ced283e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java @@ -52,10 +52,14 @@ public class Order2 extends OrderLogicCard { } } } + + /** + * Creates the TURN ORDER box of the TUI. + * @return the string containing the box + */ @Override public String toString() { - var table = new AsciiTable(BorderStyle.UNICODE, 2); List stringUp=new ArrayList<>(); for(int i=0;i<2;i++) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order3.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order3.java index 6cc6b57..b3e1247 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order3.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order3.java @@ -53,6 +53,11 @@ public class Order3 extends OrderLogicCard { } } } + + /** + * Creates the TURN ORDER box of the TUI. + * @return the string containing the box + */ @Override public String toString() { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order4.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order4.java index e4a8bed..20b573b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order4.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order4.java @@ -60,6 +60,11 @@ public class Order4 extends OrderLogicCard { } } } + + /** + * Creates the TURN ORDER box of the TUI. + * @return the string containing the box + */ @Override public String toString() { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order5.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order5.java index c435ae2..e8ea88f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order5.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order5.java @@ -61,6 +61,11 @@ public class Order5 extends OrderLogicCard { } } } + + /** + * Creates the TURN ORDER box of the TUI. + * @return the string containing the box + */ @Override public String toString() { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayer.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayer.java index cb3034b..8d3b299 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayer.java @@ -17,6 +17,10 @@ public class OrderPlayer implements Serializable { this.player=player; this.played=played; } + + /** + * @return the string containing the username and whether it played or not. + */ @Override public String toString() { return player.getUserName()+" "+played; From ec4fe1cf441a5a71042849800b910233142b9cd5 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 18:36:26 +0200 Subject: [PATCH 12/21] Add: JavaDOC to all NetworkEvent --- .../ingsw/gc14/Network/NetworkEvent.java | 47 ++++++++++++++----- .../gc14/Network/NetworkEvents/AddPlayer.java | 22 +++++++-- .../NetworkEvents/DrawLowerBuildingCard.java | 18 +++++-- .../NetworkEvents/DrawLowerTribeCard.java | 18 +++++-- .../NetworkEvents/DrawUpperBuildingCard.java | 19 ++++++-- .../NetworkEvents/DrawUpperTribeCard.java | 19 ++++++-- .../Network/NetworkEvents/NoOptionalCard.java | 16 +++++-- .../PickOptionalBuildingCard.java | 19 ++++++-- .../NetworkEvents/PickOptionalTribeCard.java | 20 ++++++-- .../gc14/Network/NetworkEvents/SkipLower.java | 16 +++++-- .../gc14/Network/NetworkEvents/SkipUpper.java | 15 ++++-- .../Network/NetworkEvents/SlotChoice.java | 19 ++++++-- .../gc14/Network/RMI/Client/RMIClient.java | 1 + 13 files changed, 196 insertions(+), 53 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvent.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvent.java index e38e7a3..6d6a159 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvent.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvent.java @@ -4,39 +4,60 @@ import it.polimi.ingsw.gc14.Controller.GameController; import java.io.Serializable; -//TODO javadoc +/** + * Represents an event sent over the network + */ public abstract class NetworkEvent implements Serializable { - //TODO javadoc + /** Username of the player requesting the event */ protected String username; - //TODO javadoc + /** + * @return the username of the player requesting the event + */ public String getUsername() { return username; } - //TODO javadoc + /** EventType of the event */ protected EventType eventType; - //TODO javadoc + /** + * @return the type of the event + */ public EventType getEventType() {return eventType;} - //TODO javadoc + /** Flag signaling whether the event could not be applied to the server model */ protected boolean isError; - //TODO javadoc + /** + * @return the flag signaling whether the event could be applied to the server model + */ public boolean getIsError() {return isError;} - //TODO javadoc + /** + * Set the isError flag. + * @param isError the value to set + */ public void setIsError(boolean isError) {this.isError = isError;} - //TODO javadoc + + /** + * Class constructor. + * Initializes all attributes. + * @param username the username of the player requesting the event + * @param eventType the type of the event + * @param isError the flag signaling if the event could be applied to the server model + */ protected NetworkEvent(String username, EventType eventType, boolean isError) { this.username = username; this.eventType = eventType; this.isError = isError; } - //TODO javadoc + + /** + * @return a string describing the name of the event and whether it is an error or not + */ @Override public String toString() { if(isError) { @@ -46,6 +67,10 @@ public abstract class NetworkEvent implements Serializable { } } - //TODO javadoc + /** + * The method to apply the current event to the specified Game Controller. + * @param gameController the Game Controller on which to apply the event + * @return true if the event could be applied; false otherwise + */ public abstract boolean apply(GameController gameController); } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/AddPlayer.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/AddPlayer.java index 14acd88..607d3e9 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/AddPlayer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/AddPlayer.java @@ -7,23 +7,35 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to add a player. + */ public class AddPlayer extends NetworkEvent implements Serializable { - //TODO javadoc + /** Number of proposed players to add to the match */ private int proposedNPlayer; - //TODO javadoc + /** + * @return the number of proposed players to add to the match + */ public int getProposedNPlayer() { return proposedNPlayer; } - //TODO javadoc + /** + * Class constructor. + * Initializes all the attributes. + * @param username the name of the player requesting the event + * @param proposedNPlayer the number of proposed players to add to the match + */ public AddPlayer(String username, int proposedNPlayer) { super(username, EventType.ADD_PLAYER, false); this.proposedNPlayer = proposedNPlayer; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could be added to the match, false otherwise + */ @Override public boolean apply(GameController gameController) { diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerBuildingCard.java index 91b67af..b2499cf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerBuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerBuildingCard.java @@ -7,18 +7,28 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to draw a building card from the lower card list. + */ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable{ - //TODO javadoc + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public DrawLowerBuildingCard(String username, int pos){ super(username, EventType.DRAW_LOWER_BUILD, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.drawLowerBuildingCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerTribeCard.java index 0dda4d1..d06c34e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerTribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawLowerTribeCard.java @@ -7,17 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; +/** + * NetworkEvent to draw a tribe card from the lower card list. + */ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public DrawLowerTribeCard(String username, int pos){ super(username, EventType.DRAW_LOWER_TRIBE, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.drawLowerTribeCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperBuildingCard.java index 077bc74..1da744e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperBuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperBuildingCard.java @@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to draw a building card from the upper card list. + */ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public DrawUpperBuildingCard(String username, int pos){ super(username, EventType.DRAW_UPPER_BUILD, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.drawUpperBuildingCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperTribeCard.java index 8fcb004..7794b10 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperTribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/DrawUpperTribeCard.java @@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to draw a tribe card from the upper card list. + */ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public DrawUpperTribeCard(String username, int pos){ super(username, EventType.DRAW_UPPER_TRIBE, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.drawUpperTribeCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java index 9791962..6e5e328 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java @@ -7,14 +7,24 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to avoid drawing a card from the upper list (see the effect of Building 12) + */ public class NoOptionalCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + */ public NoOptionalCard(String username){ super(username, EventType.NO_OPTIONAL_CARD, false); } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.noOptionalCard(username); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalBuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalBuildingCard.java index 1704082..dc3a420 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalBuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalBuildingCard.java @@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to draw a building card from the upper list (see the effect of Building 12) + */ public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public PickOptionalBuildingCard(String username, int pos){ super(username, EventType.PICK_OPTIONAL_BUILD, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.pickOptionalBuildingCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalTribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalTribeCard.java index 0262b7f..8da74be 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalTribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/PickOptionalTribeCard.java @@ -7,19 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc - +/** + * NetworkEvent to draw a tribe card from the upper list (see the effect of Building 12) + */ public class PickOptionalTribeCard extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initialized all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public PickOptionalTribeCard(String username, int pos){ super(username, EventType.PICK_OPTIONAL_TRIBE, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.pickOptionalTribeCard(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java index e962398..8001cb3 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipLower.java @@ -7,14 +7,24 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to avoid drawing a card from the lower card list + */ public class SkipLower extends NetworkEvent implements Serializable{ - //TODO javadoc + + /** + * Class constructor. + * Initializes all the attributes. + * @param username the name of the player requesting the event + */ public SkipLower(String username){ super(username, EventType.SKIP_LOWER, false); } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.SkipLowerDrawing(username); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java index 3faee82..2dccaba 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SkipUpper.java @@ -7,15 +7,24 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to avoid drawing a card from the upper card list + */ public class SkipUpper extends NetworkEvent implements Serializable{ - //TODO javadoc + /** + * Class constructor. + * Initializes all the attributes. + * @param username the name of the player requesting the event + */ public SkipUpper(String username){ super(username, EventType.SKIP_UPPER, false); } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController){ return gameController.SkipUpperDrawing(username); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SlotChoice.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SlotChoice.java index 189e3ab..6de4ea0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SlotChoice.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/SlotChoice.java @@ -7,18 +7,29 @@ import it.polimi.ingsw.gc14.View.IView; import java.io.Serializable; -//TODO javadoc +/** + * NetworkEvent to select a slot where to place the player totem. + */ public class SlotChoice extends NetworkEvent implements Serializable { - //TODO javadoc + + /** Index of the card to draw */ private int pos; - //TODO javadoc + /** + * Class constructor. + * Initializes all the attributes. + * @param username the name of the player requesting the event + * @param pos the index of the card to draw + */ public SlotChoice(String username, int pos) { super(username, EventType.SLOT_CHOICE, false); this.pos = pos; } - //TODO javadoc + /** + * @param gameController the Game Controller on which to apply the event + * @return true if the player could draw the card, false otherwise + */ @Override public boolean apply(GameController gameController) { return gameController.slotChoice(username, pos); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 2d4c348..5cdbf37 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -8,6 +8,7 @@ import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback; import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; +import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; /** * Client RMI. Uses the methods exposed by the server RMI. From b68cbd8591c473830bd4d1508b75c5f8404e93ba Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 18:44:28 +0200 Subject: [PATCH 13/21] Fix: JavaDOC to Game --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 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 15f09ad..465da3e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -49,7 +49,8 @@ public class Game implements Serializable { } /** - * The current number of players. + * Returns the current number of players participating in the game. + * @return the current number of players. */ public int getCurrentPlayerNumber() { return playersList.size(); @@ -318,6 +319,18 @@ public class Game implements Serializable { return true; } + /** + * Skips the upper card draw for the specified player when no drawable cards are available. + * The operation succeeds only if the current game stage is {@code RESOLVING_ACTIONS}, + * the specified player is the current player, at least one upper draw is still available, + * and there are no drawable upper tribe cards (i.e. all remaining upper tribe cards are event cards) + * and no upper building cards that the player can afford. + * If successful, the upper draw counter is decremented. + * If both upper and lower draws become zero (or no cards remain drawable), the next player setup is triggered. + * + * @param player the player skipping the upper draw. + * @return {@code true} if the skip succeeds, {@code false} otherwise. + */ public boolean SkipUpperDrawing(Player player) { if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) { @@ -337,6 +350,18 @@ public class Game implements Serializable { return true; } + /** + * Skips the lower card draw for the specified player when no drawable cards are available. + * The operation succeeds only if the current game stage is {@code RESOLVING_ACTIONS}, + * the specified player is the current player, at least one lower draw is still available, + * and there are no drawable lower tribe cards (i.e. all remaining lower tribe cards are event cards) + * and no lower building cards that the player can afford. + * If successful, the lower draw counter is decremented. + * If both upper and lower draws become zero (or no cards remain drawable), the next player setup is triggered. + * + * @param player the player skipping the lower draw. + * @return {@code true} if the skip succeeds, {@code false} otherwise. + */ public boolean SkipLowerDrawing(Player player) { if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) { @@ -696,13 +721,32 @@ public class Game implements Serializable { } return; - +/** + * Checks whether there are any drawable lower tribe cards on the board, + * i.e. lower tribe cards that are not event cards. + * + * @return {@code true} if at least one non-event lower tribe card is available, {@code false} otherwise. + */ } } + + /** + * Checks whether there are any drawable upper tribe cards on the board, + * i.e. upper tribe cards that are not event cards. + * + * @return {@code true} if at least one non-event upper tribe card is available, {@code false} otherwise. + */ private boolean hasDrawableUp() { return getUpperListTribeCards().stream().filter(x-> !x.IsEventCard()).count()!=0; } + + /** + * Checks whether there are any drawable lower tribe cards on the board, + * i.e. lower tribe cards that are not event cards. + * + * @return {@code true} if at least one non-event lower tribe card is available, {@code false} otherwise. + */ private boolean hasDrawableDown() { return getLowerListTribeCards().stream().filter(x-> !x.IsEventCard()).count()!=0; @@ -817,6 +861,14 @@ public class Game implements Serializable { public String toString() { return PlayersStamp()+"\n"+BoardStamp()+"\n"; } + + /** + * Returns a string representation of all the players currently in the game, + * arranged side by side in pairs. + * If the number of players is odd, the last player is printed on its own line. + * + * @return {@code String} - a string representation of all the players. + */ public String PlayersStamp() { StringBuilder stringBuilder=new StringBuilder(); @@ -832,6 +884,14 @@ public class Game implements Serializable { } return stringBuilder.toString(); } + + /** + * Returns a string representation of the board, including the current state, + * the offer track with slot assignments, the upper and lower tribe card lists, + * and the upper and lower building card lists. + * + * @return {@code String} - a string representation of the board. + */ public String BoardStamp() { var offerTrack = new AsciiTable(BorderStyle.UNICODE, slotMap.size()); From df9bd77754bd0fece93badd9ed3075f21e634215 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:04:43 +0200 Subject: [PATCH 14/21] Fix: JavaDOC to Game --- .../polimi/ingsw/gc14/Model/DecksCreator.java | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) 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 params; // Object per gestire boolean e int misti } - //TODO javadoc + /** + * Internal data class representing the raw definition of a building card as loaded from a JSON file. + * Contains the effect ID, era, price, prestige value, and a list of additional parameters. + */ private static class BuildingCardDefinition { int effectId; int era; From 4a69e2c8dbd4ff732fce105f8041f19a840b2bb0 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:12:47 +0200 Subject: [PATCH 15/21] Add: JavaDOC to LimitedList --- .../it/polimi/ingsw/gc14/LimitedList.java | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) 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 From 4fdb99167eef6ed0df4d6be1d76beb845e7562e2 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:22:12 +0200 Subject: [PATCH 16/21] Add: JavaDOC to ClientLauncherTUI --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 91 ++++++++++++------- .../gc14/Network/RMI/Client/RMIClient.java | 2 +- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 6d2d854..03a7a6a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -4,16 +4,32 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent; 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.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 - TUI view; - public void main() throws InterruptedException { - view=new TUI(null); - ClientController controller = new ClientController(view); + /** + * 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 { + view = new TUI(null); + ClientController controller = new ClientController(view); Scanner scanner = new Scanner(System.in); System.out.println("Selezionare nome utente: "); String username = scanner.next(); @@ -22,9 +38,6 @@ public class ClientLauncherTUI { int proposedNumPlayers = scanner.nextInt(); System.out.println("Selezionare RMI[0] o TCP[1]: "); int networkType = scanner.nextInt(); - - - // RMI if (networkType == 0) { // Connect @@ -36,17 +49,10 @@ 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); @@ -57,33 +63,53 @@ 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) { String action = scanner.next(); - int pos=-1; - if(!action.equals("7")&&!action.equals("8")&&!action.equals("9")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")) { - try - { + int pos = -1; + 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) - { + } catch (Exception e) { System.out.println("ERROR: Invalid input(expected number)"); } } - switch(action) { + switch (action) { case "0" -> controller.slotChoice(username, pos); case "1" -> controller.drawUpperBuildingCard(username, pos); case "2" -> controller.drawUpperTribeCard(username, pos); @@ -97,8 +123,7 @@ public class ClientLauncherTUI { case "A" -> view.fullRender(); case "B" -> view.renderBoard(); case "C" -> view.renderPlayer(); + default -> {} } - - return; } } \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 5cdbf37..be92164 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -40,7 +40,7 @@ public class RMIClient implements IClient { this.port = port; } - //TODO Javadoc fix + /** * Connects to the RMI server and attempts to join the game. * Looks up the RMI registry to retrieve the {@link IGameServer} stub. From b5316e37b4ab19b9f6e6183b5aee7cd52738a699 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 20:22:10 +0200 Subject: [PATCH 17/21] FIX: JAVADOC-TUI --- src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index e97f1ad..6321900 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -6,8 +6,13 @@ import java.util.List; public class TUI implements IView { - // ── dati di stato ─────────────────────────────────────────── + /** + * The style of the table + */ private BorderStyle style = BorderStyle.UNICODE; + /** + * The {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render + */ private Game model; private String username; public TUI(Game model) { From 9bedea385534b8b5e9d8b80cb8badb3fd6006153 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 17:59:34 +0200 Subject: [PATCH 18/21] Add: TUI javadoc --- .../it/polimi/ingsw/gc14/View/TUI/TUI.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index 6321900..19dac09 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -6,33 +6,52 @@ import java.util.List; public class TUI implements IView { - /** - * The style of the table - */ - private BorderStyle style = BorderStyle.UNICODE; /** * The {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render */ private Game model; + + /** + * The {@link it.polimi.ingsw.gc14.Model.Player } username stored for the player hand render + */ private String username; + + /** + * Constructor for the class {@code TUI} + * @param model The model that will be display + */ public TUI(Game model) { this.model = model; this.username=""; } + + /** + * Set the {@code Username} of the player, used for the hand player display + * @param username + */ public void setUsername(String username) { this.username = username; } + /** + * Update {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render + */ @Override public void update(Game model) { this.model = model; } - // ── punto di ingresso ─────────────────────────────────────── + /** + * Default method called to display homepage , implements {@link IView} + */ public void render() { renderBoard(); } + + /** + * Method called to display players status and board status + */ public void fullRender() { try{ @@ -53,6 +72,9 @@ public class TUI implements IView { System.out.println(model.PlayersStamp()+"\n"+ AsciiTable.sideBySide(lines,lines2,3)); } + /** + * Method called to display board status + */ public void renderBoard() { try{ @@ -71,6 +93,9 @@ public class TUI implements IView { List lines2=List.of((PrintMenuOptions()+"\nYOUR HAND\n"+model.getPlayerByUsername(username)).split("\n")); System.out.println(AsciiTable.sideBySide(lines,lines2,3)); } + /** + * Method called to display player status + */ public void renderPlayer() { try{ @@ -90,17 +115,26 @@ public class TUI implements IView { System.out.println(AsciiTable.sideBySide(lines,lines2,3)); } + /** + * Method called to display a message on the terminal + */ public void showMessage(String message) { System.out.println(message); } - + /** + * Method called to display a error on the terminal + */ public void showError(String message) { System.out.println(message); } + /** + * Method used to set up menu options + * @return the string format of the menu options + */ private String PrintMenuOptions() { var table=new AsciiTable(BorderStyle.ROUNDED,2); From 04b61a8cb2442ce3d26d554301a6620c1cf1916a Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 18:13:50 +0200 Subject: [PATCH 19/21] Fix: TUI javadoc --- .../it/polimi/ingsw/gc14/View/TUI/TUI.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index 19dac09..fed8a6c 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -7,18 +7,18 @@ import java.util.List; public class TUI implements IView { /** - * The {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render + * The {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render. */ private Game model; /** - * The {@link it.polimi.ingsw.gc14.Model.Player } username stored for the player hand render + * The {@link it.polimi.ingsw.gc14.Model.Player } username stored for the player hand render. */ private String username; /** - * Constructor for the class {@code TUI} - * @param model The model that will be display + * Constructor for the class {@code TUI}. + * @param model The model that will be displayed. */ public TUI(Game model) { this.model = model; @@ -26,7 +26,7 @@ public class TUI implements IView { } /** - * Set the {@code Username} of the player, used for the hand player display + * Set the {@code Username} of the player, used for the hand player display. * @param username */ public void setUsername(String username) { @@ -34,7 +34,7 @@ public class TUI implements IView { } /** - * Update {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render + * Update {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render. */ @Override public void update(Game model) { @@ -42,7 +42,7 @@ public class TUI implements IView { } /** - * Default method called to display homepage , implements {@link IView} + * Default method called to display homepage , implements {@link IView}. */ public void render() { @@ -50,7 +50,9 @@ public class TUI implements IView { } /** - * Method called to display players status and board status + * Method called to display players status and board status. + * In the upper part displays {@link #renderPlayer} information , in a table format. + * In the lower part displays {@link #renderBoard} information in the left , menu options and {@code Username} hand in the right. */ public void fullRender() { @@ -73,7 +75,8 @@ public class TUI implements IView { } /** - * Method called to display board status + * Method called to display board status. + * Displays turn order ,upper list cards , offer track , lower list cards in the left, menu options and {@code Username} hand in the right. */ public void renderBoard() { @@ -94,7 +97,8 @@ public class TUI implements IView { System.out.println(AsciiTable.sideBySide(lines,lines2,3)); } /** - * Method called to display player status + * Method called to display player status. + * Displays player prestige value,food value, character deck and building deck , in a table format. */ public void renderPlayer() { @@ -116,7 +120,7 @@ public class TUI implements IView { } /** - * Method called to display a message on the terminal + * Method called to display a message on the terminal. */ public void showMessage(String message) { @@ -124,7 +128,7 @@ public class TUI implements IView { } /** - * Method called to display a error on the terminal + * Method called to display a error on the terminal. */ public void showError(String message) { @@ -132,8 +136,9 @@ public class TUI implements IView { } /** - * Method used to set up menu options - * @return the string format of the menu options + * Method used to set up menu options. + * List of runnable command as a legend. + * @return the string format of the menu options. */ private String PrintMenuOptions() { From 76d236f5f1d0fce58f1b74c6f08c55703aeb053d Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Mon, 4 May 2026 13:00:06 +0200 Subject: [PATCH 20/21] Add: ASCII TABLE JAVA DOC --- .../ingsw/gc14/View/TUI/AsciiTable.java | 155 ++++++++++++++---- 1 file changed, 127 insertions(+), 28 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/AsciiTable.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/AsciiTable.java index 26ccb31..813708c 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/AsciiTable.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/AsciiTable.java @@ -1,43 +1,112 @@ package it.polimi.ingsw.gc14.View.TUI; import java.util.*; -//TODO javadoc -// Helper generale per costruire tabelle ASCII +/** + * General-purpose helper for building fixed-width ASCII/Unicode tables in a TUI. + * + *

A table is built by adding rows one at a time, then calling {@link #build()} + * to obtain the fully rendered string. Column width is computed automatically + * from the widest cell across all rows. + * + *

Example usage: + *

{@code
+ * AsciiTable table = new AsciiTable(BorderStyle.UNICODE, 3);
+ * table.addHeader("Name", "Food", "PP");
+ * table.addRow("Alice", "4", "12");
+ * table.addRow("Bob",   "2", "8");
+ * System.out.println(table.build());
+ * }
+ */ public class AsciiTable { - //TODO javadoc + + /** + * The border style used to draw the table (e.g. Unicode box-drawing, + * plain ASCII, rounded corners). + */ private final BorderStyle s; - //TODO javadoc + /** + * The number of columns in the table. + * Every row added via {@link #addRow} must contain exactly this many cells. + */ private final int cols; - //TODO javadoc + /** + * The rows of the table, each represented as a list of cell strings. + * Rows are stored in display order; {@link #addHeader} inserts at index 0. + */ private final List> rows = new ArrayList<>(); - //TODO javadoc + /** + * Row indices after which a horizontal separator line is drawn. + * Populated by {@link #addHeader} and {@link #addSeparator}. + */ private final List separators = new ArrayList<>(); - //TODO javadoc + /** + * Constructs an empty {@code AsciiTable} with the given border style + * and column count. + * + * @param s the {@link BorderStyle} to use for box-drawing characters + * @param cols the number of columns; every row must supply exactly this + * many cells + */ public AsciiTable(BorderStyle s, int cols) { this.s = s; this.cols = cols; } - //TODO javadoc + /** + * Appends a row at the bottom of the table. + * + * @param cells one string per column, in left-to-right order + */ public void addRow(String... cells) { rows.add(Arrays.asList(cells)); } - //TODO javadoc + /** + * Appends a row at the bottom of the table. + * + * @param cells a list of strings, one per column, in left-to-right order + */ public void addRow(List cells) { rows.add(cells); } - //TODO javadoc - public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); } + /** + * Inserts a header row at the top of the table and marks it with a + * horizontal separator so that a dividing line is drawn below it. + * + *

Calling this method after rows have already been added will push + * all existing rows down by one position. + * + * @param cells one string per column, in left-to-right order + */ + public void addHeader(String... cells) { + rows.add(0, Arrays.asList(cells)); + separators.add(0); + } - //TODO javadoc - public void addSeparator() { separators.add(rows.size()-1); } + /** + * Marks the current last row so that a horizontal separator line is + * drawn below it when the table is built. + * + *

Call this method immediately after the row that should be followed + * by the separator. + */ + public void addSeparator() { separators.add(rows.size() - 1); } - //TODO javadoc + /** + * Renders the table to a multi-line string. + * + *

Column width is determined dynamically as the length of the longest + * cell across all rows, plus one padding space. All cells are left-aligned + * and padded or truncated to the same width. + * + * @return the fully rendered table as a single string with embedded newlines + */ public String build() { var sb = new StringBuilder(); - int maxWidth = rows.stream().mapToInt(x->x.stream().mapToInt(y->y.length()).max().getAsInt()).max().getAsInt()+1; - sb.append(hline(s.tl(), s.mt(), s.tr(),maxWidth)).append('\n'); + int maxWidth = rows.stream() + .mapToInt(x -> x.stream().mapToInt(y -> y.length()).max().getAsInt()) + .max().getAsInt() + 1; + sb.append(hline(s.tl(), s.mt(), s.tr(), maxWidth)).append('\n'); for (int i = 0; i < rows.size(); i++) { sb.append(s.v()); @@ -45,14 +114,23 @@ public class AsciiTable { sb.append(rpad(" " + cell, maxWidth)).append(s.v()); sb.append('\n'); if (separators.contains(i) && i < rows.size() - 1) - sb.append(hline(s.sl(), s.sx(), s.sr(),maxWidth)).append('\n'); + sb.append(hline(s.sl(), s.sx(), s.sr(), maxWidth)).append('\n'); } sb.append(hline(s.bl(), s.mb(), s.br(), maxWidth)); return sb.toString(); } - //TODO javadoc - private String hline(String l, String m, String r,int maxWidth) { + /** + * Builds a single horizontal border line spanning all columns. + * + * @param l the left-end character (e.g. {@code ╔}, {@code ╠}, {@code ╚}) + * @param m the column-junction character (e.g. {@code ╦}, {@code ╬}, {@code ╩}) + * @param r the right-end character (e.g. {@code ╗}, {@code ╣}, {@code ╝}) + * @param maxWidth the width in characters of each column segment, + * filled with the horizontal line character of the current style + * @return the rendered horizontal line as a string + */ + private String hline(String l, String m, String r, int maxWidth) { var sb = new StringBuilder(l); for (int i = 0; i < cols; i++) { sb.append(s.h().repeat(maxWidth)); @@ -61,13 +139,40 @@ public class AsciiTable { return sb.append(r).toString(); } - //TODO javadoc + /** + * Right-pads a string with spaces to the given width, or truncates it + * if it exceeds that width. + * + * @param s the input string + * @param w the desired output width in characters + * @return a string of exactly {@code w} characters + */ private static String rpad(String s, int w) { if (s.length() >= w) return s.substring(0, w); return s + " ".repeat(w - s.length()); } - //TODO javadoc + /** + * Places two pre-rendered text blocks side by side, separated by a gap. + * + *

Each block is a list of lines as returned by {@link #build()}. + * Lines in the left block are padded to a uniform width so that the + * right block always starts at the same horizontal position. If one + * block is taller than the other, the shorter one is padded with blank + * lines. + * + *

Example: + *

{@code
+     * List left  = Arrays.asList(table1.build().split("\n"));
+     * List right = Arrays.asList(table2.build().split("\n"));
+     * System.out.print(AsciiTable.sideBySide(left, right, 2));
+     * }
+ * + * @param left lines of the left block + * @param right lines of the right block + * @param gap number of blank spaces between the two blocks + * @return the merged string with embedded newlines + */ public static String sideBySide(List left, List right, int gap) { int leftWidth = left.stream().mapToInt(String::length).max().orElse(0); int maxHeight = Math.max(left.size(), right.size()); @@ -75,17 +180,11 @@ public class AsciiTable { var sb = new StringBuilder(); for (int i = 0; i < maxHeight; i++) { - String l = i < left.size() - ? left.get(i) - : " ".repeat(leftWidth); - - // padda la riga sinistra se è più corta delle altre + String l = i < left.size() ? left.get(i) : " ".repeat(leftWidth); l = rpad(l, leftWidth); - String r = i < right.size() ? right.get(i) : ""; sb.append(l).append(padding).append(r).append('\n'); } return sb.toString(); } - } \ No newline at end of file From b40ed99bc134782de613b858de0242c85aba2e0a Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Mon, 4 May 2026 13:04:48 +0200 Subject: [PATCH 21/21] FIX: TUI javadox --- .../it/polimi/ingsw/gc14/View/TUI/TUI.java | 251 +++++++++++------- 1 file changed, 154 insertions(+), 97 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index fed8a6c..ecd489e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -4,37 +4,77 @@ import it.polimi.ingsw.gc14.View.IView; import java.util.List; +/** + * Text-based User Interface (TUI) implementation of {@link IView}. + * + *

Renders the current state of a {@link Game} model directly to the + * standard output using Unicode box-drawing characters and fixed-width + * ASCII tables (see {@link AsciiTable}). + * + *

The display is split into two side-by-side panels: + *

    + *
  • Left panel — board or player status, depending on the render method called.
  • + *
  • Right panel — menu options legend and the current player's hand.
  • + *
+ * + *

The terminal is cleared before each render via a platform-aware + * {@code cls} / {@code clear} system call. + * + *

Typical usage: + *

{@code
+ * TUI tui = new TUI(game);
+ * tui.setUsername("Alice");
+ * tui.fullRender();
+ * }
+ */ public class TUI implements IView { /** - * The {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render. + * The {@link Game} model whose state is rendered. + * Updated via {@link #update(Game)} whenever the game state changes. */ private Game model; /** - * The {@link it.polimi.ingsw.gc14.Model.Player } username stored for the player hand render. + * The username of the local player, used to retrieve and display + * that player's hand in the right panel. + * + * @see #setUsername(String) */ private String username; /** - * Constructor for the class {@code TUI}. - * @param model The model that will be displayed. + * Constructs a {@code TUI} bound to the given game model. + * The username is initialised to an empty string and must be set + * separately via {@link #setUsername(String)} before calling any + * render method that displays the player's hand. + * + * @param model the {@link Game} model to display; must not be {@code null} */ public TUI(Game model) { this.model = model; - this.username=""; + this.username = ""; } /** - * Set the {@code Username} of the player, used for the hand player display. - * @param username + * Sets the username of the local player. + * This value is used by {@link #renderBoard()} and {@link #fullRender()} + * to look up the correct player hand via + * {@link Game#getPlayerByUsername(String)}. + * + * @param username the player's username; must match an existing player + * in the current {@link Game} model */ public void setUsername(String username) { this.username = username; } /** - * Update {@link it.polimi.ingsw.gc14.Model.Game } model stored for the game status render. + * Updates the game model stored in this view. + * Should be called whenever the game state changes so that the next + * render reflects the latest state. + * + * @param model the new {@link Game} model; must not be {@code null} */ @Override public void update(Game model) { @@ -42,119 +82,136 @@ public class TUI implements IView { } /** - * Default method called to display homepage , implements {@link IView}. + * Default render entry point, as required by {@link IView}. + * Delegates to {@link #renderBoard()}. */ - public void render() - { + @Override + public void render() { renderBoard(); } /** - * Method called to display players status and board status. - * In the upper part displays {@link #renderPlayer} information , in a table format. - * In the lower part displays {@link #renderBoard} information in the left , menu options and {@code Username} hand in the right. + * Renders a full view of the game, combining both player status + * and board status. + * + *

Layout: + *

    + *
  • Top — player status table produced by + * {@link Game#PlayersStamp()}.
  • + *
  • Bottom-left — board status produced by + * {@link Game#BoardStamp()}.
  • + *
  • Bottom-right — menu options legend and the local + * player's hand.
  • + *
+ * + *

The terminal is cleared before rendering. */ - public void fullRender() - { - try{ - String os = System.getProperty("os.name").toLowerCase(); - ProcessBuilder pb; - if (os.contains("win")) { - pb = new ProcessBuilder("cmd", "/c", "cls"); - } else { - pb = new ProcessBuilder("clear"); - } - pb.inheritIO().start().waitFor(); - } - catch(Exception e){ - } - - Listlines=List.of(model.BoardStamp().split("\n")); - List lines2=List.of((PrintMenuOptions()+"\n"+model.getPlayerByUsername(username)).split("\n")); - System.out.println(model.PlayersStamp()+"\n"+ AsciiTable.sideBySide(lines,lines2,3)); + public void fullRender() { + clearTerminal(); + List lines = List.of(model.BoardStamp().split("\n")); + List lines2 = List.of((printMenuOptions() + "\n" + + model.getPlayerByUsername(username)).split("\n")); + System.out.println(model.PlayersStamp() + "\n" + + AsciiTable.sideBySide(lines, lines2, 3)); } /** - * Method called to display board status. - * Displays turn order ,upper list cards , offer track , lower list cards in the left, menu options and {@code Username} hand in the right. + * Renders the board status only. + * + *

Layout: + *

    + *
  • Left panel — turn order, upper card row, offer track, + * and lower card row, as produced by {@link Game#BoardStamp()}.
  • + *
  • Right panel — menu options legend followed by the local + * player's hand.
  • + *
+ * + *

The terminal is cleared before rendering. */ - public void renderBoard() - { - try{ - String os = System.getProperty("os.name").toLowerCase(); - ProcessBuilder pb; - if (os.contains("win")) { - pb = new ProcessBuilder("cmd", "/c", "cls"); - } else { - pb = new ProcessBuilder("clear"); - } - pb.inheritIO().start().waitFor(); - } - catch(Exception e){ - } - Listlines=List.of(model.BoardStamp().split("\n")); - List lines2=List.of((PrintMenuOptions()+"\nYOUR HAND\n"+model.getPlayerByUsername(username)).split("\n")); - System.out.println(AsciiTable.sideBySide(lines,lines2,3)); - } - /** - * Method called to display player status. - * Displays player prestige value,food value, character deck and building deck , in a table format. - */ - public void renderPlayer() - { - try{ - String os = System.getProperty("os.name").toLowerCase(); - ProcessBuilder pb; - if (os.contains("win")) { - pb = new ProcessBuilder("cmd", "/c", "cls"); - } else { - pb = new ProcessBuilder("clear"); - } - pb.inheritIO().start().waitFor(); - } - catch(Exception e){ - } - Listlines=List.of(model.PlayersStamp().split("\n")); - List lines2=List.of(PrintMenuOptions().split("\n")); - System.out.println(AsciiTable.sideBySide(lines,lines2,3)); + public void renderBoard() { + clearTerminal(); + List lines = List.of(model.BoardStamp().split("\n")); + List lines2 = List.of((printMenuOptions() + "\nYOUR HAND\n" + + model.getPlayerByUsername(username)).split("\n")); + System.out.println(AsciiTable.sideBySide(lines, lines2, 3)); } /** - * Method called to display a message on the terminal. + * Renders the player status table only. + * + *

Layout: + *

    + *
  • Left panel — prestige, food, character deck, and building + * deck for all players, as produced by {@link Game#PlayersStamp()}.
  • + *
  • Right panel — menu options legend.
  • + *
+ * + *

The terminal is cleared before rendering. */ - public void showMessage(String message) - { + public void renderPlayer() { + clearTerminal(); + List lines = List.of(model.PlayersStamp().split("\n")); + List lines2 = List.of(printMenuOptions().split("\n")); + System.out.println(AsciiTable.sideBySide(lines, lines2, 3)); + } + + /** + * Prints a plain message to standard output. + * + * @param message the message to display + */ + public void showMessage(String message) { System.out.println(message); } /** - * Method called to display a error on the terminal. + * Prints an error message to standard output. + * + * @param message the error message to display */ - public void showError(String message) - { + public void showError(String message) { + clearTerminal(); + render(); System.out.println(message); } /** - * Method used to set up menu options. - * List of runnable command as a legend. - * @return the string format of the menu options. + * Builds and returns the menu options panel as a two-column + * {@link AsciiTable} with rounded borders. + * + *

The left column lists game action commands (slot choice, draw, pick…), + * the right column lists render shortcuts (full, board, players). + * + * @return the rendered menu table as a multi-line string */ - private String PrintMenuOptions() - { - var table=new AsciiTable(BorderStyle.ROUNDED,2); - table.addHeader( "Menu Options","Render Options"); - table.addRow( List.of("0-SlotChoice(pos)","A-Full Render")); - table.addRow(List.of("1-DrawUpperTribe(pos)","B-Board Render")); - table.addRow(List.of("2-DrawUpperBuilding(pos)","C-Players Render")); - table.addRow(List.of("3-DrawLowerTribe(pos)","")); - table.addRow(List.of("4-DrawLowerBuilding(pos)","")); - table.addRow(List.of("5-PickOptionalTribe(pos)","")); - table.addRow(List.of("6-PickOptionalBuilding(pos)","")); - table.addRow(List.of("7-NoOptional","")); - table.addRow(List.of("8-NoUpperCard","")); - table.addRow(List.of("9-NoLowerCard","")); + private String printMenuOptions() { + var table = new AsciiTable(BorderStyle.ROUNDED, 2); + table.addHeader("Menu Options", "Render Options"); + table.addRow(List.of("0-SlotChoice(pos)", "A-Full Render")); + table.addRow(List.of("1-DrawUpperTribe(pos)", "B-Board Render")); + table.addRow(List.of("2-DrawUpperBuilding(pos)", "C-Players Render")); + table.addRow(List.of("3-DrawLowerTribe(pos)", "")); + table.addRow(List.of("4-DrawLowerBuilding(pos)", "")); + table.addRow(List.of("5-PickOptionalTribe(pos)", "")); + table.addRow(List.of("6-PickOptionalBuilding(pos)", "")); + table.addRow(List.of("7-NoOptional", "")); + table.addRow(List.of("8-NoUpperCard", "")); + table.addRow(List.of("9-NoLowerCard", "")); return table.build(); } -} + /** + * Clears the terminal using a platform-aware system call. + * Uses {@code cls} on Windows and {@code clear} on Unix-like systems. + * Failures are silently ignored to avoid interrupting the render flow. + */ + private void clearTerminal() { + try { + String os = System.getProperty("os.name").toLowerCase(); + ProcessBuilder pb = os.contains("win") + ? new ProcessBuilder("cmd", "/c", "cls") + : new ProcessBuilder("clear"); + pb.inheritIO().start().waitFor(); + } catch (Exception ignored) {} + } +} \ No newline at end of file