Files
Progetto-ingegneria-del-sof…/deliverables/Coverage/htmlReport/ns-a/sources/source-1.html
T
2026-06-19 21:50:38 +02:00

425 lines
16 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > Board</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.GamePackage</a>
</div>
<h1>Coverage Summary for Class: Board (it.polimi.ingsw.gc14.Model.GamePackage)</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">Board</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(1/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(16/16)
</span>
</td>
<td class="coverageStat">
<span class="percent">
96.7%
</span>
<span class="absValue">
(29/30)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(82/82)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model.GamePackage;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
&nbsp;import it.polimi.ingsw.gc14.Model.DecksCreator;
&nbsp;import it.polimi.ingsw.gc14.Model.Slot;
&nbsp;
&nbsp;import java.io.Serializable;
&nbsp;import java.util.*;
&nbsp;import java.util.stream.Collectors;
&nbsp;
&nbsp;/**
&nbsp; * Board manages all the elements during the game such as decks, upper and lower rows, totems, tiles...
&nbsp; */
&nbsp;public class Board implements Serializable {
&nbsp; /**
&nbsp; * slotList contains the ordered list of slots (tiles). The slots changes based on the number of players.
&nbsp; * Each slot (tile) has special action as drawing from the upper/lower row or taking food.
&nbsp; */
&nbsp; private List&lt;Slot&gt; slotList;
&nbsp;
&nbsp; /** tribeDeck is the deck from where you draw tribe cards as characters and events. */
&nbsp; private Queue&lt;TribeCard&gt; tribeDeck;
&nbsp;
&nbsp; /**
&nbsp; * The upper row of tribe cards. It contains a total of
&nbsp; * {@code nTotem + 4} tribe cards, which may include both character and event cards.
&nbsp; */
&nbsp; private List&lt;TribeCard&gt; upperListTribe;
&nbsp;
&nbsp; /**
&nbsp; * The lower row of the tribe card. During the first round, there will be (num. of players + 1) character cards.
&nbsp; * During the following rounds, lower row will be emptied and populated with upper row&#39;s cards.
&nbsp; * When an Event card gets in the lower row, the event effect will be activated at the end of the round.
&nbsp; */
&nbsp; private List&lt;TribeCard&gt; lowerListTribe;
&nbsp;
&nbsp; /** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here. */
&nbsp; private List&lt;BuildingCard&gt; upperListBuilding;
&nbsp;
&nbsp; /** Contains all the building cards of the lower list. When a new era starts, the old era&#39;s buildings are moved from the upper to the lower list. */
&nbsp; private List&lt;BuildingCard&gt; lowerListBuilding;
&nbsp;
&nbsp; /**
&nbsp; * Returns the upper row of tribe cards.
&nbsp; *
&nbsp; * @return the live upper tribe card list.
&nbsp; */
<b class="fc">&nbsp; public List&lt;TribeCard&gt; getUpperListTribe() { return upperListTribe; }</b>
&nbsp;
&nbsp; /**
&nbsp; * Returns the lower row of tribe cards.
&nbsp; *
&nbsp; * @return the live lower tribe card list.
&nbsp; */
<b class="fc">&nbsp; public List&lt;TribeCard&gt; getLowerListTribe() { return lowerListTribe; }</b>
&nbsp;
&nbsp; /**
&nbsp; * Returns the upper row of building cards.
&nbsp; *
&nbsp; * @return the live upper building card list.
&nbsp; */
<b class="fc">&nbsp; public List&lt;BuildingCard&gt; getUpperListBuilding() { return upperListBuilding; }</b>
&nbsp;
&nbsp; /**
&nbsp; * Returns the lower row of building cards.
&nbsp; *
&nbsp; * @return the live lower building card list.
&nbsp; */
<b class="fc">&nbsp; public List&lt;BuildingCard&gt; getLowerListBuilding() { return lowerListBuilding; }</b>
&nbsp;
&nbsp; // TODO
&nbsp; private final ArrayList&lt;List&lt;BuildingCard&gt;&gt; buildingCardsAllEras;
&nbsp; /** Number of players */
&nbsp; private int nTotem;
&nbsp;
&nbsp; /** Current era of the game */
&nbsp; private int era;
&nbsp;
&nbsp; /**
&nbsp; * Creates and returns a new list containing the slots (tiles) of the game.
&nbsp; *
&nbsp; * @return a copy of the slot list.
&nbsp; */
&nbsp; public List&lt;Slot&gt; getSlotList(){
<b class="fc">&nbsp; return slotList.stream().map(x-&gt;new Slot(x.getSlotId())).collect(Collectors.toList());</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * @return the size of the TribeDeck
&nbsp; */
&nbsp; public int getTribeDeckSize() {
<b class="fc">&nbsp; return this.tribeDeck.size();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * @return the game era
&nbsp; */
<b class="fc">&nbsp; public int getEra() {return this.era;}</b>
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Creates and initializes a new board:
&nbsp; * - Generate the slotList using a method of DecksCreator.
&nbsp; * - Generate the tribeDeck.
&nbsp; * - Populate the lower list (if there is an event card, it&#39;s added to the upper list).
&nbsp; * - Populate the upper list.
&nbsp; * - Generate the buildingDeck using a method of DecksCreator.
&nbsp; *
&nbsp; * @param nTotem the number of players.
&nbsp; */
<b class="fc">&nbsp; public Board(int nTotem) {</b>
<b class="fc">&nbsp; this.nTotem = nTotem;</b>
<b class="fc">&nbsp; this.slotList = DecksCreator.loadSlotDeck().stream().filter(x-&gt;x.getNMinPlayer()&lt;=nTotem).sorted(Comparator.comparingInt(Slot::getSlotId)).toList();</b>
<b class="fc">&nbsp; upperListTribe=new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; lowerListTribe=new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; lowerListBuilding=new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; tribeDeck=generateTribeDeck(nTotem);</b>
<b class="fc">&nbsp; era=1;</b>
&nbsp;
&nbsp;
<b class="fc">&nbsp; for(int i=0;i&lt;nTotem+1;i++)</b>
&nbsp; {
<b class="fc">&nbsp; TribeCard tempCard = tribeDeck.remove();</b>
<b class="fc">&nbsp; if(tempCard.isEventCard())</b>
&nbsp; {
<b class="fc">&nbsp; upperListTribe.add(tempCard);</b>
<b class="fc">&nbsp; i--;</b>
&nbsp; }
&nbsp; else
&nbsp; {
<b class="fc">&nbsp; lowerListTribe.add(tempCard);</b>
&nbsp; }
&nbsp; }
&nbsp;
<b class="fc">&nbsp; for(int i=upperListTribe.size();i&lt;nTotem+4;i++)</b>
&nbsp; {
<b class="fc">&nbsp; TribeCard tempCard = tribeDeck.remove();</b>
<b class="fc">&nbsp; upperListTribe.add(tempCard);</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; ArrayList&lt;BuildingCard&gt; buildingDeck = new ArrayList&lt;&gt;(DecksCreator.loadBuildingDeckByEra(1));</b>
<b class="fc">&nbsp; Collections.shuffle(buildingDeck);</b>
<b class="fc">&nbsp; buildingCardsAllEras= new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; buildingCardsAllEras.add(new ArrayList&lt;&gt;());</b>
<b class="fc">&nbsp; buildingCardsAllEras.add(new ArrayList&lt;&gt;());</b>
<b class="fc">&nbsp; buildingCardsAllEras.add(new ArrayList&lt;&gt;());</b>
<b class="fc">&nbsp; if(nTotem==2)</b>
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(0, new ArrayList&lt;&gt;(buildingDeck.subList(0, 1)));</b>
<b class="fc">&nbsp; upperListBuilding = new ArrayList&lt;&gt;(buildingDeck.subList(0,1));</b>
&nbsp; }
&nbsp; else
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(0, new ArrayList&lt;&gt;(buildingDeck.subList(0, 2)));</b>
<b class="fc">&nbsp; upperListBuilding = new ArrayList&lt;&gt;(buildingDeck.subList(0,2));</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; buildingDeck=new ArrayList&lt;&gt;(DecksCreator.loadBuildingDeckByEra(2));</b>
<b class="fc">&nbsp; Collections.shuffle(buildingDeck);</b>
<b class="fc">&nbsp; if(nTotem&lt;=3)</b>
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(1, new ArrayList&lt;BuildingCard&gt;(buildingDeck.subList(0, 2)));</b>
&nbsp; }
&nbsp; else
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(1, new ArrayList&lt;BuildingCard&gt;(buildingDeck.subList(0, 3)));</b>
&nbsp; }
<b class="fc">&nbsp; buildingDeck=new ArrayList&lt;&gt;(DecksCreator.loadBuildingDeckByEra(3));</b>
<b class="fc">&nbsp; Collections.shuffle(buildingDeck);</b>
<b class="fc">&nbsp; if(nTotem==2)</b>
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(2, new ArrayList&lt;BuildingCard&gt;(buildingDeck.subList(0, 3)));</b>
<b class="fc">&nbsp; }else if(nTotem==5)</b>
&nbsp; {
<b class="fc">&nbsp; buildingCardsAllEras.set(2, new ArrayList&lt;BuildingCard&gt;(buildingDeck.subList(0, 5)));</b>
&nbsp; }
&nbsp; else {
<b class="fc">&nbsp; buildingCardsAllEras.set(2, new ArrayList&lt;BuildingCard&gt;(buildingDeck.subList(0, 4)));</b>
&nbsp; }
&nbsp;
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates the tribeDeck. Loads the cards from each era, shuffle them, and then combine them in the final deck.
&nbsp; * In the end, two special events (Sustenance and ShamanicRitual) are added.
&nbsp; *
&nbsp; * @param nPlayers the number of players.
&nbsp; * @return a queue containing the cards in this order:
&nbsp; * - Era 1.
&nbsp; * - Era 2.
&nbsp; * - Era 3.
&nbsp; * - Special events.
&nbsp; */
&nbsp; private Queue&lt;TribeCard&gt; generateTribeDeck(int nPlayers) {
<b class="fc">&nbsp; ArrayList&lt;TribeCard&gt; era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x-&gt;x.getNMin()&lt;=nPlayers).collect(Collectors.toCollection(ArrayList::new));</b>
<b class="fc">&nbsp; ArrayList&lt;TribeCard&gt; era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x-&gt;x.getNMin()&lt;=nPlayers).collect(Collectors.toCollection(ArrayList::new));</b>
<b class="fc">&nbsp; ArrayList&lt;TribeCard&gt; era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x-&gt;x.getNMin()&lt;=nPlayers).collect(Collectors.toCollection(ArrayList::new));</b>
<b class="fc">&nbsp; Collections.shuffle(era1);</b>
<b class="fc">&nbsp; Collections.shuffle(era2);</b>
<b class="fc">&nbsp; Collections.shuffle(era3);</b>
&nbsp;
<b class="fc">&nbsp; Queue&lt;TribeCard&gt; tribeDeck_temp=new LinkedList&lt;&gt;();</b>
<b class="fc">&nbsp; tribeDeck_temp.addAll(era1);</b>
<b class="fc">&nbsp; tribeDeck_temp.addAll(era2);</b>
<b class="fc">&nbsp; tribeDeck_temp.addAll(era3);</b>
<b class="fc">&nbsp; tribeDeck_temp.add(new Sustenance(&quot;095&quot;,3,3));</b>
<b class="fc">&nbsp; tribeDeck_temp.add(new ShamanicRitual(&quot;096&quot;,3,15,7));</b>
<b class="fc">&nbsp; return tribeDeck_temp;</b>
&nbsp; }
&nbsp;
&nbsp; /** @return the queue of events cards from the lower list that need to be activated */
&nbsp; public Queue&lt;EventCard&gt; getPendingEvents(){
<b class="fc">&nbsp; return lowerListTribe.stream().filter(TribeCard::isEventCard).map(x-&gt;(EventCard)x).collect(Collectors.toCollection(LinkedList::new));</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Take the selected card from the upper tribe list of the board.
&nbsp; *
&nbsp; * @param tribeCard is the card to remove.
&nbsp; * @return true if the card is succesfully removed.
&nbsp; */
&nbsp; public boolean removeUpperTribeCard(TribeCard tribeCard) {
<b class="fc">&nbsp; return upperListTribe.remove(tribeCard);</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Take the selected card from the lower tribe list of the board.
&nbsp; *
&nbsp; * @param tribeCard is the card to remove.
&nbsp; * @return true if succeed in removing the card.
&nbsp; */
&nbsp; public boolean removeLowerTribeCard(TribeCard tribeCard) {
<b class="fc">&nbsp; return lowerListTribe.remove(tribeCard);</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Take the selected card from the upper building list of the board.
&nbsp; *
&nbsp; * @param buildingCard is the card to remove.
&nbsp; * @return true if succeed in removing the card.
&nbsp; */
&nbsp; public boolean removeUpperBuildingCard(BuildingCard buildingCard) {
<b class="fc">&nbsp; return upperListBuilding.remove(buildingCard);</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Take the selected card from the lower building list of the board.
&nbsp; *
&nbsp; * @param buildingCard is the card to remove.
&nbsp; * @return true if succeed in removing the card.
&nbsp; */
&nbsp; public boolean removeLowerBuildingCard(BuildingCard buildingCard) {
<b class="fc">&nbsp; return lowerListBuilding.remove(buildingCard);</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Goes to the next round.
&nbsp; * - Clear the lower tribe row.
&nbsp; * - Moves the upper tribe row to the lower one.
&nbsp; * - Populate the upper tribe row.
&nbsp; *
&nbsp; * @return the current era after moving to the next round.
&nbsp; */
&nbsp; public int nextRound() {
<b class="fc">&nbsp; lowerListTribe.clear();</b>
<b class="fc">&nbsp; lowerListTribe.addAll(upperListTribe);</b>
<b class="fc">&nbsp; upperListTribe.clear();</b>
&nbsp;
<b class="fc">&nbsp; for(int i=0;i&lt;nTotem+4;i++)</b>
&nbsp; {
<b class="pc">&nbsp; if (tribeDeck.isEmpty()) break;</b>
<b class="fc">&nbsp; TribeCard tempCard = tribeDeck.remove();</b>
<b class="fc">&nbsp; if(tempCard.getEra()!=era)</b>
&nbsp; {
<b class="fc">&nbsp; nextEra();</b>
&nbsp; }
<b class="fc">&nbsp; upperListTribe.add(tempCard);</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; return era;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Changes the era of the game:
&nbsp; * - Increase the era attribute.
&nbsp; * - Clear the lower building list and replace it with the upper building list.
&nbsp; * - Repopulate the upper building list.
&nbsp; */
&nbsp; private void nextEra() {
<b class="fc">&nbsp; era=era+1;</b>
<b class="fc">&nbsp; lowerListBuilding.clear();</b>
<b class="fc">&nbsp; lowerListBuilding.addAll(upperListBuilding);</b>
<b class="fc">&nbsp; upperListBuilding.clear();</b>
&nbsp;
<b class="fc">&nbsp; if(era==2)</b>
&nbsp; {
<b class="fc">&nbsp; upperListBuilding.addAll(buildingCardsAllEras.get(1));</b>
&nbsp; }
&nbsp; else
&nbsp; {
<b class="fc">&nbsp; upperListBuilding.addAll(buildingCardsAllEras.get(2));</b>
&nbsp; }
&nbsp; }
&nbsp;}
</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-14 21:53</div>
</div>
</body>
</html>