Merge branch 'main' into tests-fix

This commit is contained in:
rubenpirreram
2026-04-30 19:59:33 +02:00
committed by GitHub
59 changed files with 1539 additions and 292 deletions
@@ -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.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.Player;
import java.util.HashMap;
/**
* 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());
}
@Override
public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0);
}
}
@@ -6,6 +6,7 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
public class Building11 extends BuildingCard {
private CharacterType icon ;
/**
@@ -14,6 +15,7 @@ public class Building11 extends BuildingCard {
* @return the CharacterType associated with this building card effect.
*/
public CharacterType getIcon() {return icon;}
private int PrestigeMul;
/**
@@ -65,4 +67,9 @@ public class Building11 extends BuildingCard {
throw new IllegalArgumentException();
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
}
@Override
public String toString() {
return super.toString() + " Icon: " + this.icon.toString().charAt(0) + " MP: " + this.PrestigeMul;
}
}
@@ -182,6 +182,6 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
*/
@Override
public String toString() {
return "Era:"+String.valueOf(getEra())+" Price:"+String.valueOf(getPrice())+" Prestige:"+String.valueOf(getPrestigeValue());
return ":" + " ID:" + String.valueOf(getEffectId())+ " $:"+String.valueOf(getPrice())+" PV:"+String.valueOf(getPrestigeValue());
}
}
@@ -57,7 +57,13 @@ public abstract class Character extends TribeCard implements Cloneable {
*/
@Override
public String toString() {
return super.toString()+" "+type.toString();
return super.toString();
}
@Override
public String toStringBoard()
{
return super.toStringBoard()+" "+getType().toString()+" ";
}
/**
@@ -86,7 +86,15 @@ public class Builder extends Character
* @return the string representation of this Builder card.
*/
@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);
}
@Override
public String toStringBoard()
{
return super.toStringBoard()+" "+ " RV:" + String.valueOf(reductionValue) + " PV:" + String.valueOf(prestigeValue);
}
/**
* Creates and returns a copy of this Builder card.
@@ -47,8 +47,21 @@ public class Hunter extends Character {
*/
@Override
public String toString() {
return super.toString() + "Icon: " + String.valueOf(icon);
String toPrint = super.toString();
if(this.icon){
toPrint += " I";
}
return toPrint;
}
@Override
public String toStringBoard() {
String toPrint = super.toStringBoard();
if(this.icon){
toPrint += " I";
}
return toPrint;
}
/**
* Creates and returns a copy of this Hunter card.
@@ -52,7 +52,11 @@ public class Inventor extends Character {
*/
@Override
public String toString() {
return super.toString() + " Symbol:" + String.valueOf(icon);
return super.toString() + " I_ID:" + String.valueOf(icon);
}
@Override
public String toStringBoard() {
return super.toStringBoard() + " I_ID:" + String.valueOf(icon);
}
/**
@@ -49,8 +49,13 @@ public class Shaman extends Character {
*/
@Override
public String toString() {
return super.toString() + "Icon: " + String.valueOf(icon);
return super.toString() + " *:" + String.valueOf(icon);
}
@Override
public String toStringBoard() {
return super.toStringBoard() + " *:" + String.valueOf(icon);
}
/**
* Creates and returns a copy of this Shaman card.
@@ -62,7 +62,11 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toString() {
return super.toString()+", "+type.toString();
return super.toString()+" "+type.toString();
}
@Override
public String toStringBoard() {
return super.toString()+" "+type.toString();
}
/**
@@ -85,4 +85,9 @@ public class CavePaintings extends EventCard {
{
return new CavePaintings(getEra(), NLower, NPrestigeRem, NPrestigeMul) ;
}
@Override
public String toStringBoard() {
return super.toString()+" 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul;
}
}
@@ -70,5 +70,9 @@ public class Hunt extends EventCard {
public EventCard clone() {
return new Hunt(getEra(), prestigeMultiplier);
}
@Override
public String toStringBoard() {
return super.toString()+" 1F+"+prestigeMultiplier+"PP"+" X N Hunter";
}
}
@@ -96,6 +96,9 @@ public class ShamanicRitual extends EventCard {
public EventCard clone() {
return new ShamanicRitual(getEra(), prestigeToAdd, prestigeToRemove);
}
@Override
public String toStringBoard() {
return super.toString()+" *>:"+prestigeToAdd+" *<:"+prestigeToRemove;
}
}
@@ -89,4 +89,9 @@ public class Sustenance extends EventCard {
public EventCard clone() {
return new Sustenance(getEra(), PrestigeDebt);
}
@Override
public String toStringBoard() {
return super.toString()+" -1F/-"+PrestigeDebt+"PP";
}
}
@@ -18,6 +18,9 @@ import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import it.polimi.ingsw.gc14.Network.Observer;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
/**
* Represents the main game model.
* A Game object stores the players, the current state of the match,
@@ -36,6 +39,15 @@ public class Game implements Serializable {
o.update(this);
}
}
/**
* Returns the list of players participating in the game.
* @return
*/
public List<Player> getPlayers() {
return playersList;
}
/**
* The current number of players.
*/
@@ -746,4 +758,90 @@ public class Game implements Serializable {
return true;
}
@Override
public String toString() {
var table = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
List<String> stringUp=new ArrayList<>();
List<String> stringEmpty=new ArrayList<>();
List<String> stringDown=new ArrayList<>();
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
{
stringEmpty.add(" ");
stringDown.add(entry.getKey().toStringTUI());
if(entry.getValue()!=null)
stringUp.add(entry.getValue().getUserName());
else
stringUp.add(" ");
}
table.addRow(stringUp);
table.addRow(stringEmpty);
table.addRow(stringDown);
List<String>lines=List.of(orderLogicCard.toString().split("\n"));
List<String> lines2=new ArrayList<>();
lines2.add("OFFER TRACK");
lines2.addAll(List.of(table.build().split("\n")));
String boardToString=AsciiTable.sideBySide(lines,lines2,1);
var table2 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size()));
List<String> stringUp2=new ArrayList<>();
List<String> stringDown2=new ArrayList<>();
for(int i=0;i<Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size());i++)
{
if(i<getUpperListTribeCards().size())
{
stringUp2.add(getUpperListTribeCards().get(i).toStringBoard());
}
else
{
stringUp2.add("");
}
if(i<getLowerListTribeCards().size())
{
stringDown2.add(getLowerListTribeCards().get(i).toStringBoard());
}
else
{
stringDown2.add("");
}
}
table2.addRow(stringUp2);
table2.addRow(stringDown2);
var table3 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListBuilding().size(),getLowerListBuilding().size()));
List<String> stringUp3=new ArrayList<>();
List<String> stringDown3=new ArrayList<>();
for(int i=0;i<Math.max(getUpperListBuilding().size(),getLowerListBuilding().size());i++)
{
if(i<getUpperListBuilding().size())
{
stringUp3.add(getUpperListBuilding().get(i).toString());
}
else
{
stringUp3.add("-");
}
if(i<getLowerListBuilding().size())
{
stringDown3.add(getLowerListBuilding().get(i).toString());
}
else
{
stringDown3.add("-");
}
}
table3.addRow(stringUp3);
table3.addRow(stringDown3);
String PlayerToString ="";
for(Player p:playersList)
{
PlayerToString+=p.toString()+"\n";
}
return PlayerToString+"\n"+ boardToString +"UPPERList\\LOWERList\n"+table2.build() + "\nBUILDING\n"+table3.build() + "\n";
//return s.toString()+"\n"++"\nOFFER TRACK\n"+ table.build()+"\n" ;
}
}
@@ -111,9 +111,9 @@ public class Board implements Serializable {
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
Collections.shuffle(buildingDeck);
if(nTotem==2)
upperListBuilding= buildingDeck.subList(0,1);
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,1));
else
upperListBuilding= buildingDeck.subList(0,2);
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,2));
}
/**
@@ -1,21 +1,22 @@
package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
/**
* Abstract base class for all order logic cards.
* An OrderLogicCard manages a queue of players and defines the effects
* applied when players are pushed back into the queue.
*/
public abstract class OrderLogicCard implements Serializable {
/**
* The queue of players associated with this order logic card.
*/
private Queue<Player> players;
protected Queue<Player> players;
protected List<OrderPlayer> playerList;
/**
* Creates an order logic card with the specified list of players.
@@ -26,6 +27,8 @@ public abstract class OrderLogicCard implements Serializable {
public OrderLogicCard(ArrayList<Player> players) {
Collections.shuffle(players);
this.players = new LinkedList<>(players);
this.playerList=new ArrayList<>(players.stream().map(x->new OrderPlayer(x,false)).toList());
}
/**
@@ -36,7 +39,15 @@ public abstract class OrderLogicCard implements Serializable {
*/
public void push(Player player){
effect(player,players.size());
if(players.size()==0)
{
playerList=new ArrayList<>();
}
playerList.add(new OrderPlayer(player,false));
players.add(player);
}
/**
@@ -45,6 +56,13 @@ public abstract class OrderLogicCard implements Serializable {
* @return the first player in the queue, or {@code null} if the queue is empty.
*/
public Player pull(){
for(OrderPlayer p:playerList){
if(p.played==false)
{
p.played=true;
break;
}
}
return players.poll();
}
@@ -79,4 +97,17 @@ public abstract class OrderLogicCard implements Serializable {
for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
player.addFood(1);
}
protected int getPosition(String username)
{
int pos = 0;
for (Player p : players) {
if (p.getUserName().equals(username))
return pos;
pos++;
}
return -1;
}
}
@@ -2,8 +2,11 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.util.*;
import java.util.stream.IntStream;
public class Order2 extends OrderLogicCard {
@@ -49,4 +52,35 @@ public class Order2 extends OrderLogicCard {
}
}
}
@Override
public String toString()
{
var table = new AsciiTable(BorderStyle.UNICODE, 2);
List<String> stringUp=new ArrayList<>();
List<String> 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");
else
stringDown.add(" Not Placed");
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+1 Food");
stringList.add("-1 Food / -2 PP");
table.addRow(stringList);
return "TURN ORDER\n" + table.build() + "\n";
}
}
@@ -2,8 +2,11 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class Order3 extends OrderLogicCard {
@@ -49,4 +52,40 @@ public class Order3 extends OrderLogicCard {
}
}
}
@Override
public String toString()
{
var table = new AsciiTable(BorderStyle.UNICODE, 3);
List<String> stringUp=new ArrayList<>();
List<String> 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");
else
stringDown.add(" Not Placed");
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+2 Food");
stringList.add("--");
stringList.add("-1 Food / -2 PP");
table.addRow(stringList);
return "TURN ORDER\n" + table.build() + "\n";
}
}
@@ -2,8 +2,11 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class Order4 extends OrderLogicCard {
@@ -57,4 +60,37 @@ public class Order4 extends OrderLogicCard {
}
}
}
@Override
public String toString()
{
var table = new AsciiTable(BorderStyle.UNICODE, 4);
List<String> stringUp=new ArrayList<>();
List<String> 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");
else
stringDown.add(" Not Placed");
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+2 Food");
stringList.add("+1 Food");
stringList.add("--");
stringList.add("-1 Food / -2 PP");
table.addRow(stringList);
return "TURN ORDER\n" + table.build() + "\n";
}
}
@@ -2,8 +2,11 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class Order5 extends OrderLogicCard {
@@ -58,4 +61,38 @@ public class Order5 extends OrderLogicCard {
}
}
}
@Override
public String toString()
{
var table = new AsciiTable(BorderStyle.UNICODE, 5);
List<String> stringUp=new ArrayList<>();
List<String> 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");
else
stringDown.add(" Not Placed");
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+3 Food");
stringList.add("+1 Food");
stringList.add("--");
stringList.add("--");
stringList.add("-1 Food / -2 PP");
table.addRow(stringList);
return "TURN ORDER\n" + table.build() + "\n";
}
}
@@ -0,0 +1,21 @@
package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Player;
/**
* Abstract base class for all order logic cards.
* An OrderLogicCard manages a queue of players and defines the effects
* applied when players are pushed back into the queue.
*/
public class OrderPlayer{
public Player player;
public boolean played;
public OrderPlayer(Player player,boolean played){
this.player=player;
this.played=played;
}
@Override
public String toString() {
return player.getUserName()+" "+played;
}
}
@@ -43,6 +43,10 @@ public abstract class PlayableCard implements Serializable {
*/
@Override
public String toString() {
return "Era:"+String.valueOf(Era);
return ":";
}
public String toStringBoard()
{
return "⎕:";
}
}
@@ -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.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import java.io.Serializable;
import java.util.ArrayList;
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.
@@ -224,21 +228,91 @@ public class Player implements Serializable {
// endregion constructors
// region Functions
// TODO tostring usr + food + prestige \n tab foreach(characters.cards + spazio)
@Override
public String toString() {
String toPrint = "";
toPrint = this.getUserName()
+ ":\n\tFood: " + this.getFoodValue()
+ "\n\tPrestige: " + this.getPrestigeValue()
+ "\n\tArtists: " + this.artists.toString()
+ "\n\tBuilders: " + this.builders.toString()
+ "\n\tGatherers: " + this.gatherers.toString()
+ "\n\tShamans: " + this.shamans.toString()
+ "\n\tHunters: " + this.hunters.toString()
+ "\n\tBuildings: "
+ this.buildingCards.toString();
return toPrint;
int Last = 6;
var table = new AsciiTable(UNICODE, 1);
table.addHeader(this.getUserName());
table.addRow("RESOURCES:");
table.addRow("Food: " + this.getFoodValue());
table.addSeparator();
table.addRow("Prestige: " + this.getPrestigeValue());
if(!this.hunters.isEmpty()){
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
}
@@ -152,7 +152,25 @@ public class Slot implements Serializable {
*/
@Override
public String toString() {
return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n");
return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\n");
}
public String toStringTUI()
{
StringBuilder s = new StringBuilder();
s.append(this.getSlotId()+" ");
for(int i=0;i<this.getNUpper();i++)
{
s.append("");
}
for(int i=0;i<this.getNLower();i++)
{
s.append("");
}
if(getFood()!=0)
s.append("+"+getFood()+" Food");
return s.toString();
}
// End Constructors