Fix: Order
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user