Add: Added Javadoc For "toString" Method In Player.java.

Fix: "addSeparator" Method In AsciiTable.java Now Correctly Positons Separators.
This commit is contained in:
GabrieleRadice
2026-04-30 16:41:14 +02:00
parent 1af39bc558
commit 6d99b3e4e9
2 changed files with 26 additions and 10 deletions
@@ -8,7 +8,6 @@ import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import static it.polimi.ingsw.gc14.View.TUI.BorderStyle.*; import static it.polimi.ingsw.gc14.View.TUI.BorderStyle.*;
@@ -228,17 +227,34 @@ public class Player implements Serializable {
// endregion constructors // endregion constructors
// region Functions // region Functions
/**
* Prints the {@code Player}'s attributes for the {@code Board}'s representation.
* Uses the {@code UNICODE} border style.
* <p><b>Includes:</b>
* <li>{@link #FoodValue Food}
* <li>{@link #PrestigeValue Prestige}
* <li>{@link #artists Artists}
* <li>{@link #builders Builders}
* <li>{@link #gatherers Gatherers}
* <li>{@link #shamans Shamans}
* <li>{@link #inventors Inventors}
* <li>{@link #hunters Hunters}
* <li>{@link #buildingCards Buildings}
* </p>
* @return {@code String} - A string representation of the {@code Player}'s attributes.
* @see it.polimi.ingsw.gc14.View.TUI.BorderStyle BorderStyle
*/
@Override @Override
public String toString() { public String toString() {
int Last = 6; int Last = -1;
var table = new AsciiTable(UNICODE, 1); var table = new AsciiTable(UNICODE, 1);
table.addHeader(this.getUserName()); table.addHeader(this.getUserName());
table.addRow("RESOURCES:"); table.addRow("RESOURCES:");
table.addRow("Food: " + this.getFoodValue()); table.addRow("Food: " + this.getFoodValue());
table.addSeparator();
table.addRow("Prestige: " + this.getPrestigeValue()); table.addRow("Prestige: " + this.getPrestigeValue());
table.addSeparator();
if(!this.hunters.isEmpty()){ if(!this.hunters.isEmpty()){
Last = 6; Last = 6;
@@ -267,44 +283,44 @@ public class Player implements Serializable {
} }
table.addRow("CHARACTERS:"); table.addRow("CHARACTERS:");
if(!this.artists.isEmpty()){ if(!this.artists.isEmpty()){
table.addRow("Artists: " + this.artists.toString());
if(Last == 1){ if(Last == 1){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Artists: " + this.artists.toString());
} }
if(!this.builders.isEmpty()){ if(!this.builders.isEmpty()){
table.addRow("Builders: " + this.builders.toString());
if(Last == 2){ if(Last == 2){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Builders: " + this.builders.toString());
} }
if(!this.gatherers.isEmpty()){ if(!this.gatherers.isEmpty()){
table.addRow("Gatherers: " + this.gatherers.toString());
if(Last == 3){ if(Last == 3){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Gatherers: " + this.gatherers.toString());
} }
if(!this.shamans.isEmpty()){ if(!this.shamans.isEmpty()){
table.addRow("Shamans: " + this.shamans.toString());
if(Last == 4){ if(Last == 4){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Shamans: " + this.shamans.toString());
} }
if(!this.inventors.isEmpty()){ if(!this.inventors.isEmpty()){
table.addRow("Inventors: " + this.inventors.toString());
if(Last == 5){ if(Last == 5){
table.addSeparator(); table.addSeparator();
} }
table.addRow("Inventors: " + this.inventors.toString());
} }
if(!this.hunters.isEmpty()){ if(!this.hunters.isEmpty()){
table.addSeparator();
table.addRow("Hunters: " + this.hunters.toString()); table.addRow("Hunters: " + this.hunters.toString());
table.addSeparator();
} }
table.addRow("BUILDING CARDS:"); table.addRow("BUILDING CARDS:");
@@ -15,7 +15,7 @@ public class AsciiTable {
public void addRow(String... cells) { rows.add(Arrays.asList(cells)); } public void addRow(String... cells) { rows.add(Arrays.asList(cells)); }
public void addRow(List<String> cells) { rows.add(cells); } public void addRow(List<String> cells) { rows.add(cells); }
public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); } public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); }
public void addSeparator() { separators.add(rows.size()); } public void addSeparator() { separators.add(rows.size()-1); }
public String build() { public String build() {
var sb = new StringBuilder(); var sb = new StringBuilder();