@@ -23,6 +23,11 @@ public abstract class EventCard extends TribeCard {
|
||||
@Override
|
||||
public abstract TribeCard clone();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString()+" "+type.toString();
|
||||
}
|
||||
|
||||
public abstract void activateEvent (ArrayList <Player> playerList);
|
||||
// End Functions
|
||||
}
|
||||
|
||||
@@ -55,6 +55,14 @@ public class Board {
|
||||
return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size of the TribeDeck
|
||||
*/
|
||||
public int getTribeDeckSize() {
|
||||
return this.tribeDeck.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and initialize a new board:
|
||||
* - Generate the slotList using a method of DecksCreator
|
||||
@@ -71,7 +79,7 @@ public class Board {
|
||||
upperListTribe=new ArrayList<>();
|
||||
lowerListTribe=new ArrayList<>();
|
||||
lowerListBuilding=new ArrayList<>();
|
||||
tribeDeck=getTribeDeck(nTotem);
|
||||
tribeDeck=generateTribeDeck(nTotem);
|
||||
era=1;
|
||||
|
||||
for(int i=0;i<nTotem+1;i++)
|
||||
@@ -113,7 +121,7 @@ public class Board {
|
||||
* - Era 3
|
||||
* - Special events
|
||||
*/
|
||||
private Queue<TribeCard> getTribeDeck(int nPlayers) {
|
||||
private Queue<TribeCard> generateTribeDeck(int nPlayers) {
|
||||
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||
ArrayList<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||
ArrayList<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||
@@ -185,6 +193,7 @@ public class Board {
|
||||
public int nextRound() {
|
||||
lowerListTribe.clear();
|
||||
lowerListTribe.addAll(upperListTribe);
|
||||
upperListTribe.clear();
|
||||
|
||||
for(int i=0;i<nTotem+4;i++)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ package it.polimi.ingsw.gc14.Model.Orders;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ public class Slot {
|
||||
public String toString() {
|
||||
return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n");
|
||||
}
|
||||
|
||||
// End Constructors
|
||||
|
||||
// Functions
|
||||
|
||||
@@ -269,7 +269,7 @@
|
||||
"era": 1,
|
||||
"armed": false,
|
||||
"params": [
|
||||
4
|
||||
1
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,54 +1,189 @@
|
||||
package it.polimi.ingsw.gc14.Model.GamePackage;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
||||
import it.polimi.ingsw.gc14.Model.DecksCreator;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BoardTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Slot initialization")
|
||||
void getSlotList() {
|
||||
//Board board = new Board(3);
|
||||
//assertEquals("Ciao", board.getSlotList().toString());
|
||||
// 0 players
|
||||
Board b0 = new Board(0);
|
||||
assertEquals('B', b0.getSlotList().get(0).getSlotId());
|
||||
assertEquals('C', b0.getSlotList().get(1).getSlotId());
|
||||
assertEquals('E', b0.getSlotList().get(2).getSlotId());
|
||||
assertEquals('F', b0.getSlotList().get(3).getSlotId());
|
||||
|
||||
// 1 players
|
||||
Board b1 = new Board(1);
|
||||
assertEquals('B', b1.getSlotList().get(0).getSlotId());
|
||||
assertEquals('C', b1.getSlotList().get(1).getSlotId());
|
||||
assertEquals('E', b1.getSlotList().get(2).getSlotId());
|
||||
assertEquals('F', b1.getSlotList().get(3).getSlotId());
|
||||
|
||||
// 2 players
|
||||
Board b2 = new Board(2);
|
||||
assertEquals('B', b2.getSlotList().get(0).getSlotId());
|
||||
assertEquals('C', b2.getSlotList().get(1).getSlotId());
|
||||
assertEquals('E', b2.getSlotList().get(2).getSlotId());
|
||||
assertEquals('F', b2.getSlotList().get(3).getSlotId());
|
||||
|
||||
// 3 players
|
||||
Board b3 = new Board(3);
|
||||
assertEquals('B', b3.getSlotList().get(0).getSlotId());
|
||||
assertEquals('C', b3.getSlotList().get(1).getSlotId());
|
||||
assertEquals('D', b3.getSlotList().get(2).getSlotId());
|
||||
assertEquals('E', b3.getSlotList().get(3).getSlotId());
|
||||
assertEquals('F', b3.getSlotList().get(4).getSlotId());
|
||||
|
||||
// 4 players
|
||||
Board b4 = new Board(4);
|
||||
assertEquals('B', b4.getSlotList().get(0).getSlotId());
|
||||
assertEquals('C', b4.getSlotList().get(1).getSlotId());
|
||||
assertEquals('D', b4.getSlotList().get(2).getSlotId());
|
||||
assertEquals('E', b4.getSlotList().get(3).getSlotId());
|
||||
assertEquals('F', b4.getSlotList().get(4).getSlotId());
|
||||
assertEquals('G', b4.getSlotList().get(5).getSlotId());
|
||||
|
||||
// 5 players
|
||||
Board b5 = new Board(5);
|
||||
assertEquals('A', b5.getSlotList().get(0).getSlotId());
|
||||
assertEquals('B', b5.getSlotList().get(1).getSlotId());
|
||||
assertEquals('C', b5.getSlotList().get(2).getSlotId());
|
||||
assertEquals('D', b5.getSlotList().get(3).getSlotId());
|
||||
assertEquals('E', b5.getSlotList().get(4).getSlotId());
|
||||
assertEquals('F', b5.getSlotList().get(5).getSlotId());
|
||||
assertEquals('G', b5.getSlotList().get(6).getSlotId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing TribeDeck size with different player number")
|
||||
void getTribeDeckSize() {
|
||||
Board bd2 = new Board(2);
|
||||
Board bd3 = new Board(3);
|
||||
Board bd4 = new Board(4);
|
||||
Board bd5 = new Board(5);
|
||||
|
||||
assertEquals(61 + 2 - (2+4) - (2+1), bd2.getTribeDeckSize());
|
||||
assertEquals(72 + 2 - (3+4) - (3+1), bd3.getTribeDeckSize());
|
||||
assertEquals(83 + 2 - (4+4) - (4+1), bd4.getTribeDeckSize());
|
||||
assertEquals(94 + 2 - (5+4) - (5+1), bd5.getTribeDeckSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing constructor")
|
||||
void testConstructor() {
|
||||
int numPlayer = 5;
|
||||
Board bd = new Board(numPlayer);
|
||||
|
||||
assertEquals(96 - (numPlayer+4) - (numPlayer+1), bd.getTribeDeckSize()); // Verifica che dal mazzo TribeDeck venga pescato il numero corretto di carte
|
||||
|
||||
assertEquals(numPlayer+1, bd.lowerListTribe.size()); // Verifica che la dimensione della lista inferiore sia corretta
|
||||
assertTrue(bd.lowerListTribe.stream().noneMatch(card -> card.IsEventCard())); // Verifica che non ci siano EventCard dentro alla lista inferiore
|
||||
|
||||
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la dimensione della lista superiore sia corretta
|
||||
|
||||
assertEquals(2, bd.upperListBuilding.size()); // Verifica che ci sia il giusto numero di buildings (2 edifici per 3+ giocatori)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("get events testing")
|
||||
void getPendingEvents() {
|
||||
Board bd = new Board(0);
|
||||
|
||||
Queue<EventCard> eventQueue = new LinkedList<>();
|
||||
for (TribeCard card : bd.lowerListTribe) {
|
||||
if (card.IsEventCard()) {
|
||||
eventQueue.add((EventCard) card);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(eventQueue, bd.getPendingEvents());
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsUpperTribeCard() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Removing a card from upper row of tribe cards")
|
||||
void removeUpperTribeCard() {
|
||||
Board bd = new Board(3);
|
||||
|
||||
List<TribeCard> before = bd.upperListTribe;
|
||||
TribeCard cardToRemove = before.get(2);
|
||||
|
||||
before.remove(2);
|
||||
bd.removeUpperTribeCard(cardToRemove);
|
||||
|
||||
assertEquals(before, bd.upperListTribe);
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsLowerTribeCard() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Removing a card from lower row of tribe cards")
|
||||
void removeLowerTribeCard() {
|
||||
Board bd = new Board(3);
|
||||
|
||||
List<TribeCard> before = bd.lowerListTribe;
|
||||
TribeCard cardToRemove = before.get(2);
|
||||
|
||||
before.remove(2);
|
||||
bd.removeLowerTribeCard(cardToRemove);
|
||||
|
||||
assertEquals(before, bd.lowerListTribe);
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsUpperBuildingCard() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("RemgetTribeDeckSizeoving a card from upper row of building cards")
|
||||
void removeUpperBuildingCard() {
|
||||
Board bd = new Board(3);
|
||||
|
||||
List<BuildingCard> before = bd.upperListBuilding;
|
||||
BuildingCard cardToRemove = before.get(0);
|
||||
|
||||
before.remove(0);
|
||||
bd.removeUpperBuildingCard(cardToRemove);
|
||||
|
||||
assertEquals(before, bd.upperListBuilding);
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsLowerBuildingCard() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Removing a card from lower row of building cards")
|
||||
void removeLowerBuildingCard() {
|
||||
Board bd = new Board(3);
|
||||
bd.lowerListBuilding.add(new BuildingCard(2, 1, 5, 10));
|
||||
bd.lowerListBuilding.add(new BuildingCard(3, 2, 2, 1));
|
||||
|
||||
|
||||
List<BuildingCard> before = bd.lowerListBuilding;
|
||||
BuildingCard cardToRemove = before.get(0);
|
||||
|
||||
before.remove(0);
|
||||
bd.removeUpperBuildingCard(cardToRemove);
|
||||
|
||||
assertEquals(before, bd.lowerListBuilding);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Testing next round")
|
||||
void nextRound() {
|
||||
int numPlayer = 3;
|
||||
Board bd = new Board(numPlayer);
|
||||
assertTrue(!bd.lowerListTribe.isEmpty());
|
||||
List<TribeCard> upperListBefore = new ArrayList<>(bd.upperListTribe);
|
||||
|
||||
bd.nextRound();
|
||||
assertEquals(upperListBefore, bd.lowerListTribe); // Verifica che la lista superiore è stata spostata sotto
|
||||
assertNotEquals(upperListBefore, bd.upperListTribe); // Verifica che la lista superiore sia stata cambiata
|
||||
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la nuova dimensione della lista superiore sia corretta
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user