Merge pull request #50 from rubenpirreram/toString-fixes
To string fixes
This commit is contained in:
@@ -2,11 +2,8 @@ package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||||
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.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* During the Sustenance Event, you have a discount of 1 food token on the total you
|
* During the Sustenance Event, you have a discount of 1 food token on the total you
|
||||||
@@ -47,4 +44,8 @@ public class Building1 extends BuildingCard {
|
|||||||
return new Building1(getEra(),getPrice(),getPrestigeValue(),getIcon());
|
return new Building1(getEra(),getPrice(),getPrestigeValue(),getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " Icon: " + this.icon.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
|||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
|
||||||
public class Building11 extends BuildingCard {
|
public class Building11 extends BuildingCard {
|
||||||
|
|
||||||
private CharacterType icon ;
|
private CharacterType icon ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,6 +15,7 @@ public class Building11 extends BuildingCard {
|
|||||||
* @return the CharacterType associated with this building card effect.
|
* @return the CharacterType associated with this building card effect.
|
||||||
*/
|
*/
|
||||||
public CharacterType getIcon() {return icon;}
|
public CharacterType getIcon() {return icon;}
|
||||||
|
|
||||||
private int PrestigeMul;
|
private int PrestigeMul;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,4 +67,9 @@ public class Building11 extends BuildingCard {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
|
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " Icon: " + this.icon.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -182,6 +182,6 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Era:"+String.valueOf(getEra())+" Price:"+String.valueOf(getPrice())+" Prestige:"+String.valueOf(getPrestigeValue());
|
return "Era:"+String.valueOf(getEra())+" P:"+String.valueOf(getPrice())+" PR:"+String.valueOf(getPrestigeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public abstract class Character extends TribeCard implements Cloneable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString()+" "+type.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ public class Builder extends Character
|
|||||||
* @return the string representation of this Builder card.
|
* @return the string representation of this Builder card.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return super.toString()+" Reduction Value: " + String.valueOf(reductionValue) + "\n Prestige Value: " + String.valueOf(prestigeValue); }
|
public String toString() {
|
||||||
|
return super.toString() + " RV: " + String.valueOf(reductionValue) + " PV: " + String.valueOf(prestigeValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a copy of this Builder card.
|
* Creates and returns a copy of this Builder card.
|
||||||
|
|||||||
@@ -47,7 +47,11 @@ public class Hunter extends Character {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + "Icon: " + String.valueOf(icon);
|
String toPrint = super.toString();
|
||||||
|
if(this.icon){
|
||||||
|
toPrint += " 🏹";
|
||||||
|
}
|
||||||
|
return toPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class Inventor extends Character {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + " Symbol:" + String.valueOf(icon);
|
return super.toString() + " I_ID:" + String.valueOf(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Shaman extends Character {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + "Icon: " + String.valueOf(icon);
|
return super.toString() + " ★: " + String.valueOf(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,6 +43,6 @@ public abstract class PlayableCard implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Era:"+String.valueOf(Era);
|
return "⌛:"+String.valueOf(Era);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ package it.polimi.ingsw.gc14.Model;
|
|||||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
||||||
|
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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Player class; contains all identifiers and methods needed.
|
* Default Player class; contains all identifiers and methods needed.
|
||||||
@@ -224,21 +228,91 @@ public class Player implements Serializable {
|
|||||||
// endregion constructors
|
// endregion constructors
|
||||||
|
|
||||||
// region Functions
|
// region Functions
|
||||||
// TODO tostring usr + food + prestige \n tab foreach(characters.cards + spazio)
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String toPrint = "";
|
int Last = 6;
|
||||||
toPrint = this.getUserName()
|
|
||||||
+ ":\n\tFood: " + this.getFoodValue()
|
var table = new AsciiTable(UNICODE, 1);
|
||||||
+ "\n\tPrestige: " + this.getPrestigeValue()
|
|
||||||
+ "\n\tArtists: " + this.artists.toString()
|
table.addHeader(this.getUserName());
|
||||||
+ "\n\tBuilders: " + this.builders.toString()
|
table.addRow("RESOURCES:");
|
||||||
+ "\n\tGatherers: " + this.gatherers.toString()
|
table.addRow("Food: " + this.getFoodValue());
|
||||||
+ "\n\tShamans: " + this.shamans.toString()
|
table.addSeparator();
|
||||||
+ "\n\tHunters: " + this.hunters.toString()
|
table.addRow("Prestige: " + this.getPrestigeValue());
|
||||||
+ "\n\tBuildings: "
|
|
||||||
+ this.buildingCards.toString();
|
if(!this.hunters.isEmpty()){
|
||||||
return toPrint;
|
Last = 6;
|
||||||
|
}
|
||||||
|
else if(!this.inventors.isEmpty()){
|
||||||
|
Last = 5;
|
||||||
|
}
|
||||||
|
else if(!this.shamans.isEmpty()){
|
||||||
|
Last = 4;
|
||||||
|
}
|
||||||
|
else if(!this.gatherers.isEmpty()){
|
||||||
|
Last = 3;
|
||||||
|
}
|
||||||
|
else if(!this.builders.isEmpty()){
|
||||||
|
Last = 2;
|
||||||
|
}
|
||||||
|
else if(!this.artists.isEmpty()){
|
||||||
|
Last = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Last = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Last == 0){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("CHARACTERS:");
|
||||||
|
if(!this.artists.isEmpty()){
|
||||||
|
if(Last == 1){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("Artists: " + this.artists.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.builders.isEmpty()){
|
||||||
|
if(Last == 2){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("Builders: " + this.builders.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.gatherers.isEmpty()){
|
||||||
|
if(Last == 3){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("Gatherers: " + this.gatherers.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.shamans.isEmpty()){
|
||||||
|
if(Last == 4){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("Shamans: " + this.shamans.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.inventors.isEmpty()){
|
||||||
|
if(Last == 5){
|
||||||
|
table.addSeparator();
|
||||||
|
}
|
||||||
|
table.addRow("Inventors: " + this.inventors.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!this.hunters.isEmpty()){
|
||||||
|
table.addSeparator();
|
||||||
|
table.addRow("Hunters: " + this.hunters.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
table.addRow("BUILDING CARDS:");
|
||||||
|
if(!this.buildingCards.isEmpty()){
|
||||||
|
table.addRow("Buildings: " + this.buildingCards.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return table.build();
|
||||||
}
|
}
|
||||||
// endregion functions
|
// endregion functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ public class AsciiTable {
|
|||||||
|
|
||||||
private String rpad(String s, int w) {
|
private String rpad(String s, int w) {
|
||||||
if (s.length() >= w) return s.substring(0, w);
|
if (s.length() >= w) return s.substring(0, w);
|
||||||
return s + " ".repeat(w - s.length());
|
return s + " ".repeat(w - s.length()) + "\t";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,8 +143,4 @@ class Building0Test {
|
|||||||
b0.buy(p1);
|
b0.buy(p1);
|
||||||
assertFalse(b0.buy(p2));
|
assertFalse(b0.buy(p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+22
-1
@@ -3,7 +3,6 @@ package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
|
|||||||
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Hunter;
|
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -109,4 +108,26 @@ class Building11Test {
|
|||||||
b4.applyEffect(p5);
|
b4.applyEffect(p5);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
|
||||||
|
b11 = new Building11(1,2,3, CharacterType.BUILDER, 1);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b11.toString());
|
||||||
|
|
||||||
|
b11 = new Building11(1,2,3, CharacterType.GATHERER, 1);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b11.toString());
|
||||||
|
|
||||||
|
b11 = new Building11(1,2,3, CharacterType.ARTIST, 1);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b11.toString());
|
||||||
|
|
||||||
|
b11 = new Building11(1,2,3, CharacterType.SHAMAN, 1);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b11.toString());
|
||||||
|
|
||||||
|
b11 = new Building11(1,2,3, CharacterType.HUNTER, 1);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b11.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -66,4 +66,26 @@ class Building1Test {
|
|||||||
assertEquals(Prestige, bClone.getPrestigeValue());
|
assertEquals(Prestige, bClone.getPrestigeValue());
|
||||||
assertEquals(ct, b0.getIcon());
|
assertEquals(ct, b0.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
|
||||||
|
b1 = new Building1(1,2,3, CharacterType.BUILDER);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString());
|
||||||
|
|
||||||
|
b1 = new Building1(1,2,3, CharacterType.GATHERER);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString());
|
||||||
|
|
||||||
|
b1 = new Building1(1,2,3, CharacterType.ARTIST);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString());
|
||||||
|
|
||||||
|
b1 = new Building1(1,2,3, CharacterType.SHAMAN);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString());
|
||||||
|
|
||||||
|
b1 = new Building1(1,2,3, CharacterType.HUNTER);
|
||||||
|
assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -200,17 +200,14 @@ class PlayerTest {
|
|||||||
p.addPrestige(15);
|
p.addPrestige(15);
|
||||||
p.addFood(7);
|
p.addFood(7);
|
||||||
p.artists.add(new Artist(1));
|
p.artists.add(new Artist(1));
|
||||||
|
p.artists.add(new Artist(1));
|
||||||
|
p.artists.add(new Artist(1));
|
||||||
|
p.artists.add(new Artist(1));
|
||||||
|
p.artists.add(new Artist(1));
|
||||||
|
p.artists.add(new Artist(1));
|
||||||
p.artists.add(new Artist(2));
|
p.artists.add(new Artist(2));
|
||||||
p.buildingCards.add(new BuildingCard(2, 1,2, 5));
|
p.buildingCards.add(new BuildingCard(2, 1,2, 5));
|
||||||
p.buildingCards.add(new BuildingCard(2, 2,3, 6));
|
p.buildingCards.add(new BuildingCard(2, 2,3, 6));
|
||||||
assertEquals("test_usr:"+ "\n\t" +
|
System.out.println(p.toString());
|
||||||
"Food: 7" + "\n\t" +
|
|
||||||
"Prestige: 15" + "\n\t" +
|
|
||||||
"Artists: [Era:1 ARTIST, Era:2 ARTIST]" + "\n\t" + "Builders: []" + "\n\t" +
|
|
||||||
"Gatherers: []" + "\n\t" +
|
|
||||||
"Shamans: []" + "\n\t" +
|
|
||||||
"Hunters: []" + "\n\t" +
|
|
||||||
"Buildings: [Era:1 Price:2 Prestige:5, Era:2 Price:3 Prestige:6]",
|
|
||||||
p.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user