Fix: complete refactor of TUI

Tests updated
This commit is contained in:
2026-06-10 22:15:32 +02:00
parent 8bd740e68a
commit 4ffe4c5352
31 changed files with 242 additions and 187 deletions
Vendored Regular → Executable
View File
@@ -28,8 +28,57 @@ public class ClientLauncherTUI {
private TUI view; private TUI view;
private Terminal terminal; private Terminal terminal;
private LineReader gameReader;
private String currentUsername = ""; private String currentUsername = "";
private static final String BUILDING_DETAILS =
"ID 0 — Each time you complete a set of 6 different Character cards, take 5 \uD83C\uDF56. (Sets completed before acquiring don't count.)\n" +
"ID 1 — During the Sustenance Event, pay 1 less \uD83C\uDF56 for each Artist/Inventor/Gatherer in your tribe.\n" +
"ID 2 — During the Shamanic Ritual Event, you do not lose Prestige Points if you have fewer ⭐ than all other players.\n" +
"ID 3 — When you move your Totem to a Food-bonus space, take 1 extra \uD83C\uDF56. If placed last, pay 1 \uD83C\uDF56 normally (no effect).\n" +
"ID 4 — Each time you obtain a pair of identical Inventors (same icon), take 3 \uD83C\uDF56. (Pairs owned before don't count.)\n" +
"ID 5 — During the Shamanic Ritual Event, your tribe has 3 additional ⭐ icons.\n" +
"ID 6 — During the Shamanic Ritual Event, if you have more ⭐ than any other player, gain double Prestige. Ties still count.\n" +
"ID 7 — During the Hunt Event, take 1 \uD83C\uDF56 and gain 1 extra Prestige Point for each Hunter in your tribe.\n" +
"ID 8 — At end of game, gain double the Prestige Points shown on Builder cards in your tribe.\n" +
"ID 9 — During the Cave Paintings Event, take 1 \uD83C\uDF56 for each Artist in your tribe.\n" +
"ID 10 — At end of game, gain 6 Prestige Points for each complete set of 6 different Character cards.\n" +
"ID 11 — At end of game, gain the indicated Prestige Points for each Character card of the indicated type.\n" +
"ID 12 — After all Totems return to Turn Order (before End of Round), take 1 Character or 1 Building card from the top row (paying its cost).\n" +
"ID 13 — At end of game, gain 25 Prestige Points.";
private static final String EVENT_DETAILS =
"SUSTENANCE — Pay 1 \uD83C\uDF56 per Character (Buildings don't count). If you can't feed all Characters, lose the\n" +
" Prestige Points shown on the card for each one you couldn't feed. Each Gatherer gives a 3\uD83C\uDF56 discount.\n" +
" You cannot choose to lose PP to avoid paying Food. Sustenance resolves last if multiple Events occur.\n" +
"\n" +
"HUNT — Take 1 \uD83C\uDF56 and gain the Prestige Points shown on the card for each Hunter in your tribe.\n" +
"\n" +
"SHAMANIC RITUAL — Player with the most \uD83C\uDF1F icons gains the Prestige Points on the card.\n" +
" Player with the fewest \uD83C\uDF1F icons loses those Prestige Points. In case of a tie, all tied players gain/lose.\n" +
"\n" +
"CAVE PAINTINGS — If you have fewer Artists than the top-line threshold, lose the indicated Prestige Points.\n" +
" If you meet the bottom-line threshold, gain the indicated Prestige Points for each Artist in your tribe.";
private static final String CHARACTER_DETAILS =
"INVENTORS — At end of game, gain PP equal to (number of Inventors) × (number of different Invention icons).\n" +
" There are 10 different Invention icons.\n" +
"\n" +
"GATHERERS — During Sustenance, each Gatherer gives a 3\uD83C\uDF56 discount on what you owe.\n" +
" Note: you do not take any Food from Gatherers under any circumstances.\n" +
"\n" +
"SHAMANS — Each Shaman shows 13 \uD83C\uDF1F icons. During Shamanic Ritual, majority = gain PP; minority = lose PP.\n" +
"\n" +
"BUILDERS — During the game, each Builder reduces the \uD83C\uDF56 cost of every Building card by the amount\n" +
" shown in the top-right corner. At end of game, each Builder gives the PP shown in the bottom-left corner.\n" +
"\n" +
"ARTISTS — During Cave Paintings, gain or lose PP based on Artist count (see 'details events').\n" +
" At end of game, gain 10 PP for every 2 Artists in your tribe.\n" +
"\n" +
"HUNTERS — Adding a Hunter without the \uD83C\uDF56 icon: nothing. Adding a Hunter WITH the \uD83C\uDF56 icon:\n" +
" immediately take 1 \uD83C\uDF56 for each Hunter in your tribe (with or without the icon).\n" +
" During Hunt Event, take \uD83C\uDF56 and gain PP based on your Hunter count (see 'details events').";
/** /**
* Starts the TUI client. Creates a JLine terminal, loops through login → game → rematch. * Starts the TUI client. Creates a JLine terminal, loops through login → game → rematch.
* *
@@ -52,7 +101,7 @@ public class ClientLauncherTUI {
view = new TUI(null); view = new TUI(null);
ClientController controller = new ClientController(view); ClientController controller = new ClientController(view);
LineReader gameReader = buildGameReader(); gameReader = buildGameReader();
view.setLineReader(gameReader); view.setLineReader(gameReader);
while (true) { while (true) {
@@ -157,6 +206,7 @@ public class ClientLauncherTUI {
node("skip"), node("skip"),
node("render"), node("render"),
node("help"), node("help"),
node("details", node("buildings"), node("events"), node("characters")),
node("rematch"), node("rematch"),
node("quit") node("quit")
); );
@@ -188,7 +238,17 @@ public class ClientLauncherTUI {
} }
case "skip" -> controller.skipTurn(); case "skip" -> controller.skipTurn();
case "render" -> handleRender(parts); case "render" -> handleRender(parts);
case "help" -> view.renderHelp(); case "help" -> gameReader.printAbove("Commands: slot, draw, totem, skip, render, help, details, rematch, quit");
case "details" -> {
if (parts.length > 1 && parts[1].equalsIgnoreCase("buildings"))
gameReader.printAbove(BUILDING_DETAILS);
else if (parts.length > 1 && parts[1].equalsIgnoreCase("events"))
gameReader.printAbove(EVENT_DETAILS);
else if (parts.length > 1 && parts[1].equalsIgnoreCase("characters"))
gameReader.printAbove(CHARACTER_DETAILS);
else
gameReader.printAbove("Usage: details buildings | details events | details characters");
}
case "rematch" -> { case "rematch" -> {
if (controller.miniModel == null if (controller.miniModel == null
|| !controller.miniModel.currentState.getGameStage().equals(GameStages.ENDED)) { || !controller.miniModel.currentState.getGameStage().equals(GameStages.ENDED)) {
@@ -74,6 +74,11 @@ public class Building1 extends BuildingCard {
*/ */
@Override @Override
public String toString() { public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0); return super.toString() + " (Icon:" + this.icon.toString().substring(0, 3) + ")";
}
@Override
public String toStringPlayer() {
return super.toStringPlayer() + " (Icon:" + this.icon.toString().substring(0, 3) + ")";
} }
} }
@@ -105,6 +105,11 @@ public class Building11 extends BuildingCard {
*/ */
@Override @Override
public String toString() { public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0) + " MP: " + this.PrestigeMul; return super.toString() + "+" + this.icon.toString().substring(0, 3) + "×" + this.PrestigeMul;
}
@Override
public String toStringPlayer() {
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.icon.toString().substring(0, 3) + "×" + this.PrestigeMul + ")";
} }
} }
@@ -141,7 +141,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* if {@code price <= 0}, or if {@code prestigeValue < 0} * if {@code price <= 0}, or if {@code prestigeValue < 0}
*/ */
public BuildingCard(int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{ public BuildingCard(int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
this.effectId = effectId; this(era,price,prestigeValue);
switch (effectId){ switch (effectId){
case 2: case 2:
this.effectType=EffectType.ON_EVENT; this.effectType=EffectType.ON_EVENT;
@@ -168,7 +168,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
this(era,price,prestigeValue); this.effectId = effectId;
} }
/** /**
@@ -186,7 +186,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* if {@code price <= 0}, or if {@code prestigeValue < 0}. * if {@code price <= 0}, or if {@code prestigeValue < 0}.
*/ */
public BuildingCard(String idIMG,int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{ public BuildingCard(String idIMG,int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
this.effectId = effectId; this(idIMG,era,price,prestigeValue);
switch (effectId){ switch (effectId){
case 2: case 2:
this.effectType=EffectType.ON_EVENT; this.effectType=EffectType.ON_EVENT;
@@ -213,7 +213,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
this(idIMG,era,price,prestigeValue); this.effectId = effectId;
} }
/** /**
@@ -274,6 +274,10 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
*/ */
@Override @Override
public String toString() { public String toString() {
return ":" + " ID:" + String.valueOf(getEffectId())+ " \uD83C\uDF56:"+String.valueOf(getPrice())+" \uD83C\uDFC5:"+String.valueOf(getPrestigeValue()); return ":" + " ID:" + getEffectId()+ " \uD83C\uDF56:"+String.valueOf(getPrice())+" \uD83C\uDFC5:"+String.valueOf(getPrestigeValue());
}
public String toStringPlayer() {
return "ID:" + getEffectId();
} }
} }
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Totems;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle; import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
@@ -23,10 +24,9 @@ public class Order2 extends OrderLogicCard {
* @throws NoSuchElementException if the number of players is not equal to 2. * @throws NoSuchElementException if the number of players is not equal to 2.
*/ */
public Order2(ArrayList<Player> players) throws NoSuchElementException { public Order2(ArrayList<Player> players) throws NoSuchElementException {
super(players);
if(players.size()!=2) if(players.size()!=2)
throw new NoSuchElementException(); throw new NoSuchElementException();
super(players);
} }
/** /**
@@ -74,7 +74,7 @@ public class Order2 extends OrderLogicCard {
if(playerList.get(i).played) if(playerList.get(i).played)
stringUp.add(""); stringUp.add("");
else else
stringUp.add(playerList.get(i).player.getUserName()); stringUp.add(playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName());
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Totems;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle; import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
@@ -24,9 +25,9 @@ public class Order3 extends OrderLogicCard {
* @throws NoSuchElementException if the number of players is not equal to 3. * @throws NoSuchElementException if the number of players is not equal to 3.
*/ */
public Order3(ArrayList<Player> players) throws NoSuchElementException{ public Order3(ArrayList<Player> players) throws NoSuchElementException{
super(players);
if(players.size()!=3) if(players.size()!=3)
throw new NoSuchElementException(); throw new NoSuchElementException();
super(players);
} }
/** /**
@@ -77,7 +78,7 @@ public class Order3 extends OrderLogicCard {
if(playerList.get(i).played) if(playerList.get(i).played)
stringUp.add(""); stringUp.add("");
else else
stringUp.add(playerList.get(i).player.getUserName()); stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Totems;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle; import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
@@ -24,9 +25,9 @@ public class Order4 extends OrderLogicCard {
* @throws NoSuchElementException if the number of players is not equal to 4. * @throws NoSuchElementException if the number of players is not equal to 4.
*/ */
public Order4(ArrayList<Player> players)throws NoSuchElementException { public Order4(ArrayList<Player> players)throws NoSuchElementException {
super(players);
if(players.size()!=4) if(players.size()!=4)
throw new NoSuchElementException(); throw new NoSuchElementException();
super(players);
} }
/** /**
@@ -83,7 +84,7 @@ public class Order4 extends OrderLogicCard {
if(playerList.get(i).played) if(playerList.get(i).played)
stringUp.add(""); stringUp.add("");
else else
stringUp.add(playerList.get(i).player.getUserName()); stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Totems;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable; import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle; import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
@@ -24,9 +25,9 @@ public class Order5 extends OrderLogicCard {
* @throws NoSuchElementException if the number of players is not equal to 5. * @throws NoSuchElementException if the number of players is not equal to 5.
*/ */
public Order5(ArrayList<Player> players) throws NoSuchElementException{ public Order5(ArrayList<Player> players) throws NoSuchElementException{
super(players);
if(players.size()!=5) if(players.size()!=5)
throw new NoSuchElementException(); throw new NoSuchElementException();
super(players);
} }
/** /**
@@ -84,7 +85,7 @@ public class Order5 extends OrderLogicCard {
if(playerList.get(i).played) if(playerList.get(i).played)
stringUp.add(""); stringUp.add("");
else else
stringUp.add(playerList.get(i).player.getUserName()); stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -276,7 +276,7 @@ public class Player implements Serializable {
var table = new AsciiTable(ROUNDED, 1); var table = new AsciiTable(ROUNDED, 1);
String totemStr = (this.totem != null) ? " (" + this.totem.toString() + ")" : ""; String totemStr = (this.totem != null) ? " (" + this.totem.toString() + ")" : "";
table.addHeader(this.getUserName() + totemStr + " | \uD83C\uDF56:" + this.getFoodValue() + " | \uD83C\uDFC5:" + this.getPrestigeValue() + " "); table.addHeader(this.getUserName() + totemStr + " | \uD83C\uDF56:" + this.getFoodValue() + " | \uD83C\uDFC5:" + this.getPrestigeValue());
table.addSeparator(); table.addSeparator();
if(!this.hunters.isEmpty()){ if(!this.hunters.isEmpty()){
@@ -304,7 +304,7 @@ public class Player implements Serializable {
if(Last == 0){ if(Last == 0){
table.addSeparator(); table.addSeparator();
} }
table.addRow("CHARACTERS:"); table.addRow("CHARACTERS");
if(!this.artists.isEmpty()){ if(!this.artists.isEmpty()){
table.addRow(this.artists.size() + " Artists: \uD83C\uDFA8:" + this.artists.size()); table.addRow(this.artists.size() + " Artists: \uD83C\uDFA8:" + this.artists.size());
if(Last == 1){ if(Last == 1){
@@ -313,7 +313,7 @@ public class Player implements Serializable {
} }
if(!this.builders.isEmpty()){ if(!this.builders.isEmpty()){
table.addRow(this.builders.size() + " Builders: " + "-\uD83C\uDF56:" + this.builders.stream().mapToInt(Builder::getReductionValue).sum() + " \uD83C\uDFC5:" + this.builders.stream().mapToInt(Builder::getPrestigeValue).sum()); table.addRow(this.builders.size() + " Builders: " + "\uD83D\uDD28:" + this.builders.stream().mapToInt(Builder::getReductionValue).sum() + " \uD83C\uDFC5:" + this.builders.stream().mapToInt(Builder::getPrestigeValue).sum());
if(Last == 2){ if(Last == 2){
table.addSeparator(); table.addSeparator();
} }
@@ -342,7 +342,7 @@ public class Player implements Serializable {
.entrySet().stream() .entrySet().stream()
.sorted(Map.Entry.comparingByKey()) .sorted(Map.Entry.comparingByKey())
.map(e -> e.getKey() + ":" + e.getValue()) .map(e -> e.getKey() + ":" + e.getValue())
.collect(Collectors.joining(" "))); .collect(Collectors.joining(", ")));
if(Last == 5){ if(Last == 5){
table.addSeparator(); table.addSeparator();
} }
@@ -353,10 +353,13 @@ public class Player implements Serializable {
table.addRow(this.hunters.size() + " Hunters: \uD83C\uDF56" + this.hunters.stream().filter(Hunter::getIcon).count()); table.addRow(this.hunters.size() + " Hunters: \uD83C\uDF56" + this.hunters.stream().filter(Hunter::getIcon).count());
table.addSeparator(); table.addSeparator();
} }
table.addSeparator();
table.addRow("BUILDING CARDS:"); table.addRow("BUILDING CARDS" +
(this.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum() != 0
? " 🏅:" + this.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum()
: ""));
if(!this.buildingCards.isEmpty()){ if(!this.buildingCards.isEmpty()){
table.addRow(this.buildingCards.size() + " Buildings: " + this.buildingCards.toString()); table.addRow(this.buildingCards.size() + " Buildings: " + this.buildingCards.stream().map(BuildingCard::toStringPlayer).collect(Collectors.joining(", ")));
} }
return table.build(); return table.build();
@@ -171,18 +171,11 @@ public class Slot implements Serializable {
*/ */
public String toStringTUI() public String toStringTUI()
{ {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder(" ");
//s.append(this.getSlotId()+" "); for(int i=0;i<this.getNUpper();i++) s.append("");
for(int i=0;i<this.getNUpper();i++) for(int i=0;i<this.getNLower();i++) s.append("");
{ if(getFood()!=0) s.append("+"+getFood()+" \uD83C\uDF56");
s.append(""); s.append(" ");
}
for(int i=0;i<this.getNLower();i++)
{
s.append("");
}
if(getFood()!=0)
s.append("+"+getFood()+" \uD83C\uDF56");
return s.toString(); return s.toString();
} }
@@ -110,6 +110,7 @@ public class AsciiTable {
* Wide characters (emoji, CJK, full-width) count as 2; all others as 1. * Wide characters (emoji, CJK, full-width) count as 2; all others as 1.
*/ */
public static int displayWidth(String s) { public static int displayWidth(String s) {
s = s.replaceAll("\033\\[[^m]*m", "");
int w = 0; int w = 0;
for (int i = 0; i < s.length(); ) { for (int i = 0; i < s.length(); ) {
int cp = s.codePointAt(i); int cp = s.codePointAt(i);
@@ -106,32 +106,19 @@ public class TUI implements IView {
* @param message the human-readable message to append. * @param message the human-readable message to append.
*/ */
public void showError(ErrorType error, String message) { public void showError(ErrorType error, String message) {
if (model == null) { String text;
display(message);
return;
}
GameStages stage = model.currentState.getGameStage();
String base;
if (stage.equals(GameStages.TOTEM_CHOICE)) {
base = buildTotemsContent();
} else if (stage.equals(GameStages.ENDED)) {
base = buildStandingContent() + "\nType 'rematch' to play again or 'quit' to exit";
} else {
base = buildBoardContent();
}
if (error.equals(ErrorType.WRONG_ACTION) if (error.equals(ErrorType.WRONG_ACTION)
&& model != null
&& model.currentState.getCurrentPlayer() != null && model.currentState.getCurrentPlayer() != null
&& !model.currentState.getCurrentPlayer().getUserName().equals(username)) { && !model.currentState.getCurrentPlayer().getUserName().equals(username)) {
display(base + "\nIt's not your turn"); text = "It's not your turn";
return; } else {
text = message;
if (error == ErrorType.SERVER_CRASHED) {
text += "\nPress any key to continue";
}
} }
printLine(text);
String full = base + "\n" + message;
if (error == ErrorType.SERVER_CRASHED) {
full += "\nPress any key to continue";
}
display(full);
} }
// ── Content builders (return strings, do not print) ─────────────────────── // ── Content builders (return strings, do not print) ───────────────────────
@@ -153,11 +140,20 @@ public class TUI implements IView {
private String buildAllHandsContent() { private String buildAllHandsContent() {
List<Player> players = new ArrayList<>(model.players.values()); List<Player> players = new ArrayList<>(model.players.values());
if (players.isEmpty()) return ""; if (players.isEmpty()) return "";
StringBuilder result = new StringBuilder();
for (Player p : players) { int n = players.size();
result.append(p.toString()).append("\n"); int leftCount = Math.min(3, n);
}
return result.toString(); StringBuilder leftSb = new StringBuilder();
StringBuilder rightSb = new StringBuilder();
for (int i = 0; i < leftCount; i++) leftSb.append(players.get(i).toString()).append("\n");
for (int i = leftCount; i < n; i++) rightSb.append(players.get(i).toString()).append("\n");
if (rightSb.isEmpty()) return leftSb.toString();
return AsciiTable.sideBySide(
List.of(leftSb.toString().split("\n", -1)),
List.of(rightSb.toString().split("\n", -1)), 3);
} }
private String buildTotemsContent() { private String buildTotemsContent() {
@@ -215,6 +211,16 @@ public class TUI implements IView {
} }
} }
/** Prints {@code text} above the prompt without clearing the screen. */
private void printLine(String text) {
if (lineReader != null) {
lineReader.printAbove(text);
} else {
System.out.println(text);
System.out.flush();
}
}
/** /**
* Horizontally centers each line of {@code content} within the terminal width. * Horizontally centers each line of {@code content} within the terminal width.
* Empty lines are left unpadded. Falls back to the original string when the * Empty lines are left unpadded. Falls back to the original string when the
@@ -314,9 +320,7 @@ public class TUI implements IView {
String upperSection = UpperCards.build(); String upperSection = UpperCards.build();
String middleSection = AsciiTable.sideBySide( String middleSection = model.orderLogicCard.toString() + offerTrack.build();
List.of(model.orderLogicCard.toString().split("\n")),
List.of(offerTrack.build().split("\n")), 3);
String lowerSection = LowerCards.build(); String lowerSection = LowerCards.build();
@@ -326,23 +330,4 @@ public class TUI implements IView {
+ lowerSection; + lowerSection;
} }
// ── Help ──────────────────────────────────────────────────────────────────
/** Displays the command help panel. */
public void renderHelp() {
display(buildHelpContent());
}
private String buildHelpContent() {
var table = new AsciiTable(BorderStyle.ROUNDED, 1);
table.addHeader("Commands");
table.addRow("slot <pos>");
table.addRow("draw upper|lower tribe|building <pos>");
table.addRow("totem <pos>");
table.addRow("skip");
table.addRow("render");
table.addRow("help");
table.addRow("rematch | quit");
return table.build();
}
} }
@@ -132,27 +132,27 @@ class Building11Test {
int pm = 5; int pm = 5;
Building11 b11 = new Building11(era, price, prestigeValue, ct, pm); Building11 b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
ct = CharacterType.BUILDER; ct = CharacterType.BUILDER;
b11 = new Building11(era, price, prestigeValue, ct, pm); b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
ct = CharacterType.GATHERER; ct = CharacterType.GATHERER;
b11 = new Building11(era, price, prestigeValue, ct, pm); b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
ct = CharacterType.HUNTER; ct = CharacterType.HUNTER;
b11 = new Building11(era, price, prestigeValue, ct, pm); b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
ct = CharacterType.INVENTOR; ct = CharacterType.INVENTOR;
b11 = new Building11(era, price, prestigeValue, ct, pm); b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
ct = CharacterType.SHAMAN; ct = CharacterType.SHAMAN;
b11 = new Building11(era, price, prestigeValue, ct, pm); b11 = new Building11(era, price, prestigeValue, ct, pm);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + "+" + ct.toString().substring(0, 3) + "×" + pm, b11.toString());
} }
@Test @Test
@@ -87,27 +87,27 @@ class Building1Test {
CharacterType ct = CharacterType.ARTIST; CharacterType ct = CharacterType.ARTIST;
Building1 b1 = new Building1(era, price, prestigeValue, ct); Building1 b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
ct = CharacterType.BUILDER; ct = CharacterType.BUILDER;
b1 = new Building1(era, price, prestigeValue, ct); b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
ct = CharacterType.GATHERER; ct = CharacterType.GATHERER;
b1 = new Building1(era, price, prestigeValue, ct); b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
ct = CharacterType.HUNTER; ct = CharacterType.HUNTER;
b1 = new Building1(era, price, prestigeValue, ct); b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
ct = CharacterType.INVENTOR; ct = CharacterType.INVENTOR;
b1 = new Building1(era, price, prestigeValue, ct); b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
ct = CharacterType.SHAMAN; ct = CharacterType.SHAMAN;
b1 = new Building1(era, price, prestigeValue, ct); b1 = new Building1(era, price, prestigeValue, ct);
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + price + " 🏅:" + prestigeValue + " (Icon:" + ct.toString().substring(0, 3) + ")", b1.toString());
} }
@Test @Test
@@ -299,14 +299,14 @@ class BuildingCardTest {
int prestigeValue = 6; int prestigeValue = 6;
BuildingCard b0 = new BuildingCard(era, price, prestigeValue); BuildingCard b0 = new BuildingCard(era, price, prestigeValue);
assertEquals(":" + " ID:0" + " $:"+ b0.getPrice() + " PV:" + b0.getPrestigeValue(), b0.toString()); assertEquals(":" + " ID:0" + " 🍖:"+ b0.getPrice() + " 🏅:" + b0.getPrestigeValue(), b0.toString());
for(int ID = 3; ID < 13; ID++){ for(int ID = 3; ID < 13; ID++){
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){ if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
continue; continue;
} }
BuildingCard b = new BuildingCard(ID, era, price, prestigeValue); BuildingCard b = new BuildingCard(ID, era, price, prestigeValue);
assertEquals(":" + " ID:" + ID + " $:"+ b.getPrice() + " PV:" + b.getPrestigeValue(), b.toString()); assertEquals(":" + " ID:" + ID + " 🍖:" + b.getPrice() + " 🏅:" + b.getPrestigeValue(), b.toString());
} }
} }
@@ -14,7 +14,7 @@ class ArtistTest {
String s = a.toString(); String s = a.toString();
assertNotNull(s); assertNotNull(s);
assertTrue(s.contains("⎕:")); assertTrue(s.isEmpty());
} }
@Test @Test
@@ -28,8 +28,8 @@ class BuilderTest {
String s = b.toString(); String s = b.toString();
assertNotNull(s); assertNotNull(s);
assertFalse(s.contains(CharacterType.BUILDER.toString())); assertTrue(s.contains(CharacterType.BUILDER.toString()));
assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s); assertEquals(": BUILDER 🔨:" + b.getReductionValue() + " 🏅:" + b.getPrestigeValue(), s);
} }
@Test @Test
@@ -165,7 +165,7 @@ class BuilderTest {
String s = b.toStringBoard(); String s = b.toStringBoard();
assertNotNull(s); assertNotNull(s);
assertTrue(s.contains("RV:2")); assertTrue(s.contains("🔨:2"));
assertTrue(s.contains("PV:3")); assertTrue(s.contains("🏅:3"));
} }
} }
@@ -15,7 +15,7 @@ class GathererTest {
assertNotNull(s); assertNotNull(s);
assertFalse(s.contains(CharacterType.GATHERER.toString())); assertFalse(s.contains(CharacterType.GATHERER.toString()));
assertTrue(s.contains("⎕:")); assertTrue(s.isEmpty());
} }
@Test @Test
@@ -18,7 +18,7 @@ class HunterTest {
@Test @Test
void testToString() { void testToString() {
Hunter h = new Hunter(1, true); Hunter h = new Hunter(1, true);
assertTrue(h.toString().contains(" I")); assertTrue(h.toString().contains("🍖"));
Hunter h2 = new Hunter(3, false); Hunter h2 = new Hunter(3, false);
assertFalse(h2.toString().contains("I")); assertFalse(h2.toString().contains("I"));
@@ -27,7 +27,7 @@ class HunterTest {
@Test @Test
void testToStringBoard() { void testToStringBoard() {
Hunter h = new Hunter(1, true); Hunter h = new Hunter(1, true);
assertTrue(h.toStringBoard().contains(" I")); assertTrue(h.toStringBoard().contains("🍖"));
Hunter h2 = new Hunter(3, false); Hunter h2 = new Hunter(3, false);
assertFalse(h2.toStringBoard().contains("I")); assertFalse(h2.toStringBoard().contains("I"));
@@ -22,7 +22,7 @@ class InventorTest {
assertNotNull(s); assertNotNull(s);
assertFalse(s.contains(CharacterType.INVENTOR.toString())); assertFalse(s.contains(CharacterType.INVENTOR.toString()));
assertEquals("⎕:" + " I_ID:" + i.Icon(), s); assertEquals("ID:" + i.Icon(), s);
} }
@Test @Test
@@ -31,7 +31,7 @@ class InventorTest {
String s = i.toStringBoard(); String s = i.toStringBoard();
assertNotNull(s); assertNotNull(s);
assertTrue(s.contains("I_ID:5")); assertTrue(s.contains("ID:5"));
} }
@Test @Test
@@ -22,7 +22,7 @@ class ShamanTest {
assertNotNull(str); assertNotNull(str);
assertFalse(str.contains(CharacterType.SHAMAN.toString())); assertFalse(str.contains(CharacterType.SHAMAN.toString()));
assertEquals("⎕: *:" + s.getIcon(), str); assertEquals("🌟:" + s.getIcon(), str);
} }
@Test @Test
@@ -31,7 +31,7 @@ class ShamanTest {
String str = s.toStringBoard(); String str = s.toStringBoard();
assertNotNull(str); assertNotNull(str);
assertTrue(str.contains("*:4")); assertTrue(str.contains("🌟:4"));
} }
@Test @Test
@@ -141,7 +141,7 @@ class CavePaintingsTest {
void toStringTest() { void toStringTest() {
CavePaintings cv1 = new CavePaintings(1, 1,1,1); CavePaintings cv1 = new CavePaintings(1, 1,1,1);
assertEquals("⎕:(Event)CAVE_PAINTINGS", cv1.toString()); assertEquals(" CAVE_PAINTINGS", cv1.toString());
} }
@Test @Test
@@ -153,6 +153,6 @@ class CavePaintingsTest {
int NPrestigeMul = 3; int NPrestigeMul = 3;
CavePaintings cv1 = new CavePaintings(Era, NLower,NPrestigeRem,NPrestigeMul); CavePaintings cv1 = new CavePaintings(Era, NLower,NPrestigeRem,NPrestigeMul);
assertEquals("⎕:(Event)" + cv1.getType() + " 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul, cv1.toStringBoard()); assertEquals(": " + cv1.getType() + " 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul, cv1.toStringBoard());
} }
} }
@@ -150,7 +150,7 @@ class HuntTest {
void toStringTest() { void toStringTest() {
Hunt h1 = new Hunt(1, 3); Hunt h1 = new Hunt(1, 3);
assertEquals("⎕:(Event)HUNT", h1.toString()); assertEquals(" HUNT", h1.toString());
} }
@Test @Test
@@ -160,6 +160,6 @@ class HuntTest {
int prestigeMultiplier = 3; int prestigeMultiplier = 3;
Hunt cv1 = new Hunt(Era, prestigeMultiplier); Hunt cv1 = new Hunt(Era, prestigeMultiplier);
assertEquals("⎕:(Event)" + cv1.getType() + " 1F+" + prestigeMultiplier + "PP" + " X N Hunter", cv1.toStringBoard()); assertEquals(": " + cv1.getType() + " 1🍖+" + prestigeMultiplier + "🏅×🏹", cv1.toStringBoard());
} }
} }
@@ -235,7 +235,7 @@ class ShamanicRitualTest {
void toStringTest() { void toStringTest() {
ShamanicRitual sr1 = new ShamanicRitual(1, 5,2); ShamanicRitual sr1 = new ShamanicRitual(1, 5,2);
assertEquals("⎕:(Event)SHAMANIC_RITUAL", sr1.toString()); assertEquals(" SHAMANIC_RITUAL", sr1.toString());
} }
@Test @Test
@@ -246,6 +246,6 @@ class ShamanicRitualTest {
int prestigeToRem = 2; int prestigeToRem = 2;
ShamanicRitual cv1 = new ShamanicRitual(Era, prestigeToAdd, prestigeToRem); ShamanicRitual cv1 = new ShamanicRitual(Era, prestigeToAdd, prestigeToRem);
assertEquals("⎕:(Event)" + cv1.getType() + " *>:" + prestigeToAdd + " *<:" + prestigeToRem, cv1.toStringBoard()); assertEquals(": " + cv1.getType() + " 🌟>:" + prestigeToAdd + " 🌟<:" + prestigeToRem, cv1.toStringBoard());
} }
} }
@@ -155,7 +155,7 @@ class SustenanceTest {
void toStringTest() { void toStringTest() {
Sustenance s1 = new Sustenance(1, 5); Sustenance s1 = new Sustenance(1, 5);
assertEquals("⎕:(Event)SUSTENANCE", s1.toString()); assertEquals(" SUSTENANCE", s1.toString());
} }
@Test @Test
@@ -165,7 +165,7 @@ class SustenanceTest {
int prestigeDebt = 15; int prestigeDebt = 15;
Sustenance cv1 = new Sustenance(Era, prestigeDebt); Sustenance cv1 = new Sustenance(Era, prestigeDebt);
assertEquals("⎕:(Event)" + cv1.getType() + " -1F/-" + prestigeDebt + "PP", cv1.toStringBoard()); assertEquals(": " + cv1.getType() + " -1🍖/-" + prestigeDebt + "🏅", cv1.toStringBoard());
} }
} }
@@ -167,31 +167,31 @@ class Order2Test {
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull(); order.pull();
order.pull(); order.pull();
assertFalse(order.toString().contains(usr1)); assertFalse(order.toString().contains(usr1));
assertFalse(order.toString().contains(usr2)); assertFalse(order.toString().contains(usr2));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.push(p2); order.push(p2);
order.push(p1); order.push(p1);
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull().getUserName(); order.pull().getUserName();
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertFalse(order.toString().contains(usr2)); assertFalse(order.toString().contains(usr2));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
Player extraPlayer = new Player("px"); Player extraPlayer = new Player("px");
//TODO testare IndexOutOfBoundsException //TODO testare IndexOutOfBoundsException
@@ -195,9 +195,9 @@ class Order3Test {
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull(); order.pull();
order.pull(); order.pull();
@@ -206,9 +206,9 @@ class Order3Test {
assertFalse(order.toString().contains(usr1)); assertFalse(order.toString().contains(usr1));
assertFalse(order.toString().contains(usr2)); assertFalse(order.toString().contains(usr2));
assertFalse(order.toString().contains(usr3)); assertFalse(order.toString().contains(usr3));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.push(p3); order.push(p3);
order.push(p2); order.push(p2);
@@ -217,18 +217,18 @@ class Order3Test {
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull().getUserName(); order.pull().getUserName();
assertTrue(order.toString().contains(usr1)); assertTrue(order.toString().contains(usr1));
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertFalse(order.toString().contains(usr3)); assertFalse(order.toString().contains(usr3));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
//TODO testare IndexOutOfBoundsException //TODO testare IndexOutOfBoundsException
} }
@@ -289,10 +289,10 @@ class Order4Test {
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains(usr4)); assertTrue(order.toString().contains(usr4));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull(); order.pull();
order.pull(); order.pull();
@@ -303,10 +303,10 @@ class Order4Test {
assertFalse(order.toString().contains(usr2)); assertFalse(order.toString().contains(usr2));
assertFalse(order.toString().contains(usr3)); assertFalse(order.toString().contains(usr3));
assertFalse(order.toString().contains(usr4)); assertFalse(order.toString().contains(usr4));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.push(p4); order.push(p4);
order.push(p3); order.push(p3);
@@ -317,10 +317,10 @@ class Order4Test {
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains(usr4)); assertTrue(order.toString().contains(usr4));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull().getUserName(); order.pull().getUserName();
@@ -328,10 +328,10 @@ class Order4Test {
assertTrue(order.toString().contains(usr2)); assertTrue(order.toString().contains(usr2));
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertFalse(order.toString().contains(usr4)); assertFalse(order.toString().contains(usr4));
assertTrue(order.toString().contains("+2 Food")); assertTrue(order.toString().contains("+2🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
//TODO testare IndexOutOfBoundsException //TODO testare IndexOutOfBoundsException
} }
@@ -387,10 +387,10 @@ class Order5Test {
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains(usr4)); assertTrue(order.toString().contains(usr4));
assertTrue(order.toString().contains(usr5)); assertTrue(order.toString().contains(usr5));
assertTrue(order.toString().contains("+3 Food")); assertTrue(order.toString().contains("+3🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull(); order.pull();
order.pull(); order.pull();
@@ -403,10 +403,10 @@ class Order5Test {
assertFalse(order.toString().contains(usr3)); assertFalse(order.toString().contains(usr3));
assertFalse(order.toString().contains(usr4)); assertFalse(order.toString().contains(usr4));
assertFalse(order.toString().contains(usr5)); assertFalse(order.toString().contains(usr5));
assertTrue(order.toString().contains("+3 Food")); assertTrue(order.toString().contains("+3🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.push(p5); order.push(p5);
order.push(p4); order.push(p4);
@@ -419,10 +419,10 @@ class Order5Test {
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains(usr4)); assertTrue(order.toString().contains(usr4));
assertTrue(order.toString().contains(usr5)); assertTrue(order.toString().contains(usr5));
assertTrue(order.toString().contains("+3 Food")); assertTrue(order.toString().contains("+3🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
order.pull(); order.pull();
@@ -431,10 +431,10 @@ class Order5Test {
assertTrue(order.toString().contains(usr3)); assertTrue(order.toString().contains(usr3));
assertTrue(order.toString().contains(usr4)); assertTrue(order.toString().contains(usr4));
assertFalse(order.toString().contains(usr5)); assertFalse(order.toString().contains(usr5));
assertTrue(order.toString().contains("+3 Food")); assertTrue(order.toString().contains("+3🍖"));
assertTrue(order.toString().contains("+1 Food")); assertTrue(order.toString().contains("+1🍖"));
assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("--"));
assertTrue(order.toString().contains("-1 Food / -2 PP")); assertTrue(order.toString().contains("-1🍖/-2🏅"));
//TODO capire come è testato IndexOutOfBoundsExceptions //TODO capire come è testato IndexOutOfBoundsExceptions
} }
@@ -220,25 +220,21 @@ class PlayerTest {
p.getBuildingCards().add(new Building1(2, 5, 5, CharacterType.INVENTOR)); p.getBuildingCards().add(new Building1(2, 5, 5, CharacterType.INVENTOR));
p.getBuildingCards().add(new Building1(2, 5, 5, CharacterType.SHAMAN)); p.getBuildingCards().add(new Building1(2, 5, 5, CharacterType.SHAMAN));
p.getBuildingCards().add(new Building11(1, 5, 7, CharacterType.ARTIST , 3)); p.getBuildingCards().add(new Building11(1, 5, 7, CharacterType.ARTIST , 3));
assertEquals(""+ assertEquals(
"╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗\n" + "╭────────────────────────────────────────────────────────────────────────────╮\n" +
" test_usr \n" + " test_usr | 🍖:7 | 🏅:15 \n" +
"═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════\n" + "────────────────────────────────────────────────────────────────────────────\n" +
"║ RESOURCES: \n" + "│ CHARACTERS \n" +
"║ Food: 7 \n" + "│ 7 Artists: 🎨:7 \n" +
"║ Prestige: 15 \n" + "│ 1 Builders: 🔨:5 🏅:1 \n" +
"├═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════┤\n" + "│ 1 Gatherers: -🥗:3 │\n" +
"║ CHARACTERS: \n" + "│ 2 Shamans: 🌟:6 \n" +
"║ Artists: [⎕:, ⎕:, ⎕:, ⎕:, ⎕:, ⎕:, ⎕:] \n" + "│ 1 Inventors: 1:1 \n" +
"║ Builders: [⎕: RV:5 PV:1] \n" + "│ 2 Hunters: 🍖1 \n" +
"║ Gatherers: [⎕:] ║\n" + "├────────────────────────────────────────────────────────────────────────────┤\n" +
"║ Shamans: [⎕: *:3, ⎕: *:3] \n" + "│ BUILDING CARDS 🏅:28 \n" +
"║ Inventors: [⎕: I_ID:1] ║\n" + "│ 5 Buildings: ID:2, ID:2, ID:1 (Icon:INV), ID:1 (Icon:SHA), ID:11 (🏅:ART×3)│\n" +
"║ Hunters: [⎕: I, ⎕:] ║\n" + "╰────────────────────────────────────────────────────────────────────────────╯", p.toString());
"├═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════┤\n" +
"║ BUILDING CARDS: ║\n" +
"║ Buildings: [⎕: ID:2 $:2 PV:5, ⎕: ID:2 $:3 PV:6, ⎕: ID:1 $:5 PV:5 Icon: I, ⎕: ID:1 $:5 PV:5 Icon: S, ⎕: ID:11 $:5 PV:7 Icon: A MP: 3]║\n" +
"╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝", p.toString());
} }
@Test @Test
@@ -248,49 +244,49 @@ class PlayerTest {
assertNotNull(emptyString); assertNotNull(emptyString);
assertTrue(emptyString.contains("empty")); assertTrue(emptyString.contains("empty"));
assertTrue(emptyString.contains("CHARACTERS:")); assertTrue(emptyString.contains("CHARACTERS"));
assertTrue(emptyString.contains("BUILDING CARDS:")); assertTrue(emptyString.contains("BUILDING CARDS"));
Player onlyArtist = new Player("onlyArtist"); Player onlyArtist = new Player("onlyArtist");
onlyArtist.getArtists().add(new Artist(1)); onlyArtist.getArtists().add(new Artist(1));
String artistString = onlyArtist.toString(); String artistString = onlyArtist.toString();
assertTrue(artistString.contains("Artists:")); assertTrue(artistString.contains("Artists:"));
assertTrue(artistString.contains("BUILDING CARDS:")); assertTrue(artistString.contains("BUILDING CARDS"));
Player onlyBuilder = new Player("onlyBuilder"); Player onlyBuilder = new Player("onlyBuilder");
onlyBuilder.getBuilders().add(new Builder(1, 1, 1)); onlyBuilder.getBuilders().add(new Builder(1, 1, 1));
String builderString = onlyBuilder.toString(); String builderString = onlyBuilder.toString();
assertTrue(builderString.contains("Builders:")); assertTrue(builderString.contains("Builders:"));
assertTrue(builderString.contains("BUILDING CARDS:")); assertTrue(builderString.contains("BUILDING CARDS"));
Player onlyGatherer = new Player("onlyGatherer"); Player onlyGatherer = new Player("onlyGatherer");
onlyGatherer.getGatherers().add(new Gatherer(1, 1)); onlyGatherer.getGatherers().add(new Gatherer(1, 1));
String gathererString = onlyGatherer.toString(); String gathererString = onlyGatherer.toString();
assertTrue(gathererString.contains("Gatherers:")); assertTrue(gathererString.contains("Gatherers:"));
assertTrue(gathererString.contains("BUILDING CARDS:")); assertTrue(gathererString.contains("BUILDING CARDS"));
Player onlyShaman = new Player("onlyShaman"); Player onlyShaman = new Player("onlyShaman");
onlyShaman.getShamans().add(new Shaman(1, 1)); onlyShaman.getShamans().add(new Shaman(1, 1));
String shamanString = onlyShaman.toString(); String shamanString = onlyShaman.toString();
assertTrue(shamanString.contains("Shamans:")); assertTrue(shamanString.contains("Shamans:"));
assertTrue(shamanString.contains("BUILDING CARDS:")); assertTrue(shamanString.contains("BUILDING CARDS"));
Player onlyInventor = new Player("onlyInventor"); Player onlyInventor = new Player("onlyInventor");
onlyInventor.getInventors().add(new Inventor(1, 1)); onlyInventor.getInventors().add(new Inventor(1, 1));
String inventorString = onlyInventor.toString(); String inventorString = onlyInventor.toString();
assertTrue(inventorString.contains("Inventors:")); assertTrue(inventorString.contains("Inventors:"));
assertTrue(inventorString.contains("BUILDING CARDS:")); assertTrue(inventorString.contains("BUILDING CARDS"));
Player onlyHunter = new Player("onlyHunter"); Player onlyHunter = new Player("onlyHunter");
onlyHunter.getHunters().add(new Hunter(1, true)); onlyHunter.getHunters().add(new Hunter(1, true));
String hunterString = onlyHunter.toString(); String hunterString = onlyHunter.toString();
assertTrue(hunterString.contains("Hunters:")); assertTrue(hunterString.contains("Hunters:"));
assertTrue(hunterString.contains("BUILDING CARDS:")); assertTrue(hunterString.contains("BUILDING CARDS"));
} }
} }