291 lines
9.5 KiB
HTML
291 lines
9.5 KiB
HTML
|
|
|
|
|
|
<!DOCTYPE html>
|
|
<html id="htmlId">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
<title>Coverage Report > OrderLogicCard</title>
|
|
<style type="text/css">
|
|
@import "../../css/coverage.css";
|
|
@import "../../css/idea.min.css";
|
|
</style>
|
|
<script type="text/javascript" src="../../js/highlight.min.js"></script>
|
|
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="content">
|
|
<div class="breadCrumbs">
|
|
Current scope: <a href="../../index.html">all classes</a>
|
|
<span class="separator">|</span>
|
|
<a href="../index.html">it.polimi.ingsw.gc14.Model</a>
|
|
</div>
|
|
|
|
<h1>Coverage Summary for Class: OrderLogicCard (it.polimi.ingsw.gc14.Model)</h1>
|
|
|
|
<table class="coverageStats">
|
|
<tr>
|
|
<th class="name">Class</th>
|
|
<th class="coverageStat
|
|
">
|
|
Class, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Method, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Branch, %
|
|
</th>
|
|
<th class="coverageStat
|
|
">
|
|
Line, %
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<td class="name">OrderLogicCard</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
100%
|
|
</span>
|
|
<span class="absValue">
|
|
(1/1)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
80%
|
|
</span>
|
|
<span class="absValue">
|
|
(8/10)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
91.7%
|
|
</span>
|
|
<span class="absValue">
|
|
(11/12)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
86.7%
|
|
</span>
|
|
<span class="absValue">
|
|
(26/30)
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
<pre>
|
|
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Model;
|
|
|
|
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* Abstract base class for all order logic cards.
|
|
*
|
|
* <p>An order logic card manages the turn order of the players and defines
|
|
* the behavior used to update the order during the game.
|
|
*/
|
|
public abstract class OrderLogicCard implements Serializable {
|
|
|
|
/**
|
|
* The queue of {@link Player Players} associated with this order logic card.
|
|
*/
|
|
private final Queue<Player> players;
|
|
|
|
/**
|
|
* The list of {@link OrderPlayer} entries tracking turn order and played status.
|
|
* Protected so subclasses can read it for display purposes (e.g., {@link #toString()}).
|
|
*/
|
|
protected final List<OrderPlayer> playerList;
|
|
|
|
/**
|
|
* Returns an unmodifiable view of the player order list.
|
|
*
|
|
* @return the list of {@link OrderPlayer} entries in turn order.
|
|
*/
|
|
public List<OrderPlayer> getPlayerList() {
|
|
<b class="nc"> return Collections.unmodifiableList(playerList);</b>
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Creates an order logic card with the specified list of players.
|
|
*
|
|
* <p>The input list is shuffled in place to establish a random initial turn order.
|
|
* This is intentional: the caller's list (typically {@code Game.playersList}) is
|
|
* reordered so that the game's canonical player sequence reflects the randomized order.
|
|
*
|
|
* @param players the list of players associated with this order logic card.
|
|
* <strong>The list is mutated (shuffled) by this constructor.</strong>
|
|
*/
|
|
<b class="fc"> public OrderLogicCard(ArrayList<Player> players) {</b>
|
|
<b class="fc"> Collections.shuffle(players);</b>
|
|
<b class="fc"> this.players = new LinkedList<>(players);</b>
|
|
<b class="fc"> this.playerList = new ArrayList<>(players.stream().map(x -> new OrderPlayer(x, false)).toList());</b>
|
|
}
|
|
|
|
/**
|
|
* Applies the effect associated with the current queue position of the player
|
|
* and then adds the player to the end of the queue.
|
|
*
|
|
* @param player the player to be pushed into the queue.
|
|
*/
|
|
public void push(Player player) {
|
|
<b class="fc"> effect(player, players.size());</b>
|
|
<b class="fc"> if (players.isEmpty()) {</b>
|
|
<b class="fc"> playerList.clear();</b>
|
|
}
|
|
<b class="fc"> playerList.add(new OrderPlayer(player, false));</b>
|
|
<b class="fc"> players.add(player);</b>
|
|
}
|
|
|
|
/**
|
|
* Moves the specified player to the end of the queue without applying effects.
|
|
*
|
|
* <p>Any previous occurrence of the player is removed from both the queue
|
|
* and the order list before the player is added again.
|
|
*
|
|
* @param player the player to be pushed into the queue.
|
|
*/
|
|
public void pushNoEffect(Player player) {
|
|
<b class="fc"> players.removeIf(x -> player.getUserName().equals(x.getUserName()));</b>
|
|
<b class="fc"> playerList.removeIf(x -> player.getUserName().equals(x.getPlayer().getUserName()));</b>
|
|
<b class="fc"> playerList.add(new OrderPlayer(player, false));</b>
|
|
<b class="fc"> players.add(player);</b>
|
|
}
|
|
|
|
/**
|
|
* Removes and returns the first player in the queue.
|
|
*
|
|
* <p>The first order entry that has not yet been marked as played
|
|
* is marked as played before removing the player from the queue.
|
|
*
|
|
* @return the first player in the queue, or {@code null} if the queue is empty.
|
|
*/
|
|
public Player pull() {
|
|
<b class="fc"> for (OrderPlayer p : playerList) {</b>
|
|
<b class="fc"> if (!p.isPlayed()) {</b>
|
|
<b class="fc"> p.markAsPlayed();</b>
|
|
break;
|
|
}
|
|
}
|
|
<b class="fc"> return players.poll();</b>
|
|
}
|
|
|
|
/**
|
|
* Returns the first player in the queue without removing it.
|
|
*
|
|
* @return the first player in the queue, or {@code null} if the queue is empty.
|
|
*/
|
|
public Player getFirst()
|
|
{
|
|
<b class="fc"> return players.peek();</b>
|
|
}
|
|
|
|
/**
|
|
* Applies the effect associated with the specified player and queue position.
|
|
*
|
|
* @param player the player to whom the effect is applied.
|
|
* @param index the queue position index associated with the effect.
|
|
* @throws IndexOutOfBoundsException if the specified index is not valid.
|
|
*/
|
|
protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException;
|
|
|
|
/**
|
|
* Applies the building-related effect to the specified player.
|
|
* For each building card owned by the player with effect id equal to 3,
|
|
* the player gains 1 Food.
|
|
*
|
|
* @param player the player to whom the building effect is applied.
|
|
*/
|
|
protected void buildingEffect(Player player) {
|
|
<b class="fc"> long count = player.getBuildingCards().stream().filter(x -> x.getEffectId() == 3).count();</b>
|
|
<b class="fc"> player.addFood((int) count);</b>
|
|
}
|
|
|
|
/**
|
|
* Returns whether the given player is currently present in the turn queue.
|
|
*
|
|
* @param player the player to look up.
|
|
* @return {@code true} if the player is in the queue; {@code false} otherwise.
|
|
*/
|
|
public boolean containsInQueue(Player player) {
|
|
<b class="fc"> return players.contains(player);</b>
|
|
}
|
|
|
|
/**
|
|
* Removes the given player from both the turn queue and the order list.
|
|
* No-op if the player is not present.
|
|
*
|
|
* @param player the player to remove.
|
|
*/
|
|
public void removeFromQueue(Player player) {
|
|
<b class="nc"> players.removeIf(x -> x.equals(player));</b>
|
|
<b class="nc"> playerList.removeIf(x -> x.getPlayer().equals(player));</b>
|
|
}
|
|
|
|
/**
|
|
* Returns the position of the player associated with the specified username
|
|
* within the current order list.
|
|
*
|
|
* @param username the username of the player whose position is requested.
|
|
* @return the player's position, or {@code -1} if no player with the specified
|
|
* username is present in the order list.
|
|
* @see Player
|
|
*/
|
|
public int getPosition(String username) {
|
|
<b class="fc"> int pos = 0;</b>
|
|
<b class="pc"> for (OrderPlayer p : playerList) {</b>
|
|
<b class="fc"> if (p.getPlayer().getUserName().equals(username))</b>
|
|
<b class="fc"> return pos;</b>
|
|
<b class="fc"> pos++;</b>
|
|
}
|
|
<b class="nc"> return -1;</b>
|
|
}
|
|
|
|
|
|
}
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var msie = false, msie9 = false;
|
|
/*@cc_on
|
|
msie = true;
|
|
@if (@_jscript_version >= 9)
|
|
msie9 = true;
|
|
@end
|
|
@*/
|
|
|
|
if (!msie || msie && msie9) {
|
|
hljs.highlightAll()
|
|
hljs.initLineNumbersOnLoad();
|
|
}
|
|
})();
|
|
</script>
|
|
|
|
<div class="footer">
|
|
|
|
<div style="float:right;">generated on 2026-06-19 22:53</div>
|
|
</div>
|
|
</body>
|
|
</html>
|