Fix: Order

This commit is contained in:
rubenpirreram
2026-04-26 16:35:20 +02:00
parent 5aeefa72bb
commit 7da3b1f0d9
@@ -1,21 +1,22 @@
package it.polimi.ingsw.gc14.Model; 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.Orders.OrderPlayer;
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; 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 { public abstract class OrderLogicCard implements Serializable {
/** /**
* The queue of players associated with this order logic card. * 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. * 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) { public OrderLogicCard(ArrayList<Player> players) {
Collections.shuffle(players); Collections.shuffle(players);
this.players = new LinkedList<>(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){ public void push(Player player){
effect(player,players.size()); effect(player,players.size());
if(players.size()==0)
{
playerList=new ArrayList<>();
}
playerList.add(new OrderPlayer(player,false));
players.add(player); 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. * @return the first player in the queue, or {@code null} if the queue is empty.
*/ */
public Player pull(){ public Player pull(){
for(OrderPlayer p:playerList){
if(p.played==false)
{
p.played=true;
break;
}
}
return players.poll(); 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()) for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
player.addFood(1); 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;
}
} }