From 505820d34367cd8d7ec98e6d76cd72bdb2f2844e Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 16:34:54 +0200 Subject: [PATCH 01/45] Add:No Optional Card --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 29 +++++++++++++------ .../gc14/Controller/ClientController.java | 10 +++++++ .../ingsw/gc14/Controller/GameController.java | 12 ++++++++ .../polimi/ingsw/gc14/Network/EventType.java | 3 +- .../gc14/Network/NetworkEvents/AddPlayer.java | 4 --- .../NetworkEvents/DrawLowerBuildingCard.java | 4 --- .../NetworkEvents/DrawLowerTribeCard.java | 4 --- .../NetworkEvents/DrawUpperBuildingCard.java | 4 --- .../NetworkEvents/DrawUpperTribeCard.java | 5 +--- .../Network/NetworkEvents/NoOptionalCard.java | 22 ++++++++++++++ .../PickOptionalBuildingCard.java | 5 ---- .../NetworkEvents/PickOptionalTribeCard.java | 4 --- .../Network/NetworkEvents/SlotChoice.java | 4 --- .../ingsw/gc14/View/TUI/AsciiTable.java | 1 - 14 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 5e02464..aa30aaf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -68,16 +68,27 @@ public class ClientLauncherTUI { private void getInput(Scanner scanner, ClientController controller, String username) { - int action = scanner.nextInt(); - int pos = scanner.nextInt(); - + String action = scanner.next(); + int pos=-1; + if(!action.equals("8")) { + try + { + pos = scanner.nextInt(); + } + catch(Exception e) + { + System.out.println("ERROR: Invalid input(expected number)"); + } + } switch(action) { - case 1 -> controller.drawLowerBuildingCard(username, pos); - case 2 -> controller.drawLowerTribeCard(username, pos); - case 3 -> controller.drawUpperBuildingCard(username, pos); - case 4 -> controller.drawUpperTribeCard(username, pos); - case 5 -> controller.pickOptionalBuildingCard(username, pos); - case 6 -> controller.slotChoice(username, pos); + 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); } return; diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index 63da09f..1b96cd4 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -104,6 +104,16 @@ public class ClientController { 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. + */ + 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. * diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java index ca65067..dd6b120 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/GameController.java @@ -147,6 +147,18 @@ public class GameController { return false; return model.PickOptionalBuildingCard(model.getPlayerByUsername(playerUsername), pos); } + /** + * Refuse to pick an optional building card for the specified player. + * @param playerUsername the username of the player performing the action. + * @return {@code true} if the action succeeds, {@code false} if the player does not exist + * or if the pick operation fails. + */ + public boolean noOptionalCard(String playerUsername) { + Player player= model.getPlayerByUsername(playerUsername); + if(player==null) + return false; + return model.NoOptionalCard(model.getPlayerByUsername(playerUsername)); + } /** * Attempts to perform the slot choice action for the specified player at the specified position. diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java index aae15bf..0f8f03c 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java @@ -8,5 +8,6 @@ public enum EventType { DRAW_UPPER_BUILD, DRAW_LOWER_BUILD, PICK_OPTIONAL_TRIBE, - PICK_OPTIONAL_BUILD + PICK_OPTIONAL_BUILD, + NO_OPTIONAL_CARD } 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 54b633a..14acd88 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 @@ -29,8 +29,4 @@ public class AddPlayer extends NetworkEvent implements Serializable { { return gameController.addPlayer(username); } - public String apply(IView gameController) - { - return gameController.toString(); - } } 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 a160629..91b67af 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 @@ -24,8 +24,4 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable return gameController.drawLowerBuildingCard(username, pos); } - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } } 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 f0109c8..0dda4d1 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 @@ -23,8 +23,4 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{ return gameController.drawLowerTribeCard(username, pos); } - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } } 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 56be872..077bc74 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 @@ -24,8 +24,4 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable return gameController.drawUpperBuildingCard(username, pos); } - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } } 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 4cdbc7e..8fcb004 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 @@ -24,8 +24,5 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{ return gameController.drawUpperTribeCard(username, pos); } - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } + } 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 new file mode 100644 index 0000000..9791962 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/NoOptionalCard.java @@ -0,0 +1,22 @@ +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 NoOptionalCard extends NetworkEvent implements Serializable{ + //TODO javadoc + public NoOptionalCard(String username){ + super(username, EventType.NO_OPTIONAL_CARD, false); + } + + //TODO javadoc + @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 1996398..1704082 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 @@ -23,9 +23,4 @@ public class PickOptionalBuildingCard extends NetworkEvent implements Serializa public boolean apply(GameController gameController){ return gameController.pickOptionalBuildingCard(username, pos); } - - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } } 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 0ad9def..0262b7f 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 @@ -25,8 +25,4 @@ public class PickOptionalTribeCard extends NetworkEvent implements Serializable return gameController.pickOptionalTribeCard(username, pos); } - //TODO javadoc - public String apply(IView gameController){ - return gameController.toString(); - } } 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 e22e491..189e3ab 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 @@ -24,8 +24,4 @@ public class SlotChoice extends NetworkEvent implements Serializable { return gameController.slotChoice(username, pos); } - //TODO javadoc - public String apply(IView gameController) { - return gameController.toString(); - } } 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 74cf535..26ccb31 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 @@ -29,7 +29,6 @@ public class AsciiTable { //TODO javadoc public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); } - public void addSeparator() { separators.add(rows.size()-1); } //TODO javadoc public void addSeparator() { separators.add(rows.size()-1); } From 44388ee1e4f6ce07ac2b028d232f0c7999aa1377 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 17:40:36 +0200 Subject: [PATCH 02/45] Fix: Tui adapted to new input case --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 10 +++- .../Model/Cards/TribeCards/EventCard.java | 4 +- .../java/it/polimi/ingsw/gc14/Model/Game.java | 11 ++-- .../ingsw/gc14/Model/Orders/Order2.java | 9 +--- .../ingsw/gc14/Model/Orders/Order3.java | 9 +--- .../ingsw/gc14/Model/Orders/Order4.java | 9 +--- .../ingsw/gc14/Model/Orders/Order5.java | 9 +--- .../java/it/polimi/ingsw/gc14/Model/Slot.java | 2 +- .../it/polimi/ingsw/gc14/View/TUI/TUI.java | 51 +++++++++++-------- 9 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index aa30aaf..06d0fdf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -9,13 +9,15 @@ import java.util.Scanner; public class ClientLauncherTUI { //TODO Javadoc + TUI view; public void main() throws InterruptedException { - TUI view=new TUI(null); + 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(); + view.setUsername(username); System.out.println("Selezionare numero di giocatori desiderato: "); int proposedNumPlayers = scanner.nextInt(); System.out.println("Selezionare RMI[0] o TCP[1]: "); @@ -70,9 +72,10 @@ public class ClientLauncherTUI { private void getInput(Scanner scanner, ClientController controller, String username) { String action = scanner.next(); int pos=-1; - if(!action.equals("8")) { + if(!action.equals("8")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")&&!action.equals("D")) { try { + System.out.println("Insert the required position:"); pos = scanner.nextInt(); } catch(Exception e) @@ -89,6 +92,9 @@ public class ClientLauncherTUI { case "6" -> controller.pickOptionalTribeCard(username, pos); case "7" -> controller.pickOptionalBuildingCard(username, pos); case "8" -> controller.noOptionalCard(username); + case "A" -> view.fullRender(); + case "B" -> view.renderBoard(); + case "C" -> view.renderPlayer(); } return; diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java index 5f8fdbc..e8cd013 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java @@ -62,7 +62,7 @@ public abstract class EventCard extends TribeCard { */ @Override public String toString() { - return super.toString()+" "+type.toString(); + return super.toString()+"(Event)"+type.toString(); } /** @@ -77,7 +77,7 @@ public abstract class EventCard extends TribeCard { */ @Override public String toStringBoard() { - return super.toString()+" "+type.toString(); + return super.toString()+"(Event)"+type.toString(); } /** diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index 2308aa2..add7416 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -793,9 +793,10 @@ public class Game implements Serializable { List stringUpOffer=new ArrayList<>(); List stringDownOffer=new ArrayList<>(); + int index=0; for(Map.Entry entry:slotMap.entrySet()) { - stringDownOffer.add(entry.getKey().toStringTUI()); + stringDownOffer.add((index++)+"."+entry.getKey().toStringTUI()); if(entry.getValue()!=null) stringUpOffer.add(entry.getValue().getUserName()); else @@ -813,11 +814,11 @@ public class Game implements Serializable { { if(iTribeTableUpper.addRow(x)); 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 548f483..589ac3d 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 @@ -58,24 +58,19 @@ public class Order2 extends OrderLogicCard { var table = new AsciiTable(BorderStyle.UNICODE, 2); List stringUp=new ArrayList<>(); - List stringDown=new ArrayList<>(); for(int i=0;i<2;i++) { try { - playerList.get(i); - stringUp.add(i+". "+playerList.get(i).player.getUserName()); if(playerList.get(i).played) - stringDown.add(" Placed"); + stringUp.add(" "); else - stringDown.add(" Not Placed"); + stringUp.add(i+". "+playerList.get(i).player.getUserName()); } catch (IndexOutOfBoundsException e) { stringUp.add(""); - stringDown.add(""); } } table.addRow(stringUp); - table.addRow(stringDown); List stringList=new ArrayList<>(); stringList.add("+1 Food"); 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 14bc2db..6cc6b57 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 @@ -60,24 +60,19 @@ public class Order3 extends OrderLogicCard { var table = new AsciiTable(BorderStyle.UNICODE, 3); List stringUp=new ArrayList<>(); - List stringDown=new ArrayList<>(); for(int i=0;i<3;i++) { try { - playerList.get(i); - stringUp.add(i+". "+playerList.get(i).player.getUserName()); if(playerList.get(i).played) - stringDown.add(" Placed"); + stringUp.add(" "); else - stringDown.add(" Not Placed"); + stringUp.add(i+". "+playerList.get(i).player.getUserName()); } catch (IndexOutOfBoundsException e) { stringUp.add(""); - stringDown.add(""); } } table.addRow(stringUp); - table.addRow(stringDown); List stringList=new ArrayList<>(); 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 1fc229c..e4a8bed 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 @@ -66,24 +66,19 @@ public class Order4 extends OrderLogicCard { var table = new AsciiTable(BorderStyle.UNICODE, 4); List stringUp=new ArrayList<>(); - List stringDown=new ArrayList<>(); for(int i=0;i<4;i++) { try { - playerList.get(i); - stringUp.add(i+". "+playerList.get(i).player.getUserName()); if(playerList.get(i).played) - stringDown.add(" Placed"); + stringUp.add(" "); else - stringDown.add(" Not Placed"); + stringUp.add(i+". "+playerList.get(i).player.getUserName()); } catch (IndexOutOfBoundsException e) { stringUp.add(""); - stringDown.add(""); } } table.addRow(stringUp); - table.addRow(stringDown); List stringList=new ArrayList<>(); stringList.add("+2 Food"); 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 d184bcc..c435ae2 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 @@ -67,24 +67,19 @@ public class Order5 extends OrderLogicCard { var table = new AsciiTable(BorderStyle.UNICODE, 5); List stringUp=new ArrayList<>(); - List stringDown=new ArrayList<>(); for(int i=0;i<5;i++) { try { - playerList.get(i); - stringUp.add(i+". "+playerList.get(i).player.getUserName()); if(playerList.get(i).played) - stringDown.add(" Placed"); + stringUp.add(" "); else - stringDown.add(" Not Placed"); + stringUp.add(i+". "+playerList.get(i).player.getUserName()); } catch (IndexOutOfBoundsException e) { stringUp.add(""); - stringDown.add(""); } } table.addRow(stringUp); - table.addRow(stringDown); List stringList=new ArrayList<>(); stringList.add("+3 Food"); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java index 5ec72db..62eab05 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java @@ -172,7 +172,7 @@ public class Slot implements Serializable { public String toStringTUI() { StringBuilder s = new StringBuilder(); - s.append(this.getSlotId()+" "); + //s.append(this.getSlotId()+" "); for(int i=0;ilines=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 renderBoard() @@ -53,7 +62,9 @@ public class TUI implements IView { } catch(Exception e){ } - System.out.println(model.BoardStamp()); + 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)); } public void renderPlayer() { @@ -69,25 +80,10 @@ public class TUI implements IView { } catch(Exception e){ } - System.out.println(model.BoardStamp()); + Listlines=List.of(model.PlayersStamp().split("\n")); + List lines2=List.of(PrintMenuOptions().split("\n")); + System.out.println(AsciiTable.sideBySide(lines,lines2,3)); } - public void renderMyHand() - { - 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){ - } - System.out.println(model.getPlayerByUsername(username)); - } - public void showMessage(String message) { @@ -100,4 +96,19 @@ public class TUI implements IView { System.out.println(message); } + private String PrintMenuOptions() + { + 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","")); + return table.build(); + } + } From 39e06886a331f3758c6d656199852a575783d3e7 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:01:45 +0200 Subject: [PATCH 03/45] 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 04/45] 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 05/45] 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 06/45] 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 c91cbb303119608c617884cef7c530b671c05a5f Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Fri, 1 May 2026 18:44:40 +0200 Subject: [PATCH 07/45] Changed:GameTest.hasDrawable()-> now only on character --- src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 959dd13..73d227e 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -141,13 +141,11 @@ class GameTest { } private boolean hasDrawableLower(Game game) { - return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1 - || !game.getLowerListBuilding().isEmpty(); + return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1; } private boolean hasDrawableUpper(Game game) { - return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1 - || !game.getUpperListBuilding().isEmpty(); + return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1; } @Test 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 08/45] 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 09/45] 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 b5889d86e025a999de92d7022388797d59df986e Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 16:03:47 +0200 Subject: [PATCH 10/45] Fix: TUI list option --- src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java | 8 ++++---- .../polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java | 1 + 2 files changed, 5 insertions(+), 4 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..a1d7a6e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -85,10 +85,10 @@ public class ClientLauncherTUI { } switch(action) { 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 "1" -> controller.drawUpperTribeCard(username, pos); + case "2" -> controller.drawUpperBuildingCard(username, pos); + case "3" -> controller.drawLowerTribeCard(username, pos); + case "4" -> controller.drawLowerBuildingCard(username, pos); case "5" -> controller.pickOptionalTribeCard(username, pos); case "6" -> controller.pickOptionalBuildingCard(username, pos); case "7" -> controller.noOptionalCard(username); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 6fadf03..0e06955 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -90,6 +90,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { if (controller.addPlayer(username)) { clients.put(username, callback); playerList.add(username); + System.out.println("Accepted player: " + username); return true; } return false; 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 11/45] 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 fe621d3a3cf200b6ce5364681ec054b0bd0431f8 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 16:11:32 +0200 Subject: [PATCH 12/45] Add: TUI for server (debug) --- src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index 9c8a10e..252a9da 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -7,6 +7,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer; import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer; +import it.polimi.ingsw.gc14.View.TUI.TUI; import java.rmi.RemoteException; import java.util.concurrent.BlockingQueue; @@ -56,6 +57,8 @@ public class ServerLauncher { */ static LimitedList playerList; + TUI view; + /** * Class constructor that initializes the attributes. @@ -137,11 +140,14 @@ public class ServerLauncher { System.out.println("\n\nNotifying model"); serverRMI.notifyAll(gameController.getModel()); serverTCP.notifyAll(gameController.getModel()); + this.view = new TUI(gameController.getModel()); + this.view.fullRender(); // Game execution while (true) { try { this.doFirstEvent(); + this.view.fullRender(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; From 670b4fcf84edd34649030a6c5c3c8c663d9017a4 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 16:15:10 +0200 Subject: [PATCH 13/45] 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 482921eb86acd64ecf9a85d4e16540811dfe5fa1 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 16:38:30 +0200 Subject: [PATCH 14/45] Fix:Board --- .../ingsw/gc14/Model/GamePackage/Board.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java index 4fda653..8c324b6 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java @@ -41,6 +41,8 @@ public class Board implements Serializable { /** Contains all the building cards of the upper list. When a new era starts, the old era's buildings are moved from the upper to the lower list */ public List lowerListBuilding; + + private final ArrayList> buildingCardsAllEras; /** Number of players */ private int nTotem; @@ -88,6 +90,7 @@ public class Board implements Serializable { tribeDeck=generateTribeDeck(nTotem); era=1; + for(int i=0;i buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1)); Collections.shuffle(buildingDeck); + buildingCardsAllEras= new ArrayList<>(); if(nTotem==2) + { + buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 1))); upperListBuilding = new ArrayList<>(buildingDeck.subList(0,1)); + } else + { + buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 2))); upperListBuilding = new ArrayList<>(buildingDeck.subList(0,2)); + } + + buildingDeck=new ArrayList<>(DecksCreator.loadBuildingDeckByEra(2)); + Collections.shuffle(buildingDeck); + if(nTotem<=3) + { + buildingCardsAllEras.set(1, new ArrayList(buildingDeck.subList(0, 2))); + } + else + { + buildingCardsAllEras.set(1, new ArrayList(buildingDeck.subList(0, 3))); + } + buildingDeck=new ArrayList<>(DecksCreator.loadBuildingDeckByEra(3)); + Collections.shuffle(buildingDeck); + if(nTotem==2) + { + buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 3))); + }else if(nTotem==5) + { + buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 5))); + } + else { + buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 4))); + } + } /** @@ -230,27 +264,11 @@ public class Board implements Serializable { Collections.shuffle(buildingCards); if(era==2) { - if(nTotem<=3) - { - upperListBuilding.addAll(buildingCards.subList(0,2)); - } - else - { - upperListBuilding.addAll( buildingCards.subList(0,3)); - } + upperListBuilding.addAll(buildingCardsAllEras.get(1)); } - else // Era 3 + else { - if(nTotem==2) - { - upperListBuilding.addAll( buildingCards.subList(0,3)); - }else if(nTotem==5) - { - upperListBuilding.addAll( buildingCards.subList(0,5)); - } - else { - upperListBuilding.addAll(buildingCards.subList(0,4)); - } + upperListBuilding.addAll(buildingCardsAllEras.get(2)); } } } From 5ecca62dd9678df00e75b76a24609acfbed4c599 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 17:03:51 +0200 Subject: [PATCH 15/45] Fixed: Building Shuffle Init --- src/main/java/it/polimi/ingsw/gc14/Model/Game.java | 2 +- .../polimi/ingsw/gc14/Model/GamePackage/Board.java | 3 +++ .../ingsw/gc14/Model/GamePackage/BoardTest.java | 13 +++++++++++-- 3 files changed, 15 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 15f09ad..2037d26 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -640,7 +640,7 @@ public class Game implements Serializable { { currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT); HashMap optional=new LinkedHashMap<>(); - for (Player p : playersList) { + for (Player p : orderLogicCard.players) { int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count(); if(tempCount>0) { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java index 8c324b6..3f16dcc 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java @@ -114,6 +114,9 @@ public class Board implements Serializable { ArrayList buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1)); Collections.shuffle(buildingDeck); buildingCardsAllEras= new ArrayList<>(); + buildingCardsAllEras.add(new ArrayList<>()); + buildingCardsAllEras.add(new ArrayList<>()); + buildingCardsAllEras.add(new ArrayList<>()); if(nTotem==2) { buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 1))); diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java index f270740..ce03ea4 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java @@ -149,7 +149,7 @@ class BoardTest { } @Test - @DisplayName("RemgetTribeDeckSizeoving a card from upper row of building cards") + @DisplayName("Removing a card from upper row of building cards") void removeUpperBuildingCard() { Board bd = new Board(3); @@ -214,6 +214,8 @@ class BoardTest { assertEquals(upperListBefore, bd1.lowerListBuilding); assertNotEquals(upperListBefore, bd1.upperListBuilding); assertEquals(2, bd1.upperListBuilding.size()); + assertTrue(bd1.upperListBuilding.stream().allMatch(x->x.getEra()==2)); + assertTrue(bd1.lowerListBuilding.stream().allMatch(x->x.getEra()==1)); // Era 2, nTotem > 3 @@ -227,7 +229,8 @@ class BoardTest { assertEquals(upperListBefore, bd2.lowerListBuilding); assertNotEquals(upperListBefore, bd2.upperListBuilding); assertEquals(3, bd2.upperListBuilding.size()); - + assertTrue(bd2.upperListBuilding.stream().allMatch(x->x.getEra()==2)); + assertTrue(bd2.lowerListBuilding.stream().allMatch(x->x.getEra()==1)); // Era 3, nTotem == 2 numPlayer = 2; @@ -243,6 +246,8 @@ class BoardTest { assertEquals(upperListBefore, bd3.lowerListBuilding); assertNotEquals(upperListBefore, bd3.upperListBuilding); assertEquals(3, bd3.upperListBuilding.size()); + assertTrue(bd3.upperListBuilding.stream().allMatch(x->x.getEra()==3)); + assertTrue(bd3.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); // Era 3, nTotem == 5 @@ -259,6 +264,8 @@ class BoardTest { assertEquals(upperListBefore, bd4.lowerListBuilding); assertNotEquals(upperListBefore, bd4.upperListBuilding); assertEquals(5, bd4.upperListBuilding.size()); + assertTrue(bd4.upperListBuilding.stream().allMatch(x->x.getEra()==3)); + assertTrue(bd4.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); // Era 3, nTotem != 2, 5 @@ -275,6 +282,8 @@ class BoardTest { assertEquals(upperListBefore, bd5.lowerListBuilding); assertNotEquals(upperListBefore, bd5.upperListBuilding); assertEquals(4, bd5.upperListBuilding.size()); + assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3)); + assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); } From e2c48ae59d04709c1cd6f0b4c1b2ec29f0d84546 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 17:06:16 +0200 Subject: [PATCH 16/45] 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 17/45] 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 42a6644f8efa6e12da46893c2c2cd22cd1a787b3 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 17:21:57 +0200 Subject: [PATCH 18/45] Refactor. --- .../Building/Effects/Building11Test.java | 13 +++---- .../Cards/Building/Effects/Building1Test.java | 36 ++++++++++++------- 2 files changed, 31 insertions(+), 18 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 a3d907a..89359e5 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 @@ -112,6 +112,7 @@ class Building11Test { @Test @DisplayName("toString") void testToString(){ + int ID = 11; int era = 1; int price = 1; int prestigeValue = 3; @@ -119,26 +120,26 @@ class Building11Test { int pm = 5; Building11 b11 = new Building11(era, price, prestigeValue, ct, pm); - assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, 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()); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, 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()); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, 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()); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, 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()); + assertEquals("⎕: " + "ID:" + ID + " $:" + 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()); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java index cfd9ef4..0019f12 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java @@ -70,22 +70,34 @@ class Building1Test { @Test @DisplayName("toString") void testToString(){ - Building1 b1 = new Building1(1,2,3, CharacterType.INVENTOR); - assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b1.toString()); + int ID = 1; + int era = 1; + int price = 1; + int prestigeValue = 3; + CharacterType ct = CharacterType.ARTIST; + int pm = 5; - b1 = new Building1(1,2,3, CharacterType.BUILDER); - assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString()); + Building1 b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); - b1 = new Building1(1,2,3, CharacterType.GATHERER); - assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString()); + ct = CharacterType.BUILDER; + b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); - b1 = new Building1(1,2,3, CharacterType.ARTIST); - assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString()); + ct = CharacterType.GATHERER; + b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); - b1 = new Building1(1,2,3, CharacterType.SHAMAN); - assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString()); + ct = CharacterType.HUNTER; + b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); - b1 = new Building1(1,2,3, CharacterType.HUNTER); - assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString()); + ct = CharacterType.INVENTOR; + b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); + + ct = CharacterType.SHAMAN; + b1 = new Building1(era, price, prestigeValue, ct); + assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); } } \ No newline at end of file From 32d1cca2ad91c58d51bb0bacb1b57cb1d75c1f58 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 17:24:00 +0200 Subject: [PATCH 19/45] Fix: Fixed "buy" Method In BuildingCard.java And Relative Tests In BuildingCardTest.java; Now Correctly Handles Discounts Given By Builders. Fix: Fixed "toString" Method In BuildingCard.java And Relative Tests In BuildingCardTest.java. --- .../ingsw/gc14/Model/Cards/BuildingCard.java | 10 +- .../gc14/Model/Cards/BuildingCardTest.java | 155 +++++++++++++++++- 2 files changed, 162 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java index 24e41a1..d6ab676 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java @@ -159,8 +159,16 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf * @return {@code true} if the building card is successfully bought, * {@code false} otherwise. */ + // sum reduction value builder=> sconto public boolean buy(Player player) { - if( bought || !player.removeFood(getPrice())) + int discount = 0; + discount = player.builders.stream().mapToInt(x -> x.getReductionValue()).sum(); + + if(discount > this.price){ + discount = this.price; + } + + if(bought || !player.removeFood(this.price - discount)) return false; player.buildingCards.add(this); bought=true; diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java index 0f713fa..c5fd426 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java @@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Cards; import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType; import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder; import it.polimi.ingsw.gc14.Model.Player; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -149,12 +150,162 @@ class BuildingCardTest { assertFalse(bc0.buy(p2)); } + @Test + @DisplayName("Testing the buy method with discounts") + void testBuyDiscount() { + int food = 5; + int price = 5; + int RV = 1; + + Player p = new Player("test"); + p.addFood(food); + p.builders.add(new Builder(1, RV, 1)); + + + + //Testing that to pay == price - 1 + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p.getFoodValue()); + assertTrue(bc.buy(p)); + + int discount = p.builders.stream().mapToInt(x -> x.getReductionValue()).sum(); + assertEquals(food - price + discount, p.getFoodValue()); + + p.removeFood(p.getFoodValue()); + p.addFood(food); + } + + //Testing that to pay == 0 + p.removeFood(p.getFoodValue()); + p.addFood(food); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p.getFoodValue()); + assertTrue(bc.buy(p)); + + assertEquals(food, p.getFoodValue()); + + p.removeFood(p.getFoodValue()); + p.addFood(food); + } + + //Testing that to pay == 0; discount shouldn't go below 0 + p.removeFood(p.getFoodValue()); + p.addFood(food); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + p.builders.add(new Builder(1, RV, 1)); + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p.getFoodValue()); + assertTrue(bc.buy(p)); + + assertEquals(food, p.getFoodValue()); + + p.removeFood(p.getFoodValue()); + p.addFood(food); + } + + //Testing that to pay == 0 if price < builder b * b.RV + food = 6; + price = 3; + RV = 4; + + Player p2 = new Player("test"); + p2.addFood(food); + p2.builders.add(new Builder(1, RV, 1)); + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p2.getFoodValue()); + assertTrue(bc.buy(p2)); + + int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum(); + assertEquals(food, p2.getFoodValue()); + + p2.removeFood(p2.getFoodValue()); + p2.addFood(food); + } + + p2.removeFood(p2.getFoodValue()); + p2.addFood(food); + + //Testing discount with staggered values + price = 7; + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p2.getFoodValue()); + assertTrue(bc.buy(p2)); + + int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum(); + assertEquals(food - price + discount, p2.getFoodValue()); + + p2.removeFood(p2.getFoodValue()); + p2.addFood(food); + } + + //Testing discount with staggered values; discount shouldn't go below 0 + p2.builders.add(new Builder(1, RV, 1)); + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard bc = new BuildingCard(ID, 1, price,1); + assertEquals(food, p2.getFoodValue()); + assertTrue(bc.buy(p2)); + + assertEquals(food, p2.getFoodValue()); + + p2.removeFood(p2.getFoodValue()); + p2.addFood(food); + } + } + @Test @DisplayName("Testing toString method") void testToString() { - Building13 b0 = new Building13(1, 2,3); + int era = 2; + int price = 5; + int prestigeValue = 6; - assertEquals("Era:1 Price:2 Prestige:3", b0.toString()); + BuildingCard b0 = new BuildingCard(era, price, prestigeValue); + assertEquals("⎕:" + " ID:0" + " $:"+ b0.getPrice() + " PV:" + b0.getPrestigeValue(), b0.toString()); + + for(int ID = 3; ID < 13; ID++){ + if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ + continue; + } + BuildingCard b = new BuildingCard(ID, era, price, prestigeValue); + assertEquals("⎕:" + " ID:" + ID + " $:"+ b.getPrice() + " PV:" + b.getPrestigeValue(), b.toString()); + } } @Test From 86bb799714eea4b577ee4783c5b149a71f64633d Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 2 May 2026 17:29:22 +0200 Subject: [PATCH 20/45] Add: Game slot and draw tests --- .../it/polimi/ingsw/gc14/Model/GameTest.java | 197 ++++++++++++++---- 1 file changed, 161 insertions(+), 36 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 959dd13..3a4b1b1 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -8,7 +8,6 @@ import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; @@ -70,45 +69,59 @@ class GameTest { Player current = game.getCurrentState().getCurrentPlayer(); assertNotNull(current); - if (game.getCurrentState().getNLower() > 0 && hasDrawableLower(game)) { + if (game.getCurrentState().getNLower() > 0) { int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()); if (index != -1) { assertTrue(game.DrawLowerTribeCardByIndex(current, index)); - } else { - current.addFood(100); - assertTrue(game.DrawLowerBuildingCardByIndex(current, 0)); + return; } - } else if (game.getCurrentState().getNUpper() > 0 && hasDrawableUpper(game)) { + if (!game.getLowerListBuilding().isEmpty()) { + current.addFood(100); + assertTrue(game.DrawLowerBuildingCardByIndex(current, 0)); + return; + } + + assertTrue(game.SkipLowerDrawing(current)); + return; + } + + if (game.getCurrentState().getNUpper() > 0) { int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()); if (index != -1) { assertTrue(game.DrawUpperTribeCardByIndex(current, index)); - } else { - current.addFood(100); - assertTrue(game.DrawUpperBuildingCardByIndex(current, 0)); + return; } - } else { - fail( - "Current player has no drawable cards, although the game is still resolving actions.\n" + - "Current player: " + current + "\n" + - "Round: " + game.getCurrentState().getRound() + "\n" + - "Stage: " + game.getCurrentState().getGameStage() + "\n" + - "Slot: " + (game.getCurrentState().getSlot() == null - ? "null" - : game.getCurrentState().getSlot().getSlotId()) + "\n" + - "NLower: " + game.getCurrentState().getNLower() + "\n" + - "NUpper: " + game.getCurrentState().getNUpper() + "\n" + - "Lower tribe size: " + game.getLowerListTribeCards().size() + "\n" + - "Upper tribe size: " + game.getUpperListTribeCards().size() + "\n" + - "Lower building size: " + game.getLowerListBuilding().size() + "\n" + - "Upper building size: " + game.getUpperListBuilding().size() + "\n" + - "First lower non-event: " + firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) + "\n" + - "First upper non-event: " + firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) - ); + if (!game.getUpperListBuilding().isEmpty()) { + current.addFood(100); + assertTrue(game.DrawUpperBuildingCardByIndex(current, 0)); + return; + } + + assertTrue(game.SkipUpperDrawing(current)); + return; } + + fail( + "Current player has no remaining draw actions.\n" + + "Current player: " + current + "\n" + + "Round: " + game.getCurrentState().getRound() + "\n" + + "Stage: " + game.getCurrentState().getGameStage() + "\n" + + "Slot: " + (game.getCurrentState().getSlot() == null + ? "null" + : game.getCurrentState().getSlot().getSlotId()) + "\n" + + "NLower: " + game.getCurrentState().getNLower() + "\n" + + "NUpper: " + game.getCurrentState().getNUpper() + "\n" + + "Lower tribe size: " + game.getLowerListTribeCards().size() + "\n" + + "Upper tribe size: " + game.getUpperListTribeCards().size() + "\n" + + "Lower building size: " + game.getLowerListBuilding().size() + "\n" + + "Upper building size: " + game.getUpperListBuilding().size() + "\n" + + "First lower non-event: " + firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) + "\n" + + "First upper non-event: " + firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) + ); } private void resolveActionsUntilOptionalCardEffect(Game game) { @@ -140,14 +153,13 @@ class GameTest { resolveOptionalPhaseIfPresent(game); } - private boolean hasDrawableLower(Game game) { - return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1 - || !game.getLowerListBuilding().isEmpty(); - } + private void resolveCurrentPlayerCompletely(Game game, Player expectedPlayer) { + assertEquals(expectedPlayer, game.getCurrentState().getCurrentPlayer()); - private boolean hasDrawableUpper(Game game) { - return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1 - || !game.getUpperListBuilding().isEmpty(); + while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS + && expectedPlayer.equals(game.getCurrentState().getCurrentPlayer())) { + resolveOneMandatoryAction(game); + } } @Test @@ -808,7 +820,7 @@ class GameTest { assertFalse(game.PickOptionalBuildingCard(current, 0)); } @Test - void toStringModel() throws IOException, InterruptedException { + void toStringModel() { Game game=new Game(5); Player p1=new Player("p1"); Player p2=new Player("p2"); @@ -828,6 +840,119 @@ class GameTest { assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i)); } - System.out.println(game.toString()); + String result = game.toString(); + + assertNotNull(result); + assertFalse(result.isBlank()); + assertTrue(result.contains("CURRENT STATE")); + } + + @Test + @Timeout(value = 5, unit = TimeUnit.SECONDS) + void shouldDrawLowerBuildingWhenAvailableAndPlayerCanPay() { + Game game = new Game(3); + + addPlayers(game, 3, "lower_building_"); + + for (int safety = 0; safety < 300; safety++) { + + if (game.getCurrentState().getGameStage() == GameStages.SLOT_CHOICE) { + completeSlotChoice(game); + } + + if (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + Player current = game.getCurrentState().getCurrentPlayer(); + assertNotNull(current); + + if (game.getCurrentState().getNLower() > 0 + && !game.getLowerListBuilding().isEmpty()) { + + current.addFood(100); + + int buildingsBefore = current.buildingCards.size(); + int lowerBuildingsBefore = game.getLowerListBuilding().size(); + int foodBefore = current.getFoodValue(); + + assertTrue( + game.DrawLowerBuildingCardByIndex(current, 0), + "DrawLowerBuildingCardByIndex should return true when lower building exists, player can draw lower, and player has food." + ); + + assertEquals(buildingsBefore + 1, current.buildingCards.size()); + assertEquals(lowerBuildingsBefore - 1, game.getLowerListBuilding().size()); + assertTrue(current.getFoodValue() < foodBefore); + + return; + } + + resolveOneMandatoryAction(game); + } + + if (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) { + resolveOptionalPhaseIfPresent(game); + } + + if (game.getCurrentState().getGameStage() == GameStages.ENDED) { + break; + } + } + + fail("The test never reached a state with NLower > 0 and at least one lower building."); + } + + @Test + void drawBuildingShouldReturnFalseIfPlayerCannotPay() { + Game game = new Game(3); + addPlayers(game, 3, "no_food_building_"); + + completeSlotChoice(game); + + while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + Player current = game.getCurrentState().getCurrentPlayer(); + + if (game.getCurrentState().getNUpper() > 0 + && !game.getUpperListBuilding().isEmpty() + && current.builders.isEmpty()) { + + while (current.getFoodValue() > 0) { + assertTrue(current.removeFood(1)); + } + + assertEquals(0, current.getFoodValue()); + assertFalse(game.DrawUpperBuildingCardByIndex(current, 0)); + return; + } + + resolveOneMandatoryAction(game); + } + + fail("No upper building draw state reached with a player without builders."); + } + + @Test + void shouldResolvePlayersAccordingToSlotOrder() { + Game game = new Game(3); + addPlayers(game, 3, "slot_order_"); + + Player firstChooser = game.getCurrentState().getCurrentPlayer(); + assertTrue(game.SlotChoiceByIndex(firstChooser, 2)); + + Player secondChooser = game.getCurrentState().getCurrentPlayer(); + assertTrue(game.SlotChoiceByIndex(secondChooser, 0)); + + Player thirdChooser = game.getCurrentState().getCurrentPlayer(); + assertTrue(game.SlotChoiceByIndex(thirdChooser, 1)); + + assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + + assertEquals(secondChooser, game.getCurrentState().getCurrentPlayer()); + + resolveCurrentPlayerCompletely(game, secondChooser); + + assertEquals(thirdChooser, game.getCurrentState().getCurrentPlayer()); + + resolveCurrentPlayerCompletely(game, thirdChooser); + + assertEquals(firstChooser, game.getCurrentState().getCurrentPlayer()); } } \ No newline at end of file From 06162a243fdf7af0b4504c2094d293971f387479 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 17:29:40 +0200 Subject: [PATCH 21/45] 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 6d5a52f2a43768001d0dd9a2dd0af617b14cdac9 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 17:31:46 +0200 Subject: [PATCH 22/45] Fix: BoardTest --- .../gc14/Model/GamePackage/BoardTest.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java index ce03ea4..dd9db49 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java @@ -125,11 +125,11 @@ class BoardTest { void removeUpperTribeCard() { Board bd = new Board(3); - List before = bd.upperListTribe; - TribeCard cardToRemove = before.get(2); + List before = new ArrayList<>( bd.upperListTribe); + TribeCard cardToRemove = before.get(0); - before.remove(2); - bd.removeUpperTribeCard(cardToRemove); + assertEquals(cardToRemove, before.remove(0)); + assertTrue( bd.removeUpperTribeCard(cardToRemove)); assertEquals(before, bd.upperListTribe); } @@ -139,11 +139,11 @@ class BoardTest { void removeLowerTribeCard() { Board bd = new Board(3); - List before = bd.lowerListTribe; - TribeCard cardToRemove = before.get(2); + List before = new ArrayList<>(bd.lowerListTribe); + TribeCard cardToRemove = before.get(0); - before.remove(2); - bd.removeLowerTribeCard(cardToRemove); + assertEquals(cardToRemove, before.remove(0)); + assertTrue( bd.removeLowerTribeCard(cardToRemove)); assertEquals(before, bd.lowerListTribe); } @@ -153,11 +153,11 @@ class BoardTest { void removeUpperBuildingCard() { Board bd = new Board(3); - List before = bd.upperListBuilding; + List before = new ArrayList<>(bd.upperListBuilding); BuildingCard cardToRemove = before.get(0); - before.remove(0); - bd.removeUpperBuildingCard(cardToRemove); + assertEquals(cardToRemove, before.remove(0)); + assertTrue( bd.removeUpperBuildingCard(cardToRemove)); assertEquals(before, bd.upperListBuilding); } @@ -171,12 +171,10 @@ class BoardTest { bd.nextRound(); // Skip to era 2 } - List before = bd.lowerListBuilding; + List before = new ArrayList<>( bd.lowerListBuilding); BuildingCard cardToRemove = before.get(0); - - before.remove(0); - bd.removeLowerBuildingCard(cardToRemove); - + assertEquals(cardToRemove, before.remove(0)); + assertTrue(bd.removeLowerBuildingCard(cardToRemove)); assertEquals(before, bd.lowerListBuilding); } From be6267b46cf97d598ef140c773f52c45ff7dfe7b Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 17:35:07 +0200 Subject: [PATCH 23/45] Fix: Fixed "toString" Method In ArtistTest.java, BuilderTest.java, GathererTest.java. --- .../gc14/Model/Cards/TribeCards/Characters/ArtistTest.java | 2 +- .../gc14/Model/Cards/TribeCards/Characters/BuilderTest.java | 5 ++--- .../gc14/Model/Cards/TribeCards/Characters/GathererTest.java | 5 ++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java index a4c79b5..925cffb 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java @@ -14,7 +14,7 @@ class ArtistTest { String s = a.toString(); assertNotNull(s); - assertTrue(s.contains(CharacterType.ARTIST.toString())); + assertTrue(s.contains("⎕:")); } @Test diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java index afe9457..0ad64a9 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java @@ -27,9 +27,8 @@ class BuilderTest { String s = b.toString(); assertNotNull(s); - assertTrue(s.contains(CharacterType.BUILDER.toString())); - assertTrue(s.contains("Reduction Value: 2")); - assertTrue(s.contains("Prestige Value: 3")); + assertFalse(s.contains(CharacterType.BUILDER.toString())); + assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s); } @Test diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java index 96d3c83..10fbc3f 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java @@ -13,8 +13,11 @@ class GathererTest { Gatherer g = new Gatherer(1); String s = g.toString(); + System.out.println(s); + assertNotNull(s); - assertTrue(s.contains(CharacterType.GATHERER.toString())); + assertFalse(s.contains(CharacterType.GATHERER.toString())); + assertTrue(s.contains("⎕:")); } @Test From 1d39c5d5926db733a3fcf57eb904d48094baef03 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 17:43:48 +0200 Subject: [PATCH 24/45] Fix: Fixed "toString" Method In InventorTest.java, ShamanTest.java. --- .../gc14/Model/Cards/TribeCards/Characters/InventorTest.java | 5 ++--- .../gc14/Model/Cards/TribeCards/Characters/ShamanTest.java | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java index e89dcf2..fc0e85f 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java @@ -24,9 +24,8 @@ class InventorTest { String s = i.toString(); assertNotNull(s); - assertTrue(s.contains(CharacterType.INVENTOR.toString())); - assertTrue(s.contains("Symbol:")); - assertTrue(s.contains("5")); + assertFalse(s.contains(CharacterType.INVENTOR.toString())); + assertEquals("⎕:" + " I_ID:" + i.Icon(), i.toString()); } @Test diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java index c3111e4..b41cb69 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java @@ -21,8 +21,8 @@ class ShamanTest { String str = s.toString(); assertNotNull(str); - assertTrue(str.contains(CharacterType.SHAMAN.toString())); - assertTrue(str.contains("Icon: 4")); + assertFalse(str.contains(CharacterType.SHAMAN.toString())); + assertEquals("⎕: *:" + s.getIcon(), str); } @Test From a11f1e67411f2bb39caf215e95df512e29e20354 Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 17:50:46 +0200 Subject: [PATCH 25/45] Fix: Removed System Prints In Testing. --- src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java | 3 --- .../java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java | 1 - .../java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java | 2 -- .../java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java | 1 - .../java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java | 1 - src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java | 1 - src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java | 7 ------- 7 files changed, 16 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 3a4b1b1..18df1f3 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -359,9 +359,6 @@ class GameTest { } assertNotEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer()); - - System.out.println(game); - } private void drawTribeTest(HashMap nCardsByType, diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java index 22347b3..b21cb30 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java @@ -165,6 +165,5 @@ class Order2Test { order.push(p2); order.push(p1); order.pull().getUserName(); - System.out.println(order); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java index 3e24680..60905a5 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java @@ -195,11 +195,9 @@ class Order3Test { userPulled=order.pull().getUserName(); userPulled=order.pull().getUserName(); - System.out.println(values); order.push(p1); order.push(p2); values =(ArrayList)field.get(order); - System.out.println(order); // assertEquals("TURN ORDER\n" + // "╔════════════════════════════════════╦════════════════════════════════════╦════════════════════════════════════╗\n" + // "║ 0. ║ 1. "+values.get(1).getUserName() +"║ 2. "+values.get(2).getUserName()+"║\n" + diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java index 78e731f..58873a0 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java @@ -280,7 +280,6 @@ class Order4Test { Player p4 = new Player("wPIshOThiOpRRnIBFfM89s2$@q$9FGbz"); Order4 order = new Order4(new ArrayList<>(Arrays.asList(p1, p2,p3,p4))); String userPulled=order.pull().getUserName(); - System.out.println(order); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java index 9e838fb..1c97434 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java @@ -381,7 +381,6 @@ class Order5Test { order.pull(); order.pull(); order.push(p1); - System.out.println(order); } } diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java index 1a30d9b..b0fdc51 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java @@ -220,7 +220,6 @@ class PlayerTest { p.buildingCards.add(new Building1(2, 5, 5, CharacterType.INVENTOR)); p.buildingCards.add(new Building1(2, 5, 5, CharacterType.SHAMAN)); p.buildingCards.add(new Building11(1, 5, 7, CharacterType.ARTIST , 3)); - System.out.println(p.toString()); assertEquals(""+ "╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗\n" + "║ test_usr ║\n" + diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java index ca32b35..b307ccc 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java @@ -46,7 +46,6 @@ class SlotTest { assertEquals(0, s.getNLower()); assertEquals(0, s.getNUpper()); assertEquals(5, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @@ -60,7 +59,6 @@ class SlotTest { assertEquals(1, s.getNLower()); assertEquals(0, s.getNUpper()); assertEquals(0, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @@ -74,7 +72,6 @@ class SlotTest { assertEquals(0, s.getNLower()); assertEquals(1, s.getNUpper()); assertEquals(0, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @Test @@ -87,7 +84,6 @@ class SlotTest { assertEquals(2, s.getNLower()); assertEquals(0, s.getNUpper()); assertEquals(3, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @@ -101,7 +97,6 @@ class SlotTest { assertEquals(1, s.getNLower()); assertEquals(1, s.getNUpper()); assertEquals(0, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @@ -115,7 +110,6 @@ class SlotTest { assertEquals(0, s.getNLower()); assertEquals(2, s.getNUpper()); assertEquals(0, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } @@ -129,7 +123,6 @@ class SlotTest { assertEquals(1, s.getNLower()); assertEquals(2, s.getNUpper()); assertEquals(4, s.getNMinPlayer()); - System.out.println(s); assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); } } \ No newline at end of file From ec4fe1cf441a5a71042849800b910233142b9cd5 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 18:36:26 +0200 Subject: [PATCH 26/45] 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 071752e2568a35804fa80f5f085ba7062963696c Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Sat, 2 May 2026 18:39:08 +0200 Subject: [PATCH 27/45] Fix: Fixed "toString" Method Tests In CavePaintingsTest.java, HuntTest.java, ShamanicRitualTest.java, SustenanceTest.java. Fix: Fixed "activateEvent" Method Tests In HuntTest.java, SustenanceTest.java. Fix: Refactor In Sustenance.java. --- .../Cards/TribeCards/Events/Sustenance.java | 2 +- .../TribeCards/Events/CavePaintingsTest.java | 2 +- .../Model/Cards/TribeCards/Events/HuntTest.java | 17 +++++++++++------ .../TribeCards/Events/ShamanicRitualTest.java | 2 +- .../Cards/TribeCards/Events/SustenanceTest.java | 12 ++++++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java index 164f779..add51ff 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java @@ -43,7 +43,7 @@ public class Sustenance extends EventCard { * If the resulting Food debt is positive, the player must pay it with available Food. * If the player does not have enough Food, all remaining Food is removed and the player * loses Prestige equal to the unpaid Food debt multiplied by {@code PrestigeDebt}. - * This event is intended to be executed last among event effects. + * This event is intended to be executed last among event effects. * * @param playerList the list of players affected by the event. * @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}. diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java index d0c695a..df51011 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java @@ -111,6 +111,6 @@ class CavePaintingsTest { void toStringTest() { CavePaintings cv1 = new CavePaintings(1, 1,1,1); - assertEquals("Era:1, CAVE_PAINTINGS", cv1.toString()); + assertEquals("⎕:(Event)CAVE_PAINTINGS", cv1.toString()); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java index c38d1b0..f3b5cdb 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java @@ -41,8 +41,8 @@ class HuntTest { new Hunter(1, false).insert(p2); h1.activateEvent(players); - assertEquals(6, p1.getPrestigeValue()); - assertEquals(2, p1.getFoodValue()); + assertEquals(3*2, p1.getPrestigeValue()); + assertEquals(1+2, p1.getFoodValue()); assertEquals(3, p2.getPrestigeValue()); assertEquals(1, p2.getFoodValue()); } @@ -73,20 +73,25 @@ class HuntTest { ArrayList players = new ArrayList<>(Arrays.asList(p1, p2, p3)); Hunt h1 = new Hunt(1, 3); + assertEquals(0, p1.getFoodValue()); + new Hunter(1, true).insert(p1); new Hunter(1, false).insert(p1); new Hunter(1, false).insert(p2); BuildingCard bc = new BuildingCard(7, 1, 5, 5); p2.addFood(5); + bc.buy(p2); + assertEquals(5 - bc.getPrice(), p2.getFoodValue()); + assertEquals(0, p2.getFoodValue()); new Hunter(1, false).insert(p3); - + assertEquals(0, p3.getFoodValue()); h1.activateEvent(players); - assertEquals(6, p1.getPrestigeValue()); - assertEquals(2, p1.getFoodValue()); + assertEquals(3*2, p1.getPrestigeValue()); + assertEquals(1 + 2, p1.getFoodValue()); assertEquals(4, p2.getPrestigeValue()); assertEquals(2, p2.getFoodValue()); assertEquals(3, p3.getPrestigeValue()); @@ -113,6 +118,6 @@ class HuntTest { void toStringTest() { Hunt h1 = new Hunt(1, 3); - assertEquals("Era:1, HUNT", h1.toString()); + assertEquals("⎕:(Event)HUNT", h1.toString()); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java index 0b7fd6c..f7be0b1 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java @@ -212,6 +212,6 @@ class ShamanicRitualTest { void toStringTest() { ShamanicRitual sr1 = new ShamanicRitual(1, 5,2); - assertEquals("Era:1, SHAMANIC_RITUAL", sr1.toString()); + assertEquals("⎕:(Event)SHAMANIC_RITUAL", sr1.toString()); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java index 7dc452d..2d08763 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java @@ -49,13 +49,13 @@ class SustenanceTest { new Shaman(1, 5).insert(p1); new Builder(1, 5, 5).insert(p1); new Artist(1).insert(p1); - new Hunter(1, true).insert(p1); + new Hunter(1, false).insert(p1); new Gatherer(1).insert(p1); p2.addFood(1); new Artist(1).insert(p2); - new Hunter(1, true).insert(p2); - new Hunter(1, true).insert(p2); + new Hunter(1, false).insert(p2); + new Hunter(1, false).insert(p2); @@ -79,7 +79,7 @@ class SustenanceTest { new Shaman(1, 5).insert(p1); new Builder(1, 5, 5).insert(p1); new Artist(1).insert(p1); - new Hunter(1, true).insert(p1); + new Hunter(1, false).insert(p1); new Gatherer(1).insert(p1); p2.addFood(2); @@ -96,7 +96,7 @@ class SustenanceTest { Sustenance s = new Sustenance(1,2); s.activateEvent(players); - assertEquals(2, p1.getFoodValue()); + assertEquals(3, p1.getFoodValue()); assertEquals(1, p2.getFoodValue()); assertEquals(0, p1.getPrestigeValue()); assertEquals(0, p2.getPrestigeValue()); @@ -122,7 +122,7 @@ class SustenanceTest { void toStringTest() { Sustenance s1 = new Sustenance(1, 5); - assertEquals("Era:1, SUSTENANCE", s1.toString()); + assertEquals("⎕:(Event)SUSTENANCE", s1.toString()); } } From b68cbd8591c473830bd4d1508b75c5f8404e93ba Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 18:44:28 +0200 Subject: [PATCH 28/45] 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 29/45] 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 2ad8a2e2f54f0a16725e297eebc78afb80ccbe32 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 2 May 2026 19:05:31 +0200 Subject: [PATCH 30/45] Add: GameController case tests --- .../gc14/Controller/GameControllerTest.java | 241 +++++++++++++++--- 1 file changed, 208 insertions(+), 33 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java index aa89a2a..ec4ddc8 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java @@ -18,10 +18,7 @@ class GameControllerTest { private Game createStartedGame() { Game game = new Game(3); GameController controller = new GameController(game); - assertEquals( controller.getModel(),game); - controller = new GameController(); - controller.setModel(game); - assertEquals( controller.getModel(),game); + assertTrue(controller.addPlayer("Giorgio")); assertTrue(controller.addPlayer("Marco")); assertTrue(controller.addPlayer("Luca")); @@ -32,7 +29,7 @@ class GameControllerTest { private Queue completeSlotChoice(Game game, GameController controller) { Queue order = new LinkedList<>(); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < game.getNPlayers(); i++) { Player current = game.getCurrentState().getCurrentPlayer(); order.add(current); @@ -92,36 +89,76 @@ class GameControllerTest { private void resolveActionsUntilOptionalCardEffect(Game game, GameController controller) { int guard = 0; - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 20) { + while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 100) { guard++; - - Player current = game.getCurrentState().getCurrentPlayer(); - assertNotNull(current); - - if (game.getCurrentState().getNLower() > 0) { - int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()); - - if (index == -1) { - fail("No non-event lower tribe card available."); - } - - assertTrue(controller.drawLowerTribeCard(current.getUserName(), index)); - } else if (game.getCurrentState().getNUpper() > 0) { - int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()); - - if (index == -1) { - fail("No non-event upper tribe card available."); - } - - assertTrue(controller.drawUpperTribeCard(current.getUserName(), index)); - } else { - fail("Current player has no remaining upper or lower draws."); - } + resolveOneMandatoryAction(game, controller); } assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); } + private void resolveOneMandatoryAction(Game game, GameController controller) { + Player current = game.getCurrentState().getCurrentPlayer(); + assertNotNull(current); + + String username = current.getUserName(); + + if (game.getCurrentState().getNLower() > 0) { + int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()); + + if (index != -1) { + assertTrue(controller.drawLowerTribeCard(username, index)); + return; + } + + if (!game.getLowerListBuilding().isEmpty()) { + current.addFood(100); + assertTrue(controller.drawLowerBuildingCard(username, 0)); + return; + } + + assertTrue(controller.SkipLowerDrawing(username)); + return; + } + + if (game.getCurrentState().getNUpper() > 0) { + int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()); + + if (index != -1) { + assertTrue(controller.drawUpperTribeCard(username, index)); + return; + } + + if (!game.getUpperListBuilding().isEmpty()) { + current.addFood(100); + assertTrue(controller.drawUpperBuildingCard(username, 0)); + return; + } + + assertTrue(controller.SkipUpperDrawing(username)); + return; + } + + fail("Current player has no remaining draw actions."); + } + + private Queue completeSlotChoiceWithSlots(Game game, GameController controller, int... slotIndexes) { + assertEquals(game.getNPlayers(), slotIndexes.length); + + Queue order = new LinkedList<>(); + + for (int i = 0; i < game.getNPlayers(); i++) { + Player current = game.getCurrentState().getCurrentPlayer(); + order.add(current); + + assertTrue(controller.slotChoice(current.getUserName(), slotIndexes[i])); + } + + assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + + return order; + } + @Test void addPlayer() { @@ -150,8 +187,11 @@ class GameControllerTest { assertFalse(controller.drawLowerTribeCard("ghost", 0)); assertFalse(controller.drawUpperBuildingCard("ghost", 0)); assertFalse(controller.drawLowerBuildingCard("ghost", 0)); + assertFalse(controller.SkipUpperDrawing("ghost")); + assertFalse(controller.SkipLowerDrawing("ghost")); assertFalse(controller.pickOptionalTribeCard("ghost", 0)); assertFalse(controller.pickOptionalBuildingCard("ghost", 0)); + assertFalse(controller.noOptionalCard("ghost")); } @Test @@ -243,7 +283,13 @@ class GameControllerTest { Player current = game.getCurrentState().getCurrentPlayer(); - assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0)); + while (current.getFoodValue() > 0) { + assertTrue(current.removeFood(1)); + } + + if (current.builders.isEmpty()) { + assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0)); + } current.addFood(100); int foodBefore = current.getFoodValue(); @@ -251,7 +297,7 @@ class GameControllerTest { assertTrue(controller.drawUpperBuildingCard(current.getUserName(), 0)); - assertTrue(current.getFoodValue() < foodBefore); + assertTrue(current.getFoodValue() <= foodBefore); assertEquals(buildingsBefore + 1, current.buildingCards.size()); } @@ -267,7 +313,7 @@ class GameControllerTest { Queue players = new LinkedList<>(); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < game.getNPlayers(); i++) { Player current = game.getCurrentState().getCurrentPlayer(); players.add(current); @@ -408,7 +454,7 @@ class GameControllerTest { assertTrue(controller.pickOptionalBuildingCard(optionalPlayer.getUserName(), 0)); - assertTrue(optionalPlayer.getFoodValue() < foodBefore); + assertTrue(optionalPlayer.getFoodValue() <= foodBefore); assertEquals(buildingsBefore + 1, optionalPlayer.buildingCards.size()); } @@ -456,4 +502,133 @@ class GameControllerTest { assertFalse(controller.slotChoice(second.getUserName(), 0)); } + + @Test + void noOptionalCardShouldWorkDuringOptionalCardEffectState() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + giveOptionalEffectToAllPlayers(game); + + completeSlotChoice(game, controller); + resolveActionsUntilOptionalCardEffect(game, controller); + + Player optionalPlayer = game.getCurrentState().getCurrentPlayer(); + assertNotNull(optionalPlayer); + + assertTrue(optionalPlayer.buildingCards.stream() + .anyMatch(building -> building.getEffectId() == 12)); + + assertTrue(controller.noOptionalCard(optionalPlayer.getUserName())); + } + + @Test + void constructorsGetModelAndSetModelShouldWork() { + Game game = new Game(3); + + GameController controller = new GameController(game); + assertEquals(game, controller.getModel()); + + GameController emptyController = new GameController(); + emptyController.setModel(game); + assertEquals(game, emptyController.getModel()); + } + + @Test + void slotChoiceShouldReturnFalseForInvalidIndexes() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + Player current = game.getCurrentState().getCurrentPlayer(); + + assertFalse(controller.slotChoice(current.getUserName(), -1)); + assertFalse(controller.slotChoice(current.getUserName(), 999)); + } + + @Test + void optionalCardMethodsShouldReturnFalseForInvalidIndexesDuringOptionalCardEffectState() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + giveOptionalEffectToAllPlayers(game); + + completeSlotChoice(game, controller); + resolveActionsUntilOptionalCardEffect(game, controller); + + Player optionalPlayer = game.getCurrentState().getCurrentPlayer(); + assertNotNull(optionalPlayer); + + String username = optionalPlayer.getUserName(); + + assertFalse(controller.pickOptionalTribeCard(username, -1)); + assertFalse(controller.pickOptionalTribeCard(username, 999)); + + assertFalse(controller.pickOptionalBuildingCard(username, -1)); + assertFalse(controller.pickOptionalBuildingCard(username, 999)); + } + + @Test + void optionalCardMethodsShouldReturnFalseForWrongPlayer() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + giveOptionalEffectToAllPlayers(game); + + completeSlotChoice(game, controller); + resolveActionsUntilOptionalCardEffect(game, controller); + + Player current = game.getCurrentState().getCurrentPlayer(); + assertNotNull(current); + + Player wrongPlayer = game.getPlayers().stream() + .filter(player -> !player.equals(current)) + .findFirst() + .orElse(null); + + assertNotNull(wrongPlayer); + + assertFalse(controller.pickOptionalTribeCard(wrongPlayer.getUserName(), 0)); + assertFalse(controller.pickOptionalBuildingCard(wrongPlayer.getUserName(), 0)); + assertFalse(controller.noOptionalCard(wrongPlayer.getUserName())); + } + + @Test + void skipLowerDrawingShouldReturnFalseWhenLowerCharacterIsAvailable() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + completeSlotChoiceWithSlots(game, controller, 0, 1, 2); + + Player current = game.getCurrentState().getCurrentPlayer(); + assertNotNull(current); + + assertEquals(1, game.getCurrentState().getNLower()); + assertEquals(0, game.getCurrentState().getNUpper()); + + assertFalse(game.getLowerListTribeCards().isEmpty()); + assertTrue(firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1); + + assertFalse(controller.SkipLowerDrawing(current.getUserName())); + } + + @Test + void skipUpperDrawingShouldReturnFalseWhenUpperCharacterIsAvailable() { + Game game = createStartedGame(); + GameController controller = new GameController(game); + + completeSlotChoiceWithSlots(game, controller, 1, 2, 3); + + Player current = game.getCurrentState().getCurrentPlayer(); + assertNotNull(current); + + assertEquals(0, game.getCurrentState().getNLower()); + assertEquals(1, game.getCurrentState().getNUpper()); + + assertFalse(game.getUpperListTribeCards().isEmpty()); + assertTrue(firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1); + + assertFalse(controller.SkipUpperDrawing(current.getUserName())); + } + + } From dc18a650780913cc2a7dba88423b90a7ec171259 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:05:51 +0200 Subject: [PATCH 31/45] Microfix: add break in TCP client if connection fails --- .../it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java index 3408e99..f3a34e2 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java @@ -99,10 +99,9 @@ public class TCPClient implements IClient { controller.setModel(model); controller.view.render(); } - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + break; } } } From 4a69e2c8dbd4ff732fce105f8041f19a840b2bb0 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:12:47 +0200 Subject: [PATCH 32/45] 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 aab2f16b98e36fd4e7e0eae6a259f9ad7b8cfd83 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 19:20:41 +0200 Subject: [PATCH 33/45] Fix: End Game Logic --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 35 +++++++++++++++++-- 1 file changed, 33 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 f3d1117..94f27cf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -4,6 +4,9 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType; import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import it.polimi.ingsw.gc14.Model.Cards.TribeCard; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType; import it.polimi.ingsw.gc14.Model.GamePackage.Board; @@ -17,6 +20,8 @@ import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; + import it.polimi.ingsw.gc14.Network.Observer; import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.BorderStyle; @@ -691,7 +696,6 @@ public class Game implements Serializable { currentState.PlayerUpdate(orderLogicCard.pull(), null); currentState.GameStageUpdate(GameStages.SLOT_CHOICE); } else { - EventResolution(); currentState.GameStageUpdate(GameStages.ENDING); endGame(); } @@ -715,7 +719,6 @@ public class Game implements Serializable { currentState.PlayerUpdate(orderLogicCard.pull(), null); currentState.GameStageUpdate(GameStages.SLOT_CHOICE); } else { - EventResolution(); currentState.GameStageUpdate(GameStages.ENDING); endGame(); } @@ -808,6 +811,34 @@ public class Game implements Serializable { * and updating the game stage to {@code ENDED}. */ private void endGame() { + Queue events; + events=Stream.concat(board.lowerListTribe.stream().filter(x->!x.IsEventCard()),board.upperListTribe.stream().filter(x->!x.IsEventCard())).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new)); + ArrayListsustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new)); + events.removeAll(sustenance); + for(EventCard event:events) + { + event.activateEvent(playersList); + } + + for(EventCard e : sustenance) + { + e.activateEvent(playersList); + } + playersList.forEach(p->{ + int temp= p.builders.stream().mapToInt(Builder::getPrestigeValue).sum(); + p.addPrestige(temp); + }); + playersList.forEach(p->{ + int temp=(int) p.inventors.stream().mapToInt(Inventor::Icon).distinct().count(); + p.addPrestige(temp*p.getNType(CharacterType.INVENTOR)); + }); + playersList.forEach(p->{ + p.addPrestige(10 * (p.getNType(CharacterType.ARTIST)/2)); + }); + playersList.forEach(p->{ + int temp= p.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum(); + p.addPrestige(temp); + }); playersList.forEach( p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL). forEach(x -> x.applyEffect(p)) From 4fdb99167eef6ed0df4d6be1d76beb845e7562e2 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:22:12 +0200 Subject: [PATCH 34/45] 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 fc15a3a15b24175d21d0d235466bda4f045f9bf6 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 2 May 2026 19:35:03 +0200 Subject: [PATCH 35/45] Fix: error managing in TCP client --- .../ingsw/gc14/Network/TCP/Client/TCPClient.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java index f3a34e2..cfcee1e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java @@ -87,7 +87,14 @@ public class TCPClient implements IClient { private void receiveMessage() { while (true) { try { - Object read = socketReceive.readObject(); + Object read; + try { + read = socketReceive.readObject(); + } catch (IOException e) { + e.printStackTrace(); + break; + } + if (read instanceof NetworkEvent event) { //TODO: avoid instanceof if (event.getIsError()) { System.out.println(event); @@ -99,7 +106,7 @@ public class TCPClient implements IClient { controller.setModel(model); controller.view.render(); } - } catch (Exception e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); break; } From 4afe4b25b9805336965e35118a70e6a10cd413ef Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 19:44:34 +0200 Subject: [PATCH 36/45] Fix:EndGame #2 --- .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ src/main/java/it/polimi/ingsw/gc14/Model/Game.java | 12 +++--------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..40155f0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index 94f27cf..a9410f7 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -812,18 +812,12 @@ public class Game implements Serializable { */ private void endGame() { Queue events; - events=Stream.concat(board.lowerListTribe.stream().filter(x->!x.IsEventCard()),board.upperListTribe.stream().filter(x->!x.IsEventCard())).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new)); + events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::IsEventCard),board.upperListTribe.stream().filter(TribeCard::IsEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new)); ArrayListsustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new)); events.removeAll(sustenance); - for(EventCard event:events) - { - event.activateEvent(playersList); - } + events.forEach(event->event.activateEvent(playersList)); + sustenance.forEach(event->event.activateEvent(playersList)); - for(EventCard e : sustenance) - { - e.activateEvent(playersList); - } playersList.forEach(p->{ int temp= p.builders.stream().mapToInt(Builder::getPrestigeValue).sum(); p.addPrestige(temp); From 918b056d4c1932df5f15c136fa157e5409a29234 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sat, 2 May 2026 19:51:12 +0200 Subject: [PATCH 37/45] Removed: Observer --- .../ingsw/gc14/Controller/ClientController.java | 2 -- src/main/java/it/polimi/ingsw/gc14/Model/Game.java | 13 ------------- .../java/it/polimi/ingsw/gc14/Network/Observer.java | 7 ------- 3 files changed, 22 deletions(-) delete mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/Observer.java 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 144435f..5c2070b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -1,10 +1,8 @@ package it.polimi.ingsw.gc14.Controller; import it.polimi.ingsw.gc14.Model.Game; -import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvents.*; -import it.polimi.ingsw.gc14.Network.Observer; import it.polimi.ingsw.gc14.View.IView; /** 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 a9410f7..bc777d2 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -22,7 +22,6 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; -import it.polimi.ingsw.gc14.Network.Observer; import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.BorderStyle; @@ -33,18 +32,6 @@ import it.polimi.ingsw.gc14.View.TUI.BorderStyle; */ public class Game implements Serializable { - private transient List observers = new ArrayList<>(); // transient! non serializzare - - public void addObserver(Observer observer) { - observers.add(observer); - } - - private void notifyObservers() { - for (Observer o : observers) { - o.update(this); - } - } - /** * Returns the list of players participating in the game. * @return diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java b/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java deleted file mode 100644 index 7677d92..0000000 --- a/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.polimi.ingsw.gc14.Network; - -import it.polimi.ingsw.gc14.Model.Game; - -public interface Observer { - public void update(Game model); -} From be27500eafccd070a16113f6f2300c38c51596c9 Mon Sep 17 00:00:00 2001 From: MatteoPellegrino05 Date: Sat, 2 May 2026 20:13:02 +0200 Subject: [PATCH 38/45] Add: Improve game flow and endgame tests --- .../it/polimi/ingsw/gc14/Model/GameTest.java | 183 ++++++++++++++++-- 1 file changed, 163 insertions(+), 20 deletions(-) diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 18df1f3..0e4f2a7 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -5,6 +5,9 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCard; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character; import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType; import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -77,9 +80,8 @@ class GameTest { return; } - if (!game.getLowerListBuilding().isEmpty()) { - current.addFood(100); - assertTrue(game.DrawLowerBuildingCardByIndex(current, 0)); + if (!game.getLowerListBuilding().isEmpty() + && game.DrawLowerBuildingCardByIndex(current, 0)) { return; } @@ -95,9 +97,8 @@ class GameTest { return; } - if (!game.getUpperListBuilding().isEmpty()) { - current.addFood(100); - assertTrue(game.DrawUpperBuildingCardByIndex(current, 0)); + if (!game.getUpperListBuilding().isEmpty() + && game.DrawUpperBuildingCardByIndex(current, 0)) { return; } @@ -294,7 +295,7 @@ class GameTest { assertTrue(game.addPlayer(p3)); Queue players = new LinkedList<>(); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < game.getNPlayers(); i++) { players.add(game.getCurrentState().getCurrentPlayer()); assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i)); } @@ -337,11 +338,14 @@ class GameTest { assertFalse(game.DrawUpperTribeCardByIndex(temp_player, eventIndex)); } - temp_player.addFood(100); - assertFalse(game.getUpperListBuilding().isEmpty()); + temp_player.builders.clear(); + index = 0; + BuildingCard selectedBuilding = game.getUpperListBuilding().get(index); + temp_player.addFood(selectedBuilding.getPrice()); + assertTrue(game.DrawUpperBuildingCardByIndex(temp_player, index)); int remainingTribeIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()); @@ -445,15 +449,30 @@ class GameTest { assertFalse(game.getUpperListBuilding().isEmpty()); - current.addFood(100); + current.builders.clear(); + + BuildingCard selectedBuilding = game.getUpperListBuilding().get(0); + int expectedCost = selectedBuilding.getPrice(); + + current.addFood(expectedCost); - int foodBefore = current.getFoodValue(); int buildingsBefore = current.buildingCards.size(); + int upperBuildingsBefore = game.getUpperListBuilding().size(); + int foodBefore = current.getFoodValue(); assertTrue(game.PickOptionalBuildingCard(current, 0)); - assertTrue(current.getFoodValue() < foodBefore); assertEquals(buildingsBefore + 1, current.buildingCards.size()); + assertEquals(upperBuildingsBefore - 1, game.getUpperListBuilding().size()); + + assertTrue(current.buildingCards.stream() + .anyMatch(building -> + building.getPrice() == selectedBuilding.getPrice() + && building.getPrestigeValue() == selectedBuilding.getPrestigeValue() + && building.getEffectId() == selectedBuilding.getEffectId() + )); + + assertEquals(foodBefore - expectedCost, current.getFoodValue()); } @Test @@ -807,6 +826,8 @@ class GameTest { assertTrue(current.removeFood(1)); } + current.builders.clear(); + assertEquals(0, current.getFoodValue()); assertFalse( @@ -816,6 +837,7 @@ class GameTest { assertFalse(game.PickOptionalBuildingCard(current, 0)); } + @Test void toStringModel() { Game game=new Game(5); @@ -832,8 +854,8 @@ class GameTest { assertTrue(game.addPlayer(p5)); Queueplayers=new LinkedList<>(); - for(int i=0;i<3;i++) { - players.add( game.getCurrentState().getCurrentPlayer()); + for (int i = 0; i < game.getNPlayers(); i++) { + players.add(game.getCurrentState().getCurrentPlayer()); assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i)); } @@ -864,7 +886,12 @@ class GameTest { if (game.getCurrentState().getNLower() > 0 && !game.getLowerListBuilding().isEmpty()) { - current.addFood(100); + current.builders.clear(); + + BuildingCard selectedBuilding = game.getLowerListBuilding().get(0); + int expectedCost = selectedBuilding.getPrice(); + + current.addFood(expectedCost); int buildingsBefore = current.buildingCards.size(); int lowerBuildingsBefore = game.getLowerListBuilding().size(); @@ -877,8 +904,16 @@ class GameTest { assertEquals(buildingsBefore + 1, current.buildingCards.size()); assertEquals(lowerBuildingsBefore - 1, game.getLowerListBuilding().size()); - assertTrue(current.getFoodValue() < foodBefore); - + assertTrue(current.buildingCards.stream() + .anyMatch(building -> + building.getPrice() == selectedBuilding.getPrice() + && building.getPrestigeValue() == selectedBuilding.getPrestigeValue() + && building.getEffectId() == selectedBuilding.getEffectId() + )); + assertTrue( + current.getFoodValue() >= foodBefore - expectedCost, + "After buying the building, food should not be lower than the price paid because later effects may add food." + ); return; } @@ -908,14 +943,16 @@ class GameTest { Player current = game.getCurrentState().getCurrentPlayer(); if (game.getCurrentState().getNUpper() > 0 - && !game.getUpperListBuilding().isEmpty() - && current.builders.isEmpty()) { + && !game.getUpperListBuilding().isEmpty()) { while (current.getFoodValue() > 0) { assertTrue(current.removeFood(1)); } + current.builders.clear(); + assertEquals(0, current.getFoodValue()); + assertFalse(game.DrawUpperBuildingCardByIndex(current, 0)); return; } @@ -923,7 +960,7 @@ class GameTest { resolveOneMandatoryAction(game); } - fail("No upper building draw state reached with a player without builders."); + fail("No upper building draw state reached."); } @Test @@ -952,4 +989,110 @@ class GameTest { assertEquals(firstChooser, game.getCurrentState().getCurrentPlayer()); } + + @Test + @Timeout(value = 20, unit = TimeUnit.SECONDS) + void endGameShouldNotCrashWhenTriggeredAfterRoundTen() { + Game game = new Game(3); + + List players = addPlayers(game, 3, "end_game_"); + + giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2)); + + while (game.getCurrentState().getRound() < 10) { + playOneFullRound(game); + } + + assertEquals(10, game.getCurrentState().getRound()); + assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage()); + + completeSlotChoice(game); + resolveAllMandatoryActions(game); + + assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + + assertDoesNotThrow(() -> resolveOptionalPhaseIfPresent(game)); + + assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage()); + } + + @Test + @Timeout(value = 20, unit = TimeUnit.SECONDS) + void endGameShouldAddBuildingPrestigeValues() { + Game game = new Game(3); + + List players = addPlayers(game, 3, "building_prestige_"); + + giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2)); + + while (game.getCurrentState().getRound() < 10) { + playOneFullRound(game); + } + + completeSlotChoice(game); + resolveAllMandatoryActions(game); + + assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + + Player player = players.get(0); + + int prestigeBefore = player.getPrestigeValue(); + + player.buildingCards.add(new BuildingCard(12, 1, 1, 7)); + player.buildingCards.add(new BuildingCard(12, 1, 1, 5)); + + int expectedMinimumIncrease = 7 + 5; + + resolveOptionalPhaseIfPresent(game); + + assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage()); + + assertTrue( + player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease, + "Final scoring should add at least the prestige values of the two added building cards." + ); + } + + @Test + @Timeout(value = 20, unit = TimeUnit.SECONDS) + void endGameShouldApplyFinalCharacterPrestigeBonuses() { + Game game = new Game(3); + + List players = addPlayers(game, 3, "final_characters_"); + giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2)); + + while (game.getCurrentState().getRound() < 10) { + playOneFullRound(game); + } + + completeSlotChoice(game); + resolveAllMandatoryActions(game); + + assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + + Player player = players.get(0); + assertNotNull(player); + + int prestigeBefore = player.getPrestigeValue(); + + player.builders.add(new Builder(1, 0, 4)); + + player.inventors.add(new Inventor(1, 0)); + player.inventors.add(new Inventor(1, 1)); + + player.artists.add(new Artist(1)); + player.artists.add(new Artist(1)); + + int expectedMinimumIncrease = 4 + 4 + 10; + + resolveOptionalPhaseIfPresent(game); + + assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage()); + + assertTrue( + player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease, + "Final scoring should add at least builder prestige, inventor bonus, and artist pair bonus." + ); + } + } \ No newline at end of file From 3c2cf38f34c6ec21262c527f26bf5a24346f6b2e Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 15:12:51 +0200 Subject: [PATCH 39/45] Fix: building8 effect --- .../ingsw/gc14/Model/Cards/Building/Effects/Building8.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java index d67017d..0c4db48 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java @@ -42,7 +42,7 @@ public class Building8 extends BuildingCard { if(!player.buildingCards.contains(this)) throw new IllegalArgumentException(); for (Builder builder : player.builders) { - player.addPrestige(builder.getPrestigeValue() * 2); + player.addPrestige(builder.getPrestigeValue()); } } From c1092a2afaa5bc6d6385dd0a2d06db4d12220c01 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sun, 3 May 2026 15:20:40 +0200 Subject: [PATCH 40/45] Fix: Changed print in English. Add: request for server IP --- .../java/it/polimi/ingsw/gc14/ClientLauncherTUI.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 1d2623c..77b7b87 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -31,17 +31,19 @@ public class ClientLauncherTUI { view = new TUI(null); ClientController controller = new ClientController(view); Scanner scanner = new Scanner(System.in); - System.out.println("Selezionare nome utente: "); + System.out.println("Insert username: "); String username = scanner.next(); view.setUsername(username); - System.out.println("Selezionare numero di giocatori desiderato: "); + System.out.println("Insert preferred number of players: "); int proposedNumPlayers = scanner.nextInt(); - System.out.println("Selezionare RMI[0] o TCP[1]: "); + System.out.println("Select RMI[0] o TCP[1]: "); int networkType = scanner.nextInt(); + System.out.println("Insert server IP: "); + String IP = scanner.next(); // RMI if (networkType == 0) { // Connect - RMIClient client = new RMIClient(controller, "localhost", 1099); + RMIClient client = new RMIClient(controller, IP, 1099); if (client.connect(username, proposedNumPlayers)) { System.out.println("Succesfully connected to RMI server\n\n"); } else { @@ -55,7 +57,7 @@ public class ClientLauncherTUI { // TCP } else if (networkType == 1) { // Connect - TCPClient client = new TCPClient(controller, "localhost", 8080); + TCPClient client = new TCPClient(controller, IP, 8080); if (client.connect(username, proposedNumPlayers)) { System.out.println("Succesfully connected to TCP server\n\n"); } else { From 55c8e38ceb5435e2e112af5c3f4c8b341093ac99 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sun, 3 May 2026 15:33:57 +0200 Subject: [PATCH 41/45] Fix: Firewall blocks RMI connection --- src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index 252a9da..935a7b9 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -123,6 +123,7 @@ public class ServerLauncher { }).start(); }); + System.setProperty("java.rmi.server.port", "1100"); serverRMI.start(); new Thread(()->{serverTCP.start();}).start(); } From 2148dc3a095ddb1568c6b30cd0d9fd20ab5994c6 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 15:44:32 +0200 Subject: [PATCH 42/45] RMI START Changed --- src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index 935a7b9..252a9da 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -123,7 +123,6 @@ public class ServerLauncher { }).start(); }); - System.setProperty("java.rmi.server.port", "1100"); serverRMI.start(); new Thread(()->{serverTCP.start();}).start(); } From 6afbc4493ba741876d02b4192802b2411a16297e Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 16:03:11 +0200 Subject: [PATCH 43/45] TEST ASCII --- .../java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java index 13b365d..6a3e11e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java @@ -1,9 +1,11 @@ package it.polimi.ingsw.gc14.View.TUI; public enum BorderStyle { - UNICODE("╔","╗","╚","╝","═","║","╠","╣","╦","╩","╬","├","┤","─","┼"), - ASCII ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+"), - ROUNDED("╭","╮","╰","╯","─","│","├","┤","┬","┴","┼","├","┤","─","┼"); + + //UNICODE("╔","╗","╚","╝","═","║","╠","╣","╦","╩","╬","├","┤","─","┼"), + UNICODE ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+"), + ROUNDED ("+","+","+","+","-","|","+","+","+","+","+","+","+","-","+"); + //ROUNDED("╭","╮","╰","╯","─","│","├","┤","┬","┴","┼","├","┤","─","┼"); private final String tl,tr,bl,br,h,v,ml,mr,mt,mb,x,sl,sr,sh,sx; From e50cf43b737d84ec74fb45d48b0dbc3fd400b4ed Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 17:19:47 +0200 Subject: [PATCH 44/45] FIx: case sensitive --- .../polimi/ingsw/gc14/ClientLauncherTUI.java | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 77b7b87..2094aba 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -4,6 +4,9 @@ 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.ArrayList; +import java.util.List; import java.util.Scanner; /** @@ -14,6 +17,8 @@ import java.util.Scanner; */ public class ClientLauncherTUI { + List admissibleChar=new ArrayList<>(); + /** * The TUI view associated with this client. */ @@ -29,6 +34,23 @@ public class ClientLauncherTUI { */ public void main() throws InterruptedException { view = new TUI(null); + admissibleChar.add("0"); + admissibleChar.add("1"); + admissibleChar.add("2"); + admissibleChar.add("3"); + admissibleChar.add("4"); + admissibleChar.add("5"); + admissibleChar.add("6"); + admissibleChar.add("7"); + admissibleChar.add("8"); + admissibleChar.add("9"); + admissibleChar.add("A"); + admissibleChar.add("B"); + admissibleChar.add("C"); + admissibleChar.add("a"); + admissibleChar.add("b"); + admissibleChar.add("c"); + ClientController controller = new ClientController(view); Scanner scanner = new Scanner(System.in); System.out.println("Insert username: "); @@ -103,29 +125,37 @@ public class ClientLauncherTUI { 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 { - System.out.println("Insert the required position:"); - pos = scanner.nextInt(); - } catch (Exception e) { - System.out.println("ERROR: Invalid input(expected number)"); + + if(admissibleChar.contains(username)) + { + if (!action.equals("7") && !action.equals("8") && !action.equals("9") && !action.equals("A") && !action.equals("B") && !action.equals("C")) { + try { + System.out.println("Insert the required position:"); + pos = scanner.nextInt(); + } catch (Exception e) { + System.out.println("ERROR: Invalid input(expected number)"); + } + } + switch (action) { + case "0" -> controller.slotChoice(username, pos); + case "1" -> controller.drawUpperTribeCard(username, pos); + case "2" -> controller.drawUpperBuildingCard(username, pos); + case "3" -> controller.drawLowerTribeCard(username, pos); + case "4" -> controller.drawLowerBuildingCard(username, pos); + case "5" -> controller.pickOptionalTribeCard(username, pos); + case "6" -> controller.pickOptionalBuildingCard(username, pos); + case "7" -> controller.noOptionalCard(username); + case "8" -> controller.skipUpper(username); + case "9" -> controller.skipLower(username); + case "A", "a" -> view.fullRender(); + case "B", "b" -> view.renderBoard(); + case "C", "c" -> view.renderPlayer(); + default -> {} } } - switch (action) { - case "0" -> controller.slotChoice(username, pos); - case "1" -> controller.drawUpperTribeCard(username, pos); - case "2" -> controller.drawUpperBuildingCard(username, pos); - case "3" -> controller.drawLowerTribeCard(username, pos); - case "4" -> controller.drawLowerBuildingCard(username, pos); - case "5" -> controller.pickOptionalTribeCard(username, pos); - case "6" -> controller.pickOptionalBuildingCard(username, pos); - case "7" -> controller.noOptionalCard(username); - case "8" -> controller.skipUpper(username); - case "9" -> controller.skipLower(username); - case "A" -> view.fullRender(); - case "B" -> view.renderBoard(); - case "C" -> view.renderPlayer(); - default -> {} + else + { + System.out.println("ERROR: Invalid input(action not valid)"); } } } \ No newline at end of file From 7e8421387d033a6022387d99528c217fc9399ef2 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 17:43:52 +0200 Subject: [PATCH 45/45] Fix: Game Init --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 46 ++++++++++++------- .../gc14/Model/GamePackage/GameStages.java | 2 +- .../gc14/Controller/GameControllerTest.java | 14 +++--- .../Model/GamePackage/CurrentStateTest.java | 6 +-- .../it/polimi/ingsw/gc14/Model/GameTest.java | 34 +++++++------- 5 files changed, 58 insertions(+), 44 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 bc777d2..01b43b2 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -232,6 +232,16 @@ public class Game implements Serializable { orderLogicCard=new Order5(playersList); break; } + for(Player player : playersList) + { + switch(orderLogicCard.getPosition(player.getUserName())) + { + case 0: player.addFood(2); break; + case 1,2: player.addFood(3); break; + case 3,4: player.addFood(4); break; + } + + } currentState.PlayerUpdate(orderLogicCard.pull(),null); currentState.GameStageUpdate(GameStages.SLOT_CHOICE); } @@ -264,6 +274,10 @@ public class Game implements Serializable { { return false; } + if(slotPlayerEntry.getKey().getSlotId()=='A') + { + player.addFood(3); + } slotMap.put(slotPlayerEntry.getKey(),player); nextPlayerSetup(); return true; @@ -288,7 +302,7 @@ public class Game implements Serializable { public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.upperListTribe.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -324,7 +338,7 @@ public class Game implements Serializable { * @return {@code true} if the skip succeeds, {@code false} otherwise. */ public boolean SkipUpperDrawing(Player player) { - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -355,7 +369,7 @@ public class Game implements Serializable { * @return {@code true} if the skip succeeds, {@code false} otherwise. */ public boolean SkipLowerDrawing(Player player) { - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -389,7 +403,7 @@ public class Game implements Serializable { public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) { if( cardIndex<0 || cardIndex >=board.lowerListTribe.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -430,7 +444,7 @@ public class Game implements Serializable { public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.upperListBuilding.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -469,7 +483,7 @@ public class Game implements Serializable { public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -514,7 +528,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean PickOptionalTribeCardByIndex(Player player,int cardIndex) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -549,7 +563,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean PickOptionalBuildingCard(Player player, int cardIndex) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -581,7 +595,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean NoOptionalCard(Player player) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -620,7 +634,7 @@ public class Game implements Serializable { currentState.PlayerUpdate(tempPlayer, null); return; } - currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS); + currentState.GameStageUpdate(GameStages.RES_ACTIONS); for (Slot s : slotMap.keySet()) { if (slotMap.get(s) != null) { currentState.PlayerUpdate(slotMap.get(s), s); @@ -636,7 +650,7 @@ public class Game implements Serializable { return; } - if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) { + if(GameStages.RES_ACTIONS ==currentState.getGameStage()) { orderLogicCard.push(currentState.getCurrentPlayer()); slotMap.put(currentState.getSlot(), null); for (Slot s : slotMap.keySet()) { @@ -655,7 +669,7 @@ public class Game implements Serializable { } if(slotMap.values().stream().allMatch(v -> v == null)) { - currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT); + currentState.GameStageUpdate(GameStages.OPT_CARD_E); HashMap optional=new LinkedHashMap<>(); for (Player p : orderLogicCard.players) { int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count(); @@ -676,7 +690,7 @@ public class Game implements Serializable { return; } - currentState.GameStageUpdate(GameStages.RESOLVING_EVENT); + currentState.GameStageUpdate(GameStages.RES_EVENT); if (currentState.getRound() < 10) { nextRound(); @@ -691,7 +705,7 @@ public class Game implements Serializable { } } - if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) { + if (GameStages.OPT_CARD_E == currentState.getGameStage()) { Player optionalPlayer = OptionalCardQueue.poll(); if (optionalPlayer != null) { @@ -699,7 +713,7 @@ public class Game implements Serializable { return; } - currentState.GameStageUpdate(GameStages.RESOLVING_EVENT); + currentState.GameStageUpdate(GameStages.RES_EVENT); if (currentState.getRound() < 10) { nextRound(); @@ -748,7 +762,7 @@ public class Game implements Serializable { */ private void EventResolution() { - if(currentState.getGameStage()!= GameStages.RESOLVING_EVENT) + if(currentState.getGameStage()!= GameStages.RES_EVENT) { return; } 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 97e8fa3..61c8a74 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, RES_ACTIONS, OPT_CARD_E, RES_EVENT, ENDING, ENDED } diff --git a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java index ec4ddc8..3e95055 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java @@ -36,7 +36,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -89,12 +89,12 @@ class GameControllerTest { private void resolveActionsUntilOptionalCardEffect(Game game, GameController controller) { int guard = 0; - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 100) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && guard < 100) { guard++; resolveOneMandatoryAction(game, controller); } - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } private void resolveOneMandatoryAction(Game game, GameController controller) { @@ -154,7 +154,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), slotIndexes[i])); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -206,7 +206,7 @@ class GameControllerTest { Queue order = completeSlotChoice(game, controller); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); assertEquals(order.poll(), game.getCurrentState().getCurrentPlayer()); } @@ -320,7 +320,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); Player tempPlayer = players.poll(); assertNotNull(tempPlayer); @@ -395,7 +395,7 @@ class GameControllerTest { completeSlotChoice(game, controller); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); String cur = game.getCurrentState().getCurrentPlayer().getUserName(); diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java index b07549a..6fe34e9 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java @@ -70,7 +70,7 @@ class CurrentStateTest { void getGameStage() { Player p = new Player("test"); Slot s = new Slot('A'); - GameStages g = GameStages.RESOLVING_ACTIONS; + GameStages g = GameStages.RES_ACTIONS; CurrentState curr = new CurrentState(); curr.PlayerUpdate(p, s); curr.GameStageUpdate(g); @@ -122,12 +122,12 @@ class CurrentStateTest { void gameStageUpdate() { Player p = new Player("test"); Slot s = new Slot('A'); - GameStages g = GameStages.RESOLVING_ACTIONS; + GameStages g = GameStages.RES_ACTIONS; CurrentState curr = new CurrentState(); assertEquals(GameStages.WAITING, curr.getGameStage()); curr.PlayerUpdate(p, s); curr.GameStageUpdate(g); - assertEquals(GameStages.RESOLVING_ACTIONS, curr.getGameStage()); + assertEquals(GameStages.RES_ACTIONS, curr.getGameStage()); } @Test diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 0e4f2a7..dd11d00 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -30,7 +30,7 @@ class GameTest { assertTrue(game.SlotChoiceByIndex(current, i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -63,7 +63,7 @@ class GameTest { } private void resolveAllMandatoryActions(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { resolveOneMandatoryAction(game); } } @@ -126,15 +126,15 @@ class GameTest { } private void resolveActionsUntilOptionalCardEffect(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { resolveOneMandatoryAction(game); } - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } private void resolveOptionalPhaseIfPresent(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) { + while (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) { Player current = game.getCurrentState().getCurrentPlayer(); assertNotNull(current); @@ -147,7 +147,7 @@ class GameTest { completeSlotChoice(game); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); resolveAllMandatoryActions(game); @@ -157,7 +157,7 @@ class GameTest { private void resolveCurrentPlayerCompletely(Game game, Player expectedPlayer) { assertEquals(expectedPlayer, game.getCurrentState().getCurrentPlayer()); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && expectedPlayer.equals(game.getCurrentState().getCurrentPlayer())) { resolveOneMandatoryAction(game); } @@ -357,7 +357,7 @@ class GameTest { assertNotNull(thirdPlayer); assertEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer()); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && thirdPlayer.equals(game.getCurrentState().getCurrentPlayer())) { resolveOneMandatoryAction(game); } @@ -497,7 +497,7 @@ class GameTest { assertTrue(game.NoOptionalCard(current)); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertNotEquals(current, game.getCurrentState().getCurrentPlayer()); } @@ -662,7 +662,7 @@ class GameTest { assertDoesNotThrow(() -> resolveAllMandatoryActions(game)); - assertNotEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertNotEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } @@ -879,7 +879,7 @@ class GameTest { completeSlotChoice(game); } - if (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + if (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { Player current = game.getCurrentState().getCurrentPlayer(); assertNotNull(current); @@ -920,7 +920,7 @@ class GameTest { resolveOneMandatoryAction(game); } - if (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) { + if (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) { resolveOptionalPhaseIfPresent(game); } @@ -939,7 +939,7 @@ class GameTest { completeSlotChoice(game); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { Player current = game.getCurrentState().getCurrentPlayer(); if (game.getCurrentState().getNUpper() > 0 @@ -977,7 +977,7 @@ class GameTest { Player thirdChooser = game.getCurrentState().getCurrentPlayer(); assertTrue(game.SlotChoiceByIndex(thirdChooser, 1)); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); assertEquals(secondChooser, game.getCurrentState().getCurrentPlayer()); @@ -1009,7 +1009,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertDoesNotThrow(() -> resolveOptionalPhaseIfPresent(game)); @@ -1032,7 +1032,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); Player player = players.get(0); @@ -1068,7 +1068,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); Player player = players.get(0); assertNotNull(player);