Merge branch 'main' into Game-test-fix
This commit is contained in:
@@ -85,10 +85,10 @@ public class ClientLauncherTUI {
|
|||||||
}
|
}
|
||||||
switch(action) {
|
switch(action) {
|
||||||
case "0" -> controller.slotChoice(username, pos);
|
case "0" -> controller.slotChoice(username, pos);
|
||||||
case "1" -> controller.drawUpperBuildingCard(username, pos);
|
case "1" -> controller.drawUpperTribeCard(username, pos);
|
||||||
case "2" -> controller.drawUpperTribeCard(username, pos);
|
case "2" -> controller.drawUpperBuildingCard(username, pos);
|
||||||
case "3" -> controller.drawLowerBuildingCard(username, pos);
|
case "3" -> controller.drawLowerTribeCard(username, pos);
|
||||||
case "4" -> controller.drawLowerTribeCard(username, pos);
|
case "4" -> controller.drawLowerBuildingCard(username, pos);
|
||||||
case "5" -> controller.pickOptionalTribeCard(username, pos);
|
case "5" -> controller.pickOptionalTribeCard(username, pos);
|
||||||
case "6" -> controller.pickOptionalBuildingCard(username, pos);
|
case "6" -> controller.pickOptionalBuildingCard(username, pos);
|
||||||
case "7" -> controller.noOptionalCard(username);
|
case "7" -> controller.noOptionalCard(username);
|
||||||
|
|||||||
@@ -159,8 +159,16 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
* @return {@code true} if the building card is successfully bought,
|
* @return {@code true} if the building card is successfully bought,
|
||||||
* {@code false} otherwise.
|
* {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
|
// sum reduction value builder=> sconto
|
||||||
public boolean buy(Player player) {
|
public boolean buy(Player player) {
|
||||||
if( bought || !player.removeFood(getPrice()))
|
int discount = 0;
|
||||||
|
discount = player.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
|
|
||||||
|
if(discount > this.price){
|
||||||
|
discount = this.price;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bought || !player.removeFood(this.price - discount))
|
||||||
return false;
|
return false;
|
||||||
player.buildingCards.add(this);
|
player.buildingCards.add(this);
|
||||||
bought=true;
|
bought=true;
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ public class Game implements Serializable {
|
|||||||
{
|
{
|
||||||
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
|
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
|
||||||
HashMap<Player,Integer> optional=new LinkedHashMap<>();
|
HashMap<Player,Integer> optional=new LinkedHashMap<>();
|
||||||
for (Player p : playersList) {
|
for (Player p : orderLogicCard.players) {
|
||||||
int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count();
|
int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count();
|
||||||
if(tempCount>0)
|
if(tempCount>0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public class Board implements Serializable {
|
|||||||
/** Contains all the building cards of the upper list. When a new era starts, the old era's buildings are moved from the upper to the lower list */
|
/** Contains all the building cards of the upper list. When a new era starts, the old era's buildings are moved from the upper to the lower list */
|
||||||
public List<BuildingCard> lowerListBuilding;
|
public List<BuildingCard> lowerListBuilding;
|
||||||
|
|
||||||
|
|
||||||
|
private final ArrayList<List<BuildingCard>> buildingCardsAllEras;
|
||||||
/** Number of players */
|
/** Number of players */
|
||||||
private int nTotem;
|
private int nTotem;
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ public class Board implements Serializable {
|
|||||||
tribeDeck=generateTribeDeck(nTotem);
|
tribeDeck=generateTribeDeck(nTotem);
|
||||||
era=1;
|
era=1;
|
||||||
|
|
||||||
|
|
||||||
for(int i=0;i<nTotem+1;i++)
|
for(int i=0;i<nTotem+1;i++)
|
||||||
{
|
{
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
@@ -110,10 +113,44 @@ public class Board implements Serializable {
|
|||||||
|
|
||||||
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
|
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
|
||||||
Collections.shuffle(buildingDeck);
|
Collections.shuffle(buildingDeck);
|
||||||
|
buildingCardsAllEras= new ArrayList<>();
|
||||||
|
buildingCardsAllEras.add(new ArrayList<>());
|
||||||
|
buildingCardsAllEras.add(new ArrayList<>());
|
||||||
|
buildingCardsAllEras.add(new ArrayList<>());
|
||||||
if(nTotem==2)
|
if(nTotem==2)
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 1)));
|
||||||
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,1));
|
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,1));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 2)));
|
||||||
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,2));
|
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,2));
|
||||||
|
}
|
||||||
|
|
||||||
|
buildingDeck=new ArrayList<>(DecksCreator.loadBuildingDeckByEra(2));
|
||||||
|
Collections.shuffle(buildingDeck);
|
||||||
|
if(nTotem<=3)
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(1, new ArrayList<BuildingCard>(buildingDeck.subList(0, 2)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(1, new ArrayList<BuildingCard>(buildingDeck.subList(0, 3)));
|
||||||
|
}
|
||||||
|
buildingDeck=new ArrayList<>(DecksCreator.loadBuildingDeckByEra(3));
|
||||||
|
Collections.shuffle(buildingDeck);
|
||||||
|
if(nTotem==2)
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(2, new ArrayList<BuildingCard>(buildingDeck.subList(0, 3)));
|
||||||
|
}else if(nTotem==5)
|
||||||
|
{
|
||||||
|
buildingCardsAllEras.set(2, new ArrayList<BuildingCard>(buildingDeck.subList(0, 5)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buildingCardsAllEras.set(2, new ArrayList<BuildingCard>(buildingDeck.subList(0, 4)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,27 +267,11 @@ public class Board implements Serializable {
|
|||||||
Collections.shuffle(buildingCards);
|
Collections.shuffle(buildingCards);
|
||||||
if(era==2)
|
if(era==2)
|
||||||
{
|
{
|
||||||
if(nTotem<=3)
|
upperListBuilding.addAll(buildingCardsAllEras.get(1));
|
||||||
{
|
|
||||||
upperListBuilding.addAll(buildingCards.subList(0,2));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
upperListBuilding.addAll( buildingCards.subList(0,3));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // Era 3
|
else
|
||||||
{
|
{
|
||||||
if(nTotem==2)
|
upperListBuilding.addAll(buildingCardsAllEras.get(2));
|
||||||
{
|
|
||||||
upperListBuilding.addAll( buildingCards.subList(0,3));
|
|
||||||
}else if(nTotem==5)
|
|
||||||
{
|
|
||||||
upperListBuilding.addAll( buildingCards.subList(0,5));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
upperListBuilding.addAll(buildingCards.subList(0,4));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
|||||||
if (controller.addPlayer(username)) {
|
if (controller.addPlayer(username)) {
|
||||||
clients.put(username, callback);
|
clients.put(username, callback);
|
||||||
playerList.add(username);
|
playerList.add(username);
|
||||||
|
System.out.println("Accepted player: " + username);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
|||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||||
|
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
@@ -56,6 +57,8 @@ public class ServerLauncher {
|
|||||||
*/
|
*/
|
||||||
static LimitedList<String> playerList;
|
static LimitedList<String> playerList;
|
||||||
|
|
||||||
|
TUI view;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor that initializes the attributes.
|
* Class constructor that initializes the attributes.
|
||||||
@@ -137,11 +140,14 @@ public class ServerLauncher {
|
|||||||
System.out.println("\n\nNotifying model");
|
System.out.println("\n\nNotifying model");
|
||||||
serverRMI.notifyAll(gameController.getModel());
|
serverRMI.notifyAll(gameController.getModel());
|
||||||
serverTCP.notifyAll(gameController.getModel());
|
serverTCP.notifyAll(gameController.getModel());
|
||||||
|
this.view = new TUI(gameController.getModel());
|
||||||
|
this.view.fullRender();
|
||||||
|
|
||||||
// Game execution
|
// Game execution
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
this.doFirstEvent();
|
this.doFirstEvent();
|
||||||
|
this.view.fullRender();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class Building11Test {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("toString")
|
@DisplayName("toString")
|
||||||
void testToString(){
|
void testToString(){
|
||||||
|
int ID = 11;
|
||||||
int era = 1;
|
int era = 1;
|
||||||
int price = 1;
|
int price = 1;
|
||||||
int prestigeValue = 3;
|
int prestigeValue = 3;
|
||||||
@@ -119,26 +120,26 @@ class Building11Test {
|
|||||||
int pm = 5;
|
int pm = 5;
|
||||||
|
|
||||||
Building11 b11 = new Building11(era, price, prestigeValue, ct, pm);
|
Building11 b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
|
|
||||||
ct = CharacterType.BUILDER;
|
ct = CharacterType.BUILDER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
|
|
||||||
ct = CharacterType.GATHERER;
|
ct = CharacterType.GATHERER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
|
|
||||||
ct = CharacterType.HUNTER;
|
ct = CharacterType.HUNTER;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
|
|
||||||
ct = CharacterType.INVENTOR;
|
ct = CharacterType.INVENTOR;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
|
|
||||||
ct = CharacterType.SHAMAN;
|
ct = CharacterType.SHAMAN;
|
||||||
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
b11 = new Building11(era, price, prestigeValue, ct, pm);
|
||||||
assertEquals("⎕: " + "ID:11" + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+24
-12
@@ -70,22 +70,34 @@ class Building1Test {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("toString")
|
@DisplayName("toString")
|
||||||
void testToString(){
|
void testToString(){
|
||||||
Building1 b1 = new Building1(1,2,3, CharacterType.INVENTOR);
|
int ID = 1;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b1.toString());
|
int era = 1;
|
||||||
|
int price = 1;
|
||||||
|
int prestigeValue = 3;
|
||||||
|
CharacterType ct = CharacterType.ARTIST;
|
||||||
|
int pm = 5;
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.BUILDER);
|
Building1 b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString());
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.GATHERER);
|
ct = CharacterType.BUILDER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString());
|
b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.ARTIST);
|
ct = CharacterType.GATHERER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString());
|
b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.SHAMAN);
|
ct = CharacterType.HUNTER;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString());
|
b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
b1 = new Building1(1,2,3, CharacterType.HUNTER);
|
ct = CharacterType.INVENTOR;
|
||||||
assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString());
|
b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
|
|
||||||
|
ct = CharacterType.SHAMAN;
|
||||||
|
b1 = new Building1(era, price, prestigeValue, ct);
|
||||||
|
assertEquals("⎕: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Cards;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13;
|
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -149,12 +150,162 @@ class BuildingCardTest {
|
|||||||
assertFalse(bc0.buy(p2));
|
assertFalse(bc0.buy(p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing the buy method with discounts")
|
||||||
|
void testBuyDiscount() {
|
||||||
|
int food = 5;
|
||||||
|
int price = 5;
|
||||||
|
int RV = 1;
|
||||||
|
|
||||||
|
Player p = new Player("test");
|
||||||
|
p.addFood(food);
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Testing that to pay == price - 1
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p));
|
||||||
|
|
||||||
|
int discount = p.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
|
assertEquals(food - price + discount, p.getFoodValue());
|
||||||
|
|
||||||
|
p.removeFood(p.getFoodValue());
|
||||||
|
p.addFood(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Testing that to pay == 0
|
||||||
|
p.removeFood(p.getFoodValue());
|
||||||
|
p.addFood(food);
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p));
|
||||||
|
|
||||||
|
assertEquals(food, p.getFoodValue());
|
||||||
|
|
||||||
|
p.removeFood(p.getFoodValue());
|
||||||
|
p.addFood(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Testing that to pay == 0; discount shouldn't go below 0
|
||||||
|
p.removeFood(p.getFoodValue());
|
||||||
|
p.addFood(food);
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
p.builders.add(new Builder(1, RV, 1));
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p));
|
||||||
|
|
||||||
|
assertEquals(food, p.getFoodValue());
|
||||||
|
|
||||||
|
p.removeFood(p.getFoodValue());
|
||||||
|
p.addFood(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Testing that to pay == 0 if price < builder b * b.RV
|
||||||
|
food = 6;
|
||||||
|
price = 3;
|
||||||
|
RV = 4;
|
||||||
|
|
||||||
|
Player p2 = new Player("test");
|
||||||
|
p2.addFood(food);
|
||||||
|
p2.builders.add(new Builder(1, RV, 1));
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p2.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p2));
|
||||||
|
|
||||||
|
int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
|
assertEquals(food, p2.getFoodValue());
|
||||||
|
|
||||||
|
p2.removeFood(p2.getFoodValue());
|
||||||
|
p2.addFood(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
p2.removeFood(p2.getFoodValue());
|
||||||
|
p2.addFood(food);
|
||||||
|
|
||||||
|
//Testing discount with staggered values
|
||||||
|
price = 7;
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p2.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p2));
|
||||||
|
|
||||||
|
int discount = p2.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
|
||||||
|
assertEquals(food - price + discount, p2.getFoodValue());
|
||||||
|
|
||||||
|
p2.removeFood(p2.getFoodValue());
|
||||||
|
p2.addFood(food);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Testing discount with staggered values; discount shouldn't go below 0
|
||||||
|
p2.builders.add(new Builder(1, RV, 1));
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard bc = new BuildingCard(ID, 1, price,1);
|
||||||
|
assertEquals(food, p2.getFoodValue());
|
||||||
|
assertTrue(bc.buy(p2));
|
||||||
|
|
||||||
|
assertEquals(food, p2.getFoodValue());
|
||||||
|
|
||||||
|
p2.removeFood(p2.getFoodValue());
|
||||||
|
p2.addFood(food);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Testing toString method")
|
@DisplayName("Testing toString method")
|
||||||
void testToString() {
|
void testToString() {
|
||||||
Building13 b0 = new Building13(1, 2,3);
|
int era = 2;
|
||||||
|
int price = 5;
|
||||||
|
int prestigeValue = 6;
|
||||||
|
|
||||||
assertEquals("Era:1 Price:2 Prestige:3", b0.toString());
|
BuildingCard b0 = new BuildingCard(era, price, prestigeValue);
|
||||||
|
assertEquals("⎕:" + " ID:0" + " $:"+ b0.getPrice() + " PV:" + b0.getPrestigeValue(), b0.toString());
|
||||||
|
|
||||||
|
for(int ID = 3; ID < 13; ID++){
|
||||||
|
if(ID == 4 || ID == 8 || ID == 10 || ID == 11){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BuildingCard b = new BuildingCard(ID, era, price, prestigeValue);
|
||||||
|
assertEquals("⎕:" + " ID:" + ID + " $:"+ b.getPrice() + " PV:" + b.getPrestigeValue(), b.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ class ArtistTest {
|
|||||||
String s = a.toString();
|
String s = a.toString();
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.ARTIST.toString()));
|
assertTrue(s.contains("⎕:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+2
-3
@@ -27,9 +27,8 @@ class BuilderTest {
|
|||||||
String s = b.toString();
|
String s = b.toString();
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.BUILDER.toString()));
|
assertFalse(s.contains(CharacterType.BUILDER.toString()));
|
||||||
assertTrue(s.contains("Reduction Value: 2"));
|
assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s);
|
||||||
assertTrue(s.contains("Prestige Value: 3"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+4
-1
@@ -13,8 +13,11 @@ class GathererTest {
|
|||||||
Gatherer g = new Gatherer(1);
|
Gatherer g = new Gatherer(1);
|
||||||
String s = g.toString();
|
String s = g.toString();
|
||||||
|
|
||||||
|
System.out.println(s);
|
||||||
|
|
||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertTrue(s.contains(CharacterType.GATHERER.toString()));
|
assertFalse(s.contains(CharacterType.GATHERER.toString()));
|
||||||
|
assertTrue(s.contains("⎕:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -125,11 +125,11 @@ class BoardTest {
|
|||||||
void removeUpperTribeCard() {
|
void removeUpperTribeCard() {
|
||||||
Board bd = new Board(3);
|
Board bd = new Board(3);
|
||||||
|
|
||||||
List<TribeCard> before = bd.upperListTribe;
|
List<TribeCard> before = new ArrayList<>( bd.upperListTribe);
|
||||||
TribeCard cardToRemove = before.get(2);
|
TribeCard cardToRemove = before.get(0);
|
||||||
|
|
||||||
before.remove(2);
|
assertEquals(cardToRemove, before.remove(0));
|
||||||
bd.removeUpperTribeCard(cardToRemove);
|
assertTrue( bd.removeUpperTribeCard(cardToRemove));
|
||||||
|
|
||||||
assertEquals(before, bd.upperListTribe);
|
assertEquals(before, bd.upperListTribe);
|
||||||
}
|
}
|
||||||
@@ -139,25 +139,25 @@ class BoardTest {
|
|||||||
void removeLowerTribeCard() {
|
void removeLowerTribeCard() {
|
||||||
Board bd = new Board(3);
|
Board bd = new Board(3);
|
||||||
|
|
||||||
List<TribeCard> before = bd.lowerListTribe;
|
List<TribeCard> before = new ArrayList<>(bd.lowerListTribe);
|
||||||
TribeCard cardToRemove = before.get(2);
|
TribeCard cardToRemove = before.get(0);
|
||||||
|
|
||||||
before.remove(2);
|
assertEquals(cardToRemove, before.remove(0));
|
||||||
bd.removeLowerTribeCard(cardToRemove);
|
assertTrue( bd.removeLowerTribeCard(cardToRemove));
|
||||||
|
|
||||||
assertEquals(before, bd.lowerListTribe);
|
assertEquals(before, bd.lowerListTribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("RemgetTribeDeckSizeoving a card from upper row of building cards")
|
@DisplayName("Removing a card from upper row of building cards")
|
||||||
void removeUpperBuildingCard() {
|
void removeUpperBuildingCard() {
|
||||||
Board bd = new Board(3);
|
Board bd = new Board(3);
|
||||||
|
|
||||||
List<BuildingCard> before = bd.upperListBuilding;
|
List<BuildingCard> before = new ArrayList<>(bd.upperListBuilding);
|
||||||
BuildingCard cardToRemove = before.get(0);
|
BuildingCard cardToRemove = before.get(0);
|
||||||
|
|
||||||
before.remove(0);
|
assertEquals(cardToRemove, before.remove(0));
|
||||||
bd.removeUpperBuildingCard(cardToRemove);
|
assertTrue( bd.removeUpperBuildingCard(cardToRemove));
|
||||||
|
|
||||||
assertEquals(before, bd.upperListBuilding);
|
assertEquals(before, bd.upperListBuilding);
|
||||||
}
|
}
|
||||||
@@ -171,12 +171,10 @@ class BoardTest {
|
|||||||
bd.nextRound(); // Skip to era 2
|
bd.nextRound(); // Skip to era 2
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BuildingCard> before = bd.lowerListBuilding;
|
List<BuildingCard> before = new ArrayList<>( bd.lowerListBuilding);
|
||||||
BuildingCard cardToRemove = before.get(0);
|
BuildingCard cardToRemove = before.get(0);
|
||||||
|
assertEquals(cardToRemove, before.remove(0));
|
||||||
before.remove(0);
|
assertTrue(bd.removeLowerBuildingCard(cardToRemove));
|
||||||
bd.removeLowerBuildingCard(cardToRemove);
|
|
||||||
|
|
||||||
assertEquals(before, bd.lowerListBuilding);
|
assertEquals(before, bd.lowerListBuilding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +212,8 @@ class BoardTest {
|
|||||||
assertEquals(upperListBefore, bd1.lowerListBuilding);
|
assertEquals(upperListBefore, bd1.lowerListBuilding);
|
||||||
assertNotEquals(upperListBefore, bd1.upperListBuilding);
|
assertNotEquals(upperListBefore, bd1.upperListBuilding);
|
||||||
assertEquals(2, bd1.upperListBuilding.size());
|
assertEquals(2, bd1.upperListBuilding.size());
|
||||||
|
assertTrue(bd1.upperListBuilding.stream().allMatch(x->x.getEra()==2));
|
||||||
|
assertTrue(bd1.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
|
||||||
|
|
||||||
|
|
||||||
// Era 2, nTotem > 3
|
// Era 2, nTotem > 3
|
||||||
@@ -227,7 +227,8 @@ class BoardTest {
|
|||||||
assertEquals(upperListBefore, bd2.lowerListBuilding);
|
assertEquals(upperListBefore, bd2.lowerListBuilding);
|
||||||
assertNotEquals(upperListBefore, bd2.upperListBuilding);
|
assertNotEquals(upperListBefore, bd2.upperListBuilding);
|
||||||
assertEquals(3, bd2.upperListBuilding.size());
|
assertEquals(3, bd2.upperListBuilding.size());
|
||||||
|
assertTrue(bd2.upperListBuilding.stream().allMatch(x->x.getEra()==2));
|
||||||
|
assertTrue(bd2.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
|
||||||
|
|
||||||
// Era 3, nTotem == 2
|
// Era 3, nTotem == 2
|
||||||
numPlayer = 2;
|
numPlayer = 2;
|
||||||
@@ -243,6 +244,8 @@ class BoardTest {
|
|||||||
assertEquals(upperListBefore, bd3.lowerListBuilding);
|
assertEquals(upperListBefore, bd3.lowerListBuilding);
|
||||||
assertNotEquals(upperListBefore, bd3.upperListBuilding);
|
assertNotEquals(upperListBefore, bd3.upperListBuilding);
|
||||||
assertEquals(3, bd3.upperListBuilding.size());
|
assertEquals(3, bd3.upperListBuilding.size());
|
||||||
|
assertTrue(bd3.upperListBuilding.stream().allMatch(x->x.getEra()==3));
|
||||||
|
assertTrue(bd3.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
|
||||||
|
|
||||||
|
|
||||||
// Era 3, nTotem == 5
|
// Era 3, nTotem == 5
|
||||||
@@ -259,6 +262,8 @@ class BoardTest {
|
|||||||
assertEquals(upperListBefore, bd4.lowerListBuilding);
|
assertEquals(upperListBefore, bd4.lowerListBuilding);
|
||||||
assertNotEquals(upperListBefore, bd4.upperListBuilding);
|
assertNotEquals(upperListBefore, bd4.upperListBuilding);
|
||||||
assertEquals(5, bd4.upperListBuilding.size());
|
assertEquals(5, bd4.upperListBuilding.size());
|
||||||
|
assertTrue(bd4.upperListBuilding.stream().allMatch(x->x.getEra()==3));
|
||||||
|
assertTrue(bd4.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
|
||||||
|
|
||||||
|
|
||||||
// Era 3, nTotem != 2, 5
|
// Era 3, nTotem != 2, 5
|
||||||
@@ -275,6 +280,8 @@ class BoardTest {
|
|||||||
assertEquals(upperListBefore, bd5.lowerListBuilding);
|
assertEquals(upperListBefore, bd5.lowerListBuilding);
|
||||||
assertNotEquals(upperListBefore, bd5.upperListBuilding);
|
assertNotEquals(upperListBefore, bd5.upperListBuilding);
|
||||||
assertEquals(4, bd5.upperListBuilding.size());
|
assertEquals(4, bd5.upperListBuilding.size());
|
||||||
|
assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3));
|
||||||
|
assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user