Coverage Summary for Class: Order3 (it.polimi.ingsw.gc14.Model.Orders)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| Order3 |
100%
(1/1)
|
100%
(3/3)
|
88.9%
(16/18)
|
96%
(24/25)
|
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;
/**
* Represents the order logic card used in a three-player game.
*
* <p>This class defines the specific turn-order behavior for games with
* three players.
*/
public class Order3 extends OrderLogicCard {
/**
* Creates an Order3 logic card for a three-player game.
*
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 3.
*/
public Order3(ArrayList<Player> players) throws NoSuchElementException{
super(players);
if(players.size()!=3)
throw new NoSuchElementException();
}
/**
* Applies the effect associated with the specified position index for the given player.
* <p>If {@code index == 0}, the player gains 2 Food and the building effect is applied.
* <p>If {@code index == 1}, no effect is applied.
* <p>If {@code index == 2}, the player tries to remove 1 Food; if the player cannot pay it,
* the player loses 2 Prestige.
*
* @param player the player to whom the effect is applied.
* @param index the position index of the effect to apply.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= 3}.
*/
@Override
protected void effect(Player player,int index) throws IndexOutOfBoundsException
{
if(index >= 3 || index < 0)
{
throw new IndexOutOfBoundsException("index out of bounds");
}
if(index==0)
{
player.addFood(2);
buildingEffect(player);
return;
}
if(index==2){
if(!player.removeFood(1)){
player.removePrestige(2);
}
}
}
/**
* Creates the TURN ORDER box of the TUI.
* @return the string containing the box
*/
@Override
public String toString()
{
var table = new AsciiTable(BorderStyle.ROUNDED, 3);
List<String> stringUp=new ArrayList<>();
for(int i=0;i<3;i++)
{
try {
if(playerList.get(i).isPlayed())
stringUp.add("");
else
stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
}
}
table.addRow(stringUp);
List<String> stringList=new ArrayList<>();
stringList.add("+2\uD83C\uDF56");
stringList.add("--");
stringList.add("-1\uD83C\uDF56/-2\uD83C\uDFC5");
table.addRow(stringList);
return table.build() + "\n";
}
}