lines2=List.of((PrintMenuOptions()+"\n"+model.getPlayerByUsername(username)).split("\n"));
- System.out.println(model.PlayersStamp()+"\n"+ AsciiTable.sideBySide(lines,lines2,3));
+ /**
+ * Renders a full view of the game, combining both player status
+ * and board status.
+ *
+ * Layout:
+ *
+ * - Top — player status table produced by
+ * {@link Game#PlayersStamp()}.
+ * - Bottom-left — board status produced by
+ * {@link Game#BoardStamp()}.
+ * - Bottom-right — menu options legend and the local
+ * player's hand.
+ *
+ *
+ * The terminal is cleared before rendering.
+ */
+ public void fullRender() {
+ clearTerminal();
+ List lines = List.of(model.BoardStamp().split("\n"));
+ List lines2 = List.of((printMenuOptions() + "\n" +
+ model.getPlayerByUsername(username)).split("\n"));
+ System.out.println(model.PlayersStamp() + "\n" +
+ AsciiTable.sideBySide(lines, lines2, 3));
}
- public void renderBoard()
- {
- try{
- String os = System.getProperty("os.name").toLowerCase();
- ProcessBuilder pb;
- if (os.contains("win")) {
- pb = new ProcessBuilder("cmd", "/c", "cls");
- } else {
- pb = new ProcessBuilder("clear");
- }
- pb.inheritIO().start().waitFor();
- }
- catch(Exception e){
- }
- Listlines=List.of(model.BoardStamp().split("\n"));
- List lines2=List.of((PrintMenuOptions()+"\nYOUR HAND\n"+model.getPlayerByUsername(username)).split("\n"));
- System.out.println(AsciiTable.sideBySide(lines,lines2,3));
- }
- public void renderPlayer()
- {
- try{
- String os = System.getProperty("os.name").toLowerCase();
- ProcessBuilder pb;
- if (os.contains("win")) {
- pb = new ProcessBuilder("cmd", "/c", "cls");
- } else {
- pb = new ProcessBuilder("clear");
- }
- pb.inheritIO().start().waitFor();
- }
- catch(Exception e){
- }
- Listlines=List.of(model.PlayersStamp().split("\n"));
- List lines2=List.of(PrintMenuOptions().split("\n"));
- System.out.println(AsciiTable.sideBySide(lines,lines2,3));
+ /**
+ * Renders the board status only.
+ *
+ * Layout:
+ *
+ * - Left panel — turn order, upper card row, offer track,
+ * and lower card row, as produced by {@link Game#BoardStamp()}.
+ * - Right panel — menu options legend followed by the local
+ * player's hand.
+ *
+ *
+ * The terminal is cleared before rendering.
+ */
+ public void renderBoard() {
+ clearTerminal();
+ List lines = List.of(model.BoardStamp().split("\n"));
+ List lines2 = List.of((printMenuOptions() + "\nYOUR HAND\n" +
+ model.getPlayerByUsername(username)).split("\n"));
+ System.out.println(AsciiTable.sideBySide(lines, lines2, 3));
}
- public void showMessage(String message)
- {
+ /**
+ * Renders the player status table only.
+ *
+ * Layout:
+ *
+ * - Left panel — prestige, food, character deck, and building
+ * deck for all players, as produced by {@link Game#PlayersStamp()}.
+ * - Right panel — menu options legend.
+ *
+ *
+ * The terminal is cleared before rendering.
+ */
+ public void renderPlayer() {
+ clearTerminal();
+ List lines = List.of(model.PlayersStamp().split("\n"));
+ List lines2 = List.of(printMenuOptions().split("\n"));
+ System.out.println(AsciiTable.sideBySide(lines, lines2, 3));
+ }
+
+ /**
+ * Prints a plain message to standard output.
+ *
+ * @param message the message to display
+ */
+ public void showMessage(String message) {
System.out.println(message);
}
-
- public void showError(String message)
- {
+ /**
+ * Prints an error message to standard output.
+ *
+ * @param message the error message to display
+ */
+ public void showError(String message) {
+ clearTerminal();
+ render();
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",""));
+ /**
+ * Builds and returns the menu options panel as a two-column
+ * {@link AsciiTable} with rounded borders.
+ *
+ * The left column lists game action commands (slot choice, draw, pick…),
+ * the right column lists render shortcuts (full, board, players).
+ *
+ * @return the rendered menu table as a multi-line string
+ */
+ private String printMenuOptions() {
+ var table = new AsciiTable(BorderStyle.ROUNDED, 2);
+ table.addHeader("Menu Options", "Render Options");
+ table.addRow(List.of("0-SlotChoice(pos)", "A-Full Render"));
+ table.addRow(List.of("1-DrawUpperTribe(pos)", "B-Board Render"));
+ table.addRow(List.of("2-DrawUpperBuilding(pos)", "C-Players Render"));
+ table.addRow(List.of("3-DrawLowerTribe(pos)", ""));
+ table.addRow(List.of("4-DrawLowerBuilding(pos)", ""));
+ table.addRow(List.of("5-PickOptionalTribe(pos)", ""));
+ table.addRow(List.of("6-PickOptionalBuilding(pos)", ""));
+ table.addRow(List.of("7-NoOptional", ""));
+ table.addRow(List.of("8-NoUpperCard", ""));
+ table.addRow(List.of("9-NoLowerCard", ""));
return table.build();
}
-}
+ /**
+ * Clears the terminal using a platform-aware system call.
+ * Uses {@code cls} on Windows and {@code clear} on Unix-like systems.
+ * Failures are silently ignored to avoid interrupting the render flow.
+ */
+ private void clearTerminal() {
+ try {
+ String os = System.getProperty("os.name").toLowerCase();
+ ProcessBuilder pb = os.contains("win")
+ ? new ProcessBuilder("cmd", "/c", "cls")
+ : new ProcessBuilder("clear");
+ pb.inheritIO().start().waitFor();
+ } catch (Exception ignored) {}
+ }
+}
\ No newline at end of file
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
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