Merge remote-tracking branch 'origin/toString-fixes' into toString-fixes
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
@@ -691,4 +703,22 @@ 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> stringDown=new ArrayList<>();
|
||||
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
|
||||
{
|
||||
|
||||
stringDown.add(entry.getKey().toStringTUI());
|
||||
if(entry.getValue()!=null)
|
||||
stringUp.add(entry.getValue().getUserName());
|
||||
else
|
||||
stringUp.add(" ");
|
||||
}
|
||||
table.addRow(stringUp);
|
||||
table.addRow(stringDown);
|
||||
return orderLogicCard.toString()+"\nOFFER TRACK\n"+ table.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
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 Prestige");
|
||||
table.addRow(stringList);
|
||||
return "TURN ORDER\n" + table.build() + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,21 +57,29 @@ public class Order3 extends OrderLogicCard {
|
||||
{
|
||||
|
||||
var table = new AsciiTable(BorderStyle.UNICODE, 3);
|
||||
List<Player> tempPlayer=new ArrayList<>(players);
|
||||
List<String> stringList=new ArrayList<>();
|
||||
|
||||
List<String> stringUp=new ArrayList<>();
|
||||
List<String> stringDown=new ArrayList<>();
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
try {
|
||||
tempPlayer.get(i);
|
||||
stringList.add(i+". "+tempPlayer.get(i).getUserName());
|
||||
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) {
|
||||
stringList.add(i+". ");
|
||||
stringUp.add("");
|
||||
stringDown.add("");
|
||||
}
|
||||
}
|
||||
table.addRow(stringList);
|
||||
stringList=new ArrayList<>();
|
||||
table.addRow(stringUp);
|
||||
table.addRow(stringDown);
|
||||
|
||||
List<String> stringList=new ArrayList<>();
|
||||
|
||||
stringList.add("+2 Food");
|
||||
stringList.add(" --");
|
||||
stringList.add("-1 Food / -2 Prestige");
|
||||
|
||||
@@ -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 Prestige");
|
||||
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 Prestige");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user