addresses = ni.getInetAddresses();
+ while (addresses.hasMoreElements()) {
+ InetAddress addr = addresses.nextElement();
+ // Solo IPv4
+ if (addr instanceof Inet4Address) {
+ System.out.println("[" + ips.size() + "] " + ni.getDisplayName() + " -> " + addr.getHostAddress());
+ ips.add(addr.getHostAddress());
+ }
+ }
+ }
+
+ if (ips.isEmpty()) throw new Exception("Nessuna interfaccia disponibile");
+ if (ips.size() == 1) {
+ System.out.println("Una sola interfaccia trovata, uso: " + ips.get(0));
+ return ips.get(0);
+ }
+
+ System.out.print("Scegli interfaccia: ");
+ int choice = scanner.nextInt();
+ return ips.get(choice);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
index 144435f..9f52437 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java
@@ -1,12 +1,13 @@
package it.polimi.ingsw.gc14.Controller;
import it.polimi.ingsw.gc14.Model.Game;
-import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
-import it.polimi.ingsw.gc14.Network.Observer;
import it.polimi.ingsw.gc14.View.IView;
+import java.rmi.RemoteException;
+import java.util.Objects;
+
/**
* Controller class that holds all the components of the client, such as view, network client and Game Controller.
* It provides methods to set the client components and to execute requested actions.
@@ -50,7 +51,7 @@ public class ClientController {
*/
public void setModel(Game model) {
localController.setModel(model);
- view.update(localController.getModel());
+ view.setModel(localController.getModel());
}
@@ -70,7 +71,19 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawUpperTribeCard(String playerUsername, int pos) {
- client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
+
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ {
+ view.showError("It's not your turn!");
+ }
+ else
+ {
+ try {
+ client.drawUpperTribeCard(playerUsername, pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -81,7 +94,14 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawLowerTribeCard(String playerUsername,int pos) {
- client.doEvent(new DrawLowerTribeCard(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else
+ try {
+ client.drawLowerTribeCard(playerUsername, pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
}
@@ -92,7 +112,16 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawUpperBuildingCard(String playerUsername,int pos) {
- client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.drawUpperBuildingCard(playerUsername,pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
@@ -103,7 +132,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void drawLowerBuildingCard(String playerUsername,int pos) {
- client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.drawLowerBuildingCard(playerUsername,pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -113,7 +150,15 @@ public class ClientController {
* @param playerUsername the name of the player performing the action
*/
public void skipUpper(String playerUsername) {
- client.doEvent(new SkipUpper(playerUsername));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.skipUpper(playerUsername);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -122,7 +167,17 @@ public class ClientController {
* This action is available only when the lower list is empty or the player cannot draw any card.
* @param playerUsername the name of the player performing the action
*/
- public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));}
+ public void skipLower(String playerUsername) {
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.skipLower(playerUsername);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
/**
@@ -132,7 +187,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
- client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.pickOptionalTribeCard(playerUsername,pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -143,7 +206,15 @@ public class ClientController {
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
- client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.pickOptionalBuildingCard(playerUsername,pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -153,7 +224,15 @@ public class ClientController {
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
- client.doEvent(new NoOptionalCard(playerUsername));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.noOptionalCard(playerUsername);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@@ -163,7 +242,15 @@ public class ClientController {
* @param pos the index of the selected slot
*/
public void slotChoice(String playerUsername,int pos) {
- client.doEvent(new SlotChoice(playerUsername,pos));
+ if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
+ view.showError("It's not your turn!");
+ else {
+ try {
+ client.slotChoice(playerUsername,pos);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
index d67017d..0c4db48 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java
@@ -42,7 +42,7 @@ public class Building8 extends BuildingCard {
if(!player.buildingCards.contains(this))
throw new IllegalArgumentException();
for (Builder builder : player.builders) {
- player.addPrestige(builder.getPrestigeValue() * 2);
+ player.addPrestige(builder.getPrestigeValue());
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
index fa997e1..9770187 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java
@@ -167,8 +167,16 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @return {@code true} if the building card is successfully bought,
* {@code false} otherwise.
*/
+ // sum reduction value builder=> sconto
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;
player.buildingCards.add(this);
bought=true;
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java
index 2e18de0..6971681 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java
@@ -91,7 +91,6 @@ public class CavePaintings extends EventCard {
return new CavePaintings(getEra(), NLower, NPrestigeRem, NPrestigeMul) ;
}
-
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
@@ -111,6 +110,6 @@ public class CavePaintings extends EventCard {
*/
@Override
public String toStringBoard() {
- return super.toString()+" 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul;
+ return super.toStringBoard()+" 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul;
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java
index 4bf1e52..80870d2 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java
@@ -84,7 +84,7 @@ public class Hunt extends EventCard {
*/
@Override
public String toStringBoard() {
- return super.toString()+" 1F+"+prestigeMultiplier+"PP"+" X N Hunter";
+ return super.toStringBoard()+" 1F+"+prestigeMultiplier+"PP"+" X N Hunter";
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java
index 70703d5..1a65f10 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java
@@ -111,7 +111,7 @@ public class ShamanicRitual extends EventCard {
*/
@Override
public String toStringBoard() {
- return super.toString()+" *>:"+prestigeToAdd+" *<:"+prestigeToRemove;
+ return super.toStringBoard()+" *>:"+prestigeToAdd+" *<:"+prestigeToRemove;
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
index 8826d3d..ac53288 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java
@@ -48,7 +48,7 @@ public class Sustenance extends EventCard {
* If the resulting Food debt is positive, the player must pay it with available Food.
* If the player does not have enough Food, all remaining Food is removed and the player
* loses Prestige equal to the unpaid Food debt multiplied by {@code PrestigeDebt}.
- * This event is intended to be executed last among event effects.
+ * This event is intended to be executed last among event effects.
*
* @param playerList the list of players affected by the event.
* @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}.
@@ -108,6 +108,6 @@ public class Sustenance extends EventCard {
*/
@Override
public String toStringBoard() {
- return super.toString()+" -1F/-"+PrestigeDebt+"PP";
+ return super.toStringBoard()+" -1F/-"+PrestigeDebt+"PP";
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java
index db8fc1a..500a4a5 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java
@@ -4,6 +4,9 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
@@ -17,7 +20,8 @@ import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
-import it.polimi.ingsw.gc14.Network.Observer;
+import java.util.stream.Stream;
+
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
@@ -28,26 +32,6 @@ import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
*/
public class Game implements Serializable {
- /**
- * List of observers registered to receive updates when the game state changes.
- *
- * The list is marked as {@code transient} because observers should not be
- * serialized with the game model.
- */
- private transient List observers = new ArrayList<>(); // transient! non serializzare
-
-
- public void addObserver(Observer observer) {
- observers.add(observer);
- }
-
-
- private void notifyObservers() {
- for (Observer o : observers) {
- o.update(this);
- }
- }
-
/**
* Returns the list of players participating in the game.
*
@@ -250,6 +234,16 @@ public class Game implements Serializable {
orderLogicCard=new Order5(playersList);
break;
}
+ for(Player player : playersList)
+ {
+ switch(orderLogicCard.getPosition(player.getUserName()))
+ {
+ case 0: player.addFood(2); break;
+ case 1,2: player.addFood(3); break;
+ case 3,4: player.addFood(4); break;
+ }
+
+ }
currentState.PlayerUpdate(orderLogicCard.pull(),null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
}
@@ -282,6 +276,10 @@ public class Game implements Serializable {
{
return false;
}
+ if(slotPlayerEntry.getKey().getSlotId()=='A')
+ {
+ player.addFood(3);
+ }
slotMap.put(slotPlayerEntry.getKey(),player);
nextPlayerSetup();
return true;
@@ -306,7 +304,7 @@ public class Game implements Serializable {
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
return false;
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -342,7 +340,7 @@ public class Game implements Serializable {
* @return {@code true} if the skip succeeds, {@code false} otherwise.
*/
public boolean SkipUpperDrawing(Player player) {
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -373,7 +371,7 @@ public class Game implements Serializable {
* @return {@code true} if the skip succeeds, {@code false} otherwise.
*/
public boolean SkipLowerDrawing(Player player) {
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -407,7 +405,7 @@ public class Game implements Serializable {
public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
return false;
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -448,7 +446,7 @@ public class Game implements Serializable {
public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
return false;
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -487,7 +485,7 @@ public class Game implements Serializable {
public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
return false;
- if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
+ if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
return false;
}
@@ -532,7 +530,7 @@ public class Game implements Serializable {
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean PickOptionalTribeCardByIndex(Player player,int cardIndex) {
- if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
+ if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
@@ -567,7 +565,7 @@ public class Game implements Serializable {
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean PickOptionalBuildingCard(Player player, int cardIndex) {
- if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
+ if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
@@ -599,7 +597,7 @@ public class Game implements Serializable {
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean NoOptionalCard(Player player) {
- if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
+ if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
@@ -638,7 +636,7 @@ public class Game implements Serializable {
currentState.PlayerUpdate(tempPlayer, null);
return;
}
- currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
+ currentState.GameStageUpdate(GameStages.RES_ACTIONS);
for (Slot s : slotMap.keySet()) {
if (slotMap.get(s) != null) {
currentState.PlayerUpdate(slotMap.get(s), s);
@@ -654,7 +652,7 @@ public class Game implements Serializable {
return;
}
- if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
+ if(GameStages.RES_ACTIONS ==currentState.getGameStage()) {
orderLogicCard.push(currentState.getCurrentPlayer());
slotMap.put(currentState.getSlot(), null);
for (Slot s : slotMap.keySet()) {
@@ -673,9 +671,9 @@ public class Game implements Serializable {
}
if(slotMap.values().stream().allMatch(v -> v == null))
{
- currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
+ currentState.GameStageUpdate(GameStages.OPT_CARD_E);
HashMap optional=new LinkedHashMap<>();
- for (Player p : playersList) {
+ for (Player p : orderLogicCard.players) {
int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count();
if(tempCount>0)
{
@@ -694,14 +692,13 @@ public class Game implements Serializable {
return;
}
- currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
+ currentState.GameStageUpdate(GameStages.RES_EVENT);
if (currentState.getRound() < 10) {
nextRound();
currentState.PlayerUpdate(orderLogicCard.pull(), null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
} else {
- EventResolution();
currentState.GameStageUpdate(GameStages.ENDING);
endGame();
}
@@ -710,7 +707,7 @@ public class Game implements Serializable {
}
}
- if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
+ if (GameStages.OPT_CARD_E == currentState.getGameStage()) {
Player optionalPlayer = OptionalCardQueue.poll();
if (optionalPlayer != null) {
@@ -718,14 +715,13 @@ public class Game implements Serializable {
return;
}
- currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
+ currentState.GameStageUpdate(GameStages.RES_EVENT);
if (currentState.getRound() < 10) {
nextRound();
currentState.PlayerUpdate(orderLogicCard.pull(), null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
} else {
- EventResolution();
currentState.GameStageUpdate(GameStages.ENDING);
endGame();
}
@@ -768,7 +764,7 @@ public class Game implements Serializable {
*/
private void EventResolution() {
- if(currentState.getGameStage()!= GameStages.RESOLVING_EVENT)
+ if(currentState.getGameStage()!= GameStages.RES_EVENT)
{
return;
}
@@ -818,6 +814,28 @@ public class Game implements Serializable {
* and updating the game stage to {@code ENDED}.
*/
private void endGame() {
+ Queue events;
+ events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::IsEventCard),board.upperListTribe.stream().filter(TribeCard::IsEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
+ ArrayListsustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
+ events.removeAll(sustenance);
+ events.forEach(event->event.activateEvent(playersList));
+ sustenance.forEach(event->event.activateEvent(playersList));
+
+ playersList.forEach(p->{
+ int temp= p.builders.stream().mapToInt(Builder::getPrestigeValue).sum();
+ p.addPrestige(temp);
+ });
+ playersList.forEach(p->{
+ int temp=(int) p.inventors.stream().mapToInt(Inventor::Icon).distinct().count();
+ p.addPrestige(temp*p.getNType(CharacterType.INVENTOR));
+ });
+ playersList.forEach(p->{
+ p.addPrestige(10 * (p.getNType(CharacterType.ARTIST)/2));
+ });
+ playersList.forEach(p->{
+ int temp= p.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum();
+ p.addPrestige(temp);
+ });
playersList.forEach(
p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL).
forEach(x -> x.applyEffect(p))
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java
index afec513..473062e 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java
@@ -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 */
public List lowerListBuilding;
+
+ private final ArrayList> buildingCardsAllEras;
/** Number of players */
private int nTotem;
@@ -88,6 +90,7 @@ public class Board implements Serializable {
tribeDeck=generateTribeDeck(nTotem);
era=1;
+
for(int i=0;i buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
Collections.shuffle(buildingDeck);
+ buildingCardsAllEras= new ArrayList<>();
+ buildingCardsAllEras.add(new ArrayList<>());
+ buildingCardsAllEras.add(new ArrayList<>());
+ buildingCardsAllEras.add(new ArrayList<>());
if(nTotem==2)
+ {
+ buildingCardsAllEras.set(0, new ArrayList<>(buildingDeck.subList(0, 1)));
upperListBuilding = new ArrayList<>(buildingDeck.subList(0,1));
+ }
else
+ {
+ buildingCardsAllEras.set(0, 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(buildingDeck.subList(0, 2)));
+ }
+ else
+ {
+ buildingCardsAllEras.set(1, new ArrayList(buildingDeck.subList(0, 3)));
+ }
+ buildingDeck=new ArrayList<>(DecksCreator.loadBuildingDeckByEra(3));
+ Collections.shuffle(buildingDeck);
+ if(nTotem==2)
+ {
+ buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 3)));
+ }else if(nTotem==5)
+ {
+ buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 5)));
+ }
+ else {
+ buildingCardsAllEras.set(2, new ArrayList(buildingDeck.subList(0, 4)));
+ }
+
}
/**
@@ -231,27 +268,11 @@ public class Board implements Serializable {
Collections.shuffle(buildingCards);
if(era==2)
{
- if(nTotem<=3)
- {
- upperListBuilding.addAll(buildingCards.subList(0,2));
- }
- else
- {
- upperListBuilding.addAll( buildingCards.subList(0,3));
- }
+ upperListBuilding.addAll(buildingCardsAllEras.get(1));
}
- else // Era 3
+ else
{
- if(nTotem==2)
- {
- upperListBuilding.addAll( buildingCards.subList(0,3));
- }else if(nTotem==5)
- {
- upperListBuilding.addAll( buildingCards.subList(0,5));
- }
- else {
- upperListBuilding.addAll(buildingCards.subList(0,4));
- }
+ upperListBuilding.addAll(buildingCardsAllEras.get(2));
}
}
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java
index e272fbd..00b4376 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java
@@ -6,5 +6,5 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
* Represents the possible stages of a game.
*/
public enum GameStages {
- WAITING, SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT, ENDING, ENDED
+ WAITING, SLOT_CHOICE, RES_ACTIONS, OPT_CARD_E, RES_EVENT, ENDING, ENDED
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java
index 86f6435..a38a329 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/IClient.java
@@ -1,8 +1,33 @@
package it.polimi.ingsw.gc14.Network;
+import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
+
import java.rmi.RemoteException;
+import java.util.Objects;
public interface IClient {
public boolean connect(String username,int preferredInt);
- public void doEvent(NetworkEvent event) ;
+
+ public void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException;
+
+ public void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException;
+
+ public void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+
+ public void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+ public void skipUpper(String playerUsername) throws RemoteException;
+
+ public void skipLower(String playerUsername) throws RemoteException;
+
+
+ public void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException;
+
+ public void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+
+ public void noOptionalCard(String playerUsername) throws RemoteException;
+
+ public void slotChoice(String playerUsername,int pos) throws RemoteException;
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java b/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java
deleted file mode 100644
index 7677d92..0000000
--- a/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package it.polimi.ingsw.gc14.Network;
-
-import it.polimi.ingsw.gc14.Model.Game;
-
-public interface Observer {
- public void update(Game model);
-}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/ClientCallbackImpl.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/ClientCallbackImpl.java
index beb9c91..817e3d3 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/ClientCallbackImpl.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/ClientCallbackImpl.java
@@ -53,7 +53,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
@Override
public void onAction(NetworkEvent event) throws RemoteException {
if(event.getIsError()) {
- System.out.println(event.toString());
+ clientController.view.showError(event.toString());
} else {
event.apply(clientController.localController);
clientController.view.render();
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java
index be92164..141e01e 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java
@@ -1,11 +1,14 @@
package it.polimi.ingsw.gc14.Network.RMI.Client;
+import java.net.InetAddress;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
+import java.util.Objects;
import it.polimi.ingsw.gc14.Controller.ClientController;
import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
+import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
@@ -27,6 +30,7 @@ public class RMIClient implements IClient {
/** Client game's controller */
ClientController controller;
+ private String myIP;
/**
* Class constructor.
@@ -34,10 +38,11 @@ public class RMIClient implements IClient {
* @param host the host address of the RMI server
* @param port the port of the RMI server
*/
- public RMIClient(ClientController controller, String host, int port) {
+ public RMIClient(ClientController controller, String host, int port, String myIP) {
this.controller=controller;
this.host = host;
this.port = port;
+ this.myIP = myIP;
}
@@ -51,6 +56,7 @@ public class RMIClient implements IClient {
*/
public boolean connect(String username,int preferredInt) {
try {
+ System.setProperty("java.rmi.server.hostname", this.myIP);
Registry registry = LocateRegistry.getRegistry(host, port);
this.stub = (IGameServer) registry.lookup("RMIGameServer");
ClientCallbackImpl callback = new ClientCallbackImpl(controller);
@@ -64,17 +70,111 @@ public class RMIClient implements IClient {
}
- /**
- * Sends a {@link NetworkEvent} to the server.
- * @param event the event to send
- * @throws RemoteException if any RMI error occurs
- */
- public void doEvent(NetworkEvent event) {
- try {
- stub.doEvent(event);
- }catch (Exception e) {
- }
+ /**
+ * Requests to draw a tribe card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException {
+ stub.drawUpperTribeCard(playerUsername,pos);
}
+
+ /**
+ * Requests to draw a tribe card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException {
+ stub.drawLowerTribeCard(playerUsername,pos);
+ }
+
+
+ /**
+ * Requests to draw a building card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException {
+ stub.drawUpperBuildingCard(playerUsername,pos);
+ }
+
+
+ /**
+ * Requests to draw a building card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException {
+ stub.drawLowerBuildingCard(playerUsername,pos);
+ }
+
+
+ /**
+ * Requests to skip drawing from the upper list.
+ * This action is available only when the upper list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipUpper(String playerUsername) throws RemoteException {
+ stub.skipUpper(playerUsername);
+ }
+
+
+ /**
+ * Requests to skip drawing from the lower list.
+ * This action is available only when the lower list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipLower(String playerUsername) throws RemoteException {
+ stub.skipLower(playerUsername);
+ }
+
+
+ /**
+ * Used to draw a tribe card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException {
+ stub.pickOptionalTribeCard(playerUsername,pos);
+ }
+
+
+ /**
+ * Used to draw a building card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException {
+ stub.pickOptionalBuildingCard(playerUsername,pos);
+ }
+
+
+ /**
+ * Used to skip the action of drawing a card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void noOptionalCard(String playerUsername) throws RemoteException {
+ stub.noOptionalCard(playerUsername);
+ }
+
+
+ /**
+ * Used to perform the slot choice action for the specified player at the specified position.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the selected slot
+ */
+ public void slotChoice(String playerUsername,int pos) throws RemoteException {
+ stub.slotChoice(playerUsername,pos);
+ }
+
+
}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java
index 24fcdce..225bdff 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Common/IGameServer.java
@@ -30,5 +30,27 @@ public interface IGameServer extends Remote {
* @throws RemoteException if an RMI communication error occurs.
*/
boolean doEvent(NetworkEvent event) throws RemoteException;
+ void drawUpperTribeCard(String playerUsername, int pos) throws RemoteException;
+
+ void drawLowerTribeCard(String playerUsername,int pos) throws RemoteException;
+
+ void drawUpperBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+
+ void drawLowerBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+ void skipUpper(String playerUsername) throws RemoteException;
+
+ void skipLower(String playerUsername) throws RemoteException;
+
+
+ void pickOptionalTribeCard(String playerUsername,int pos) throws RemoteException;
+
+ void pickOptionalBuildingCard(String playerUsername,int pos) throws RemoteException;
+
+
+ void noOptionalCard(String playerUsername) throws RemoteException;
+
+ void slotChoice(String playerUsername,int pos) throws RemoteException;
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java
index 6fadf03..fdcc868 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java
@@ -4,14 +4,18 @@ import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.LimitedList;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
+import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
+import java.net.InetAddress;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
@@ -22,7 +26,7 @@ import java.rmi.*;
* Server RMI. Exposes a method to join the game and one to execute an event.
*/
public class RMIServer extends UnicastRemoteObject implements IGameServer {
-
+ private String host;
/** Server game's controller */
private GameController controller;
@@ -56,11 +60,12 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param playerList The player's usernames list
* @throws RemoteException if an RMI error occurs
*/
- public RMIServer(GameController controller, int nPort, BlockingQueue actionQueue,LimitedList playerList) throws RemoteException {
+ public RMIServer(GameController controller, int nPort, BlockingQueue actionQueue,LimitedList playerList,String host) throws RemoteException {
this.controller = controller;
this.nPort = nPort;
this.actionQueue = actionQueue;
this.playerList = playerList;
+ this.host = host;
}
@@ -76,7 +81,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param callback The client's callback interface
* @return true if the player successfully joined the game, false otherwise
*/
- @Override
public boolean joinGame(String username, int preferredInt, IClientCallback callback) {
if (preferredInt<2 || preferredInt>5) {
return false;
@@ -90,6 +94,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
if (controller.addPlayer(username)) {
clients.put(username, callback);
playerList.add(username);
+ System.out.println("Accepted player: " + username);
return true;
}
return false;
@@ -103,11 +108,114 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param action The desired actio
* @return true if the action was successfully added, false otherwise
*/
- @Override
public boolean doEvent(NetworkEvent action) {
return actionQueue.offer(action);
}
+ /**
+ * Requests to draw a tribe card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperTribeCard(String playerUsername, int pos) {
+ actionQueue.offer(new DrawUpperTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to draw a tribe card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerTribeCard(String playerUsername,int pos) {
+ actionQueue.offer(new DrawLowerTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to draw a building card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperBuildingCard(String playerUsername,int pos) {
+ actionQueue.offer(new DrawUpperBuildingCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to draw a building card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerBuildingCard(String playerUsername,int pos) {
+ actionQueue.offer(new DrawLowerBuildingCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to skip drawing from the upper list.
+ * This action is available only when the upper list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipUpper(String playerUsername) {
+ actionQueue.offer(new SkipUpper(playerUsername));
+ }
+
+
+ /**
+ * Requests to skip drawing from the lower list.
+ * This action is available only when the lower list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipLower(String playerUsername) {
+ actionQueue.offer(new SkipLower(playerUsername));
+ }
+
+
+ /**
+ * Used to draw a tribe card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalTribeCard(String playerUsername,int pos) {
+ actionQueue.offer(new PickOptionalTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Used to draw a building card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalBuildingCard(String playerUsername,int pos) {
+ actionQueue.offer(new PickOptionalBuildingCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Used to skip the action of drawing a card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void noOptionalCard(String playerUsername) {
+ actionQueue.offer(new NoOptionalCard(playerUsername));
+ }
+
+
+ /**
+ * Used to perform the slot choice action for the specified player at the specified position.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the selected slot
+ */
+ public void slotChoice(String playerUsername,int pos) {
+ actionQueue.offer(new SlotChoice(playerUsername,pos));
+ }
// RMI's internal methods
@@ -116,8 +224,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param action The desired action
*/
public void notifyAll(NetworkEvent action) throws RemoteException {
- for (IClientCallback cb : clients.values()) {
- cb.onAction(action);
+ for (Map.Entry entry : clients.entrySet()) {
+ if(!action.getIsError() ||(action.getIsError()&& action.getUsername().equals(entry.getKey())))
+ entry.getValue().onAction(action);
}
}
@@ -141,6 +250,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
*/
public boolean start() {
try {
+ System.setProperty("java.rmi.server.hostname", host); // o il tuo IP/hostname
registry = LocateRegistry.createRegistry(nPort);
registry.rebind("RMIGameServer", this);
System.out.println("RMI Server started on port: "+nPort);
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java
index 3408e99..e9ef147 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java
@@ -4,7 +4,7 @@ import it.polimi.ingsw.gc14.Controller.ClientController;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
-import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
+import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import java.io.*;
import java.net.*;
@@ -87,10 +87,17 @@ public class TCPClient implements IClient {
private void receiveMessage() {
while (true) {
try {
- Object read = socketReceive.readObject();
+ Object read;
+ try {
+ read = socketReceive.readObject();
+ } catch (IOException e) {
+ e.printStackTrace();
+ break;
+ }
+
if (read instanceof NetworkEvent event) { //TODO: avoid instanceof
if (event.getIsError()) {
- System.out.println(event);
+ controller.view.showError(event.toString());
} else {
event.apply(controller.localController);
controller.view.render();
@@ -99,20 +106,124 @@ public class TCPClient implements IClient {
controller.setModel(model);
controller.view.render();
}
- } catch (IOException e) {
- e.printStackTrace();
} catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
+ e.printStackTrace();
+ break;
}
}
}
+ /**
+ * Requests to draw a tribe card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperTribeCard(String playerUsername, int pos) {
+ doEvent(new DrawUpperTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to draw a tribe card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerTribeCard(String playerUsername,int pos) {
+ doEvent(new DrawLowerTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to draw a building card from the upper list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawUpperBuildingCard(String playerUsername,int pos) {
+ doEvent(new DrawUpperBuildingCard(playerUsername,pos));
+
+ }
+
+
+ /**
+ * Requests to draw a building card from the lower list.
+ * Creates a NetworkEvent and sends it through the network client.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void drawLowerBuildingCard(String playerUsername,int pos) {
+ doEvent(new DrawLowerBuildingCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Requests to skip drawing from the upper list.
+ * This action is available only when the upper list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipUpper(String playerUsername) {
+ doEvent(new SkipUpper(playerUsername));
+ }
+
+
+ /**
+ * Requests to skip drawing from the lower list.
+ * This action is available only when the lower list is empty or the player cannot draw any card.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void skipLower(String playerUsername) {
+ doEvent(new SkipLower(playerUsername));
+ }
+
+
+ /**
+ * Used to draw a tribe card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalTribeCard(String playerUsername,int pos) {
+ doEvent(new PickOptionalTribeCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Used to draw a building card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the card to draw
+ */
+ public void pickOptionalBuildingCard(String playerUsername,int pos) {
+ doEvent(new PickOptionalBuildingCard(playerUsername,pos));
+ }
+
+
+ /**
+ * Used to skip the action of drawing a card from the upper list.
+ * Available only if the player owns the building 12.
+ * @param playerUsername the name of the player performing the action
+ */
+ public void noOptionalCard(String playerUsername) {
+ doEvent(new NoOptionalCard(playerUsername));
+ }
+
+
+ /**
+ * Used to perform the slot choice action for the specified player at the specified position.
+ * @param playerUsername the name of the player performing the action
+ * @param pos the index of the selected slot
+ */
+ public void slotChoice(String playerUsername,int pos) {
+ doEvent(new SlotChoice(playerUsername,pos));
+ }
/**
* Sends a {@link NetworkEvent} to the server.
* @param event The NetworkEvent to send.
*/
- public void doEvent(NetworkEvent event) {
+ private void doEvent(NetworkEvent event) {
try {
socketSend.writeObject(event);
} catch (IOException e) {
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java
index 893a303..b64b1f2 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java
@@ -15,7 +15,13 @@ import java.util.concurrent.BlockingQueue;
* It is also responsible to send events and game model updates back to the client.
*/
public class ClientHandler implements Runnable {
-
+ /**
+ * The username of the connected client on this handler
+ */
+ private final String username;
+ public String getUsername() {
+ return username;
+ }
/** The TCP socket */
private Socket clientSocket;
@@ -44,7 +50,8 @@ public class ClientHandler implements Runnable {
* @param clientHandlers the shared list of all active client handlers.
* @param actionQueue the queue containing incoming events.
*/
- public ClientHandler(Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List clientHandlers, BlockingQueue actionQueue) {
+ public ClientHandler(String username, Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List clientHandlers, BlockingQueue actionQueue) {
+ this.username=username;
this.clientSocket = clientSocket;
this.in = in;
this.out = out;
diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java
index 563279a..f420dbb 100644
--- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java
+++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java
@@ -115,7 +115,7 @@ public class TCPServer {
clientSocket.getOutputStream().write((int) (1));
System.out.println("Accepted player: " + eventAddPlayer.getUsername());
- ClientHandler clientHandler = new ClientHandler(clientSocket, clientSend, clientReceive, clientHandlers, actionQueue);
+ ClientHandler clientHandler = new ClientHandler(eventAddPlayer.getUsername(),clientSocket, clientSend, clientReceive, clientHandlers, actionQueue);
clientHandlers.add(clientHandler);
ConnectedPlayers++;
@@ -145,7 +145,10 @@ public class TCPServer {
* @param event the network event to send to all connected TCP clients.
*/
public void notifyAll(NetworkEvent event){
- clientHandlers.forEach((x) -> x.notifyEvent(event));
+ clientHandlers.forEach((x) -> {
+ if(!event.getIsError()||(event.getIsError()&& event.getUsername().equals(x.getUsername())))
+ x.notifyEvent(event);
+ });
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java
index 9c8a10e..0f43343 100644
--- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java
+++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java
@@ -7,10 +7,13 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
+import it.polimi.ingsw.gc14.View.TUI.TUI;
import java.rmi.RemoteException;
+import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
+import java.net.*;
/**
@@ -56,6 +59,8 @@ public class ServerLauncher {
*/
static LimitedList playerList;
+ TUI view;
+
/**
* Class constructor that initializes the attributes.
@@ -104,7 +109,14 @@ public class ServerLauncher {
playerList = new LimitedList<>(5, ()->{});
BlockingQueue actionQueue = new LinkedBlockingQueue<>();
GameController gameController = new GameController();
- RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList);
+ String IP;
+ try {
+ IP=chooseNetworkInterface(new Scanner(System.in));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList,IP);
TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue, playerList);
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
@@ -137,11 +149,14 @@ public class ServerLauncher {
System.out.println("\n\nNotifying model");
serverRMI.notifyAll(gameController.getModel());
serverTCP.notifyAll(gameController.getModel());
+ this.view = new TUI(gameController.getModel());
+ this.view.fullRender();
// Game execution
while (true) {
try {
this.doFirstEvent();
+ this.view.fullRender();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
@@ -150,4 +165,36 @@ public class ServerLauncher {
}
}
}
+ public static String chooseNetworkInterface(Scanner scanner) throws Exception {
+ List ips = new ArrayList<>();
+
+ // Lista tutte le interfacce attive con IP reale
+ Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
+ while (interfaces.hasMoreElements()) {
+ NetworkInterface ni = interfaces.nextElement();
+
+ // Salta loopback, interfacce spente o virtuali
+ if (!ni.isUp() || ni.isLoopback() || ni.isVirtual()) continue;
+
+ Enumeration addresses = ni.getInetAddresses();
+ while (addresses.hasMoreElements()) {
+ InetAddress addr = addresses.nextElement();
+ // Solo IPv4
+ if (addr instanceof Inet4Address) {
+ System.out.println("[" + ips.size() + "] " + ni.getDisplayName() + " -> " + addr.getHostAddress());
+ ips.add(addr.getHostAddress());
+ }
+ }
+ }
+
+ if (ips.isEmpty()) throw new Exception("Nessuna interfaccia disponibile");
+ if (ips.size() == 1) {
+ System.out.println("Una sola interfaccia trovata, uso: " + ips.get(0));
+ return ips.get(0);
+ }
+
+ System.out.print("Scegli interfaccia: ");
+ int choice = Integer.parseInt(scanner.nextLine().trim());
+ return ips.get(choice);
+ }
}
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/GUI.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/GUI.java
new file mode 100644
index 0000000..9a49330
--- /dev/null
+++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/GUI.java
@@ -0,0 +1,55 @@
+package it.polimi.ingsw.gc14.View.GUI;
+
+import it.polimi.ingsw.gc14.Controller.ClientController;
+import it.polimi.ingsw.gc14.Model.Game;
+import it.polimi.ingsw.gc14.View.GUI.MainView;
+import it.polimi.ingsw.gc14.View.IView;
+import javafx.application.Platform;
+import javafx.stage.Stage;
+
+public class GUI implements IView { // stessa interfaccia che implementa TUI
+
+ private final Stage stage;
+ private final MainView mainView = new MainView();
+ private Game model;
+ private String username;
+
+ public GUI(Stage stage) {
+ this.stage = stage;
+ }
+
+ @Override
+ public void setModel(Game model) {
+ this.model = model;
+ mainView.setModel(model);
+ }
+
+ /**
+ * Chiamato da onGameInit e onAction — sempre da thread RMI/TCP.
+ * Platform.runLater garantisce che la UI venga aggiornata sul JavaFX thread.
+ */
+ @Override
+ public void render() {
+ Platform.runLater(() -> {
+ mainView.render();
+ stage.setScene(mainView.getScene());
+ });
+ }
+
+ @Override
+ public void showMessage(String message) {
+
+ }
+
+ @Override
+ public void showError(String message) {
+
+ }
+
+ public void setUsername(String username) {
+ this.username=username;
+ }
+
+ // Getter per il launcher
+ public Stage getStage() { return stage; }
+}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java
new file mode 100644
index 0000000..8e6cba6
--- /dev/null
+++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java
@@ -0,0 +1,44 @@
+package it.polimi.ingsw.gc14.View.GUI;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.*;
+
+public class LoginFXMLController {
+
+ @FXML private TextField campoNome;
+ @FXML private TextField campoNumPlayers;
+ @FXML private TextField campoIP;
+ @FXML private RadioButton btnRMI;
+ @FXML private RadioButton btnTCP;
+ @FXML private Button btnAccedi;
+ @FXML private Label labelErrore;
+
+ @FXML
+ public void initialize() {
+ // I RadioButton vanno collegati a un ToggleGroup a mano
+ // perché FXML non lo fa automaticamente
+ ToggleGroup group = new ToggleGroup();
+ btnRMI.setToggleGroup(group);
+ btnTCP.setToggleGroup(group);
+ }
+
+ // --- Getter esposti a LoginView ---
+
+ public Button getBtnAccedi() { return btnAccedi; }
+
+ public String getNome() { return campoNome.getText().trim(); }
+
+ public int getNumPlayers() {
+ try {
+ return Integer.parseInt(campoNumPlayers.getText().trim());
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+
+ public int getNetworkType() { return btnRMI.isSelected() ? 0 : 1; }
+
+ public String getIP() { return campoIP.getText().trim(); }
+
+ public void setErrore(String messaggio) { labelErrore.setText(messaggio); }
+}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginView.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginView.java
new file mode 100644
index 0000000..51eaf1b
--- /dev/null
+++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginView.java
@@ -0,0 +1,35 @@
+package it.polimi.ingsw.gc14.View.GUI;
+
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+
+import java.io.IOException;
+
+public class LoginView {
+
+ private final Scene scene;
+ private final LoginFXMLController fxmlController;
+
+ public LoginView() {
+ try {
+ FXMLLoader loader = new FXMLLoader(
+ getClass().getResource("/GUIScene/login.fxml")
+ );
+ scene = new Scene(loader.load(), 350, 380);
+ fxmlController = loader.getController();
+ } catch (IOException e) {
+ throw new RuntimeException("Impossibile caricare login.fxml", e);
+ }
+ }
+
+ // --- Delega tutto al controller FXML ---
+
+ public Scene getScene() { return scene; }
+ public Button getBtnAccedi() { return fxmlController.getBtnAccedi(); }
+ public String getNome() { return fxmlController.getNome(); }
+ public int getNumPlayers() { return fxmlController.getNumPlayers(); }
+ public int getNetworkType() { return fxmlController.getNetworkType(); }
+ public String getIP() { return fxmlController.getIP(); }
+ public void setErrore(String messaggio) { fxmlController.setErrore(messaggio); }
+}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java
new file mode 100644
index 0000000..496245b
--- /dev/null
+++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainFXMLController.java
@@ -0,0 +1,43 @@
+package it.polimi.ingsw.gc14.View.GUI;
+
+import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
+import it.polimi.ingsw.gc14.Model.Game;
+import javafx.fxml.FXML;
+import javafx.scene.image.*;
+import javafx.scene.layout.*;
+import javafx.scene.shape.*;
+
+import java.util.List;
+
+public class MainFXMLController {
+
+ @FXML private HBox board;
+ @FXML private HBox upperList;
+ @FXML private HBox lowerList;
+ @FXML private HBox myHand;
+ @FXML private VBox playersHand;
+
+ private Game model;
+
+ public void setModel(Game model) {
+ this.model = model;
+ }
+
+ public void render() {
+ Image placeholder = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-001.png"));
+
+ for (TribeCard card : model.getUpperListTribeCards()) {
+ ImageView view = new ImageView(placeholder);
+ view.setFitHeight(250);
+ view.setPreserveRatio(true);
+ upperList.getChildren().add(view);
+ }
+
+ for (TribeCard card : model.getLowerListTribeCards()) {
+ ImageView view = new ImageView(placeholder);
+ view.setFitHeight(250);
+ view.setPreserveRatio(true);
+ lowerList.getChildren().add(view);
+ }
+ }
+}
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainView.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainView.java
new file mode 100644
index 0000000..7df0470
--- /dev/null
+++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/MainView.java
@@ -0,0 +1,39 @@
+package it.polimi.ingsw.gc14.View.GUI;
+
+import it.polimi.ingsw.gc14.Model.Game;
+import javafx.fxml.FXMLLoader;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.Scene;
+import javafx.scene.control.Label;
+import javafx.scene.layout.VBox;
+
+import java.io.IOException;
+
+public class MainView {
+
+ private final Scene scene;
+ private final MainFXMLController fxmlController;
+ private Game model;
+
+ public MainView() {
+ try {
+ FXMLLoader loader = new FXMLLoader(
+ getClass().getResource("/GUIScene/main.fxml")
+ );
+ scene = new Scene(loader.load(), 1920, 1080);
+ fxmlController = loader.getController();
+ } catch (IOException e) {
+ throw new RuntimeException("Impossibile caricare login.fxml", e);
+ }
+ }
+
+ public Scene getScene() { return scene; }
+ public void setModel(Game model) {
+ this.model = model;
+ fxmlController.setModel(model);
+ }
+ public void render() {
+ fxmlController.render();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/IView.java b/src/main/java/it/polimi/ingsw/gc14/View/IView.java
index 2169583..5025588 100644
--- a/src/main/java/it/polimi/ingsw/gc14/View/IView.java
+++ b/src/main/java/it/polimi/ingsw/gc14/View/IView.java
@@ -4,7 +4,7 @@ import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
public interface IView {
- public void update(Game game);
+ public void setModel(Game game);
public void render();
public void showMessage(String message);
public void showError(String message);
diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java
index ecd489e..1253f5c 100644
--- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java
+++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java
@@ -77,7 +77,7 @@ public class TUI implements IView {
* @param model the new {@link Game} model; must not be {@code null}
*/
@Override
- public void update(Game model) {
+ public void setModel(Game model) {
this.model = model;
}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index e178647..3adc89b 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -18,4 +18,8 @@ module it.polimi.ingsw.gc14 {
exports it.polimi.ingsw.gc14.Network.RMI.Client to java.rmi;
exports it.polimi.ingsw.gc14.Network to java.rmi;
exports it.polimi.ingsw.gc14.Model to java.rmi, com.google.gson;
+
+ // GUI
+ opens it.polimi.ingsw.gc14.View.GUI to javafx.fxml;
+ exports it.polimi.ingsw.gc14.View.GUI;
}
\ No newline at end of file
diff --git a/src/main/resources/GUIImages/Backs/back-001.png b/src/main/resources/GUIImages/Backs/back-001.png
new file mode 100644
index 0000000..89dec13
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-001.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-030.png b/src/main/resources/GUIImages/Backs/back-030.png
new file mode 100644
index 0000000..a196534
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-030.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-058.png b/src/main/resources/GUIImages/Backs/back-058.png
new file mode 100644
index 0000000..a71865e
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-058.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-095.png b/src/main/resources/GUIImages/Backs/back-095.png
new file mode 100644
index 0000000..8381fbc
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-095.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-097.png b/src/main/resources/GUIImages/Backs/back-097.png
new file mode 100644
index 0000000..5905498
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-097.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-103.png b/src/main/resources/GUIImages/Backs/back-103.png
new file mode 100644
index 0000000..033193c
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-103.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-110.png b/src/main/resources/GUIImages/Backs/back-110.png
new file mode 100644
index 0000000..efc1db5
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-110.png differ
diff --git a/src/main/resources/GUIImages/Backs/back-118.png b/src/main/resources/GUIImages/Backs/back-118.png
new file mode 100644
index 0000000..21df212
Binary files /dev/null and b/src/main/resources/GUIImages/Backs/back-118.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-001.png b/src/main/resources/GUIImages/Fronts/card-001.png
new file mode 100644
index 0000000..6b56265
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-001.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-002.png b/src/main/resources/GUIImages/Fronts/card-002.png
new file mode 100644
index 0000000..d4146fb
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-002.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-003.png b/src/main/resources/GUIImages/Fronts/card-003.png
new file mode 100644
index 0000000..4e060fc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-003.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-004.png b/src/main/resources/GUIImages/Fronts/card-004.png
new file mode 100644
index 0000000..c6bf04f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-004.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-005.png b/src/main/resources/GUIImages/Fronts/card-005.png
new file mode 100644
index 0000000..70ee4dd
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-005.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-006.png b/src/main/resources/GUIImages/Fronts/card-006.png
new file mode 100644
index 0000000..7401038
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-006.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-007.png b/src/main/resources/GUIImages/Fronts/card-007.png
new file mode 100644
index 0000000..b487ecf
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-007.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-008.png b/src/main/resources/GUIImages/Fronts/card-008.png
new file mode 100644
index 0000000..a6dd5de
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-008.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-009.png b/src/main/resources/GUIImages/Fronts/card-009.png
new file mode 100644
index 0000000..be7920f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-009.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-010.png b/src/main/resources/GUIImages/Fronts/card-010.png
new file mode 100644
index 0000000..c74f545
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-010.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-011.png b/src/main/resources/GUIImages/Fronts/card-011.png
new file mode 100644
index 0000000..8f5432b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-011.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-012.png b/src/main/resources/GUIImages/Fronts/card-012.png
new file mode 100644
index 0000000..2ce6a2e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-012.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-013.png b/src/main/resources/GUIImages/Fronts/card-013.png
new file mode 100644
index 0000000..06cf152
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-013.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-014.png b/src/main/resources/GUIImages/Fronts/card-014.png
new file mode 100644
index 0000000..d144a51
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-014.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-015.png b/src/main/resources/GUIImages/Fronts/card-015.png
new file mode 100644
index 0000000..6bc6920
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-015.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-016.png b/src/main/resources/GUIImages/Fronts/card-016.png
new file mode 100644
index 0000000..d144a51
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-016.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-017.png b/src/main/resources/GUIImages/Fronts/card-017.png
new file mode 100644
index 0000000..43ff517
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-017.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-018.png b/src/main/resources/GUIImages/Fronts/card-018.png
new file mode 100644
index 0000000..877e4c3
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-018.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-019.png b/src/main/resources/GUIImages/Fronts/card-019.png
new file mode 100644
index 0000000..3b6ac1b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-019.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-020.png b/src/main/resources/GUIImages/Fronts/card-020.png
new file mode 100644
index 0000000..5f3e486
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-020.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-021.png b/src/main/resources/GUIImages/Fronts/card-021.png
new file mode 100644
index 0000000..63945c2
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-021.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-022.png b/src/main/resources/GUIImages/Fronts/card-022.png
new file mode 100644
index 0000000..8ecadf9
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-022.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-023.png b/src/main/resources/GUIImages/Fronts/card-023.png
new file mode 100644
index 0000000..5b761cc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-023.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-024.png b/src/main/resources/GUIImages/Fronts/card-024.png
new file mode 100644
index 0000000..73d7cc5
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-024.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-025.png b/src/main/resources/GUIImages/Fronts/card-025.png
new file mode 100644
index 0000000..81d1ce1
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-025.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-026.png b/src/main/resources/GUIImages/Fronts/card-026.png
new file mode 100644
index 0000000..05af101
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-026.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-027.png b/src/main/resources/GUIImages/Fronts/card-027.png
new file mode 100644
index 0000000..54786a8
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-027.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-028.png b/src/main/resources/GUIImages/Fronts/card-028.png
new file mode 100644
index 0000000..79c8ec4
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-028.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-029.png b/src/main/resources/GUIImages/Fronts/card-029.png
new file mode 100644
index 0000000..c9f0783
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-029.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-030.png b/src/main/resources/GUIImages/Fronts/card-030.png
new file mode 100644
index 0000000..8ec9df7
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-030.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-031.png b/src/main/resources/GUIImages/Fronts/card-031.png
new file mode 100644
index 0000000..4e060fc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-031.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-032.png b/src/main/resources/GUIImages/Fronts/card-032.png
new file mode 100644
index 0000000..d2e489e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-032.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-033.png b/src/main/resources/GUIImages/Fronts/card-033.png
new file mode 100644
index 0000000..6b56265
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-033.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-034.png b/src/main/resources/GUIImages/Fronts/card-034.png
new file mode 100644
index 0000000..a45d075
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-034.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-035.png b/src/main/resources/GUIImages/Fronts/card-035.png
new file mode 100644
index 0000000..55fb912
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-035.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-036.png b/src/main/resources/GUIImages/Fronts/card-036.png
new file mode 100644
index 0000000..d74bb4a
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-036.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-037.png b/src/main/resources/GUIImages/Fronts/card-037.png
new file mode 100644
index 0000000..a556bcb
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-037.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-038.png b/src/main/resources/GUIImages/Fronts/card-038.png
new file mode 100644
index 0000000..4efd17d
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-038.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-039.png b/src/main/resources/GUIImages/Fronts/card-039.png
new file mode 100644
index 0000000..cfaa742
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-039.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-040.png b/src/main/resources/GUIImages/Fronts/card-040.png
new file mode 100644
index 0000000..c74f545
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-040.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-041.png b/src/main/resources/GUIImages/Fronts/card-041.png
new file mode 100644
index 0000000..a5f73b4
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-041.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-042.png b/src/main/resources/GUIImages/Fronts/card-042.png
new file mode 100644
index 0000000..97f9071
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-042.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-043.png b/src/main/resources/GUIImages/Fronts/card-043.png
new file mode 100644
index 0000000..7cf882e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-043.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-044.png b/src/main/resources/GUIImages/Fronts/card-044.png
new file mode 100644
index 0000000..07376e7
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-044.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-045.png b/src/main/resources/GUIImages/Fronts/card-045.png
new file mode 100644
index 0000000..6bc6920
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-045.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-046.png b/src/main/resources/GUIImages/Fronts/card-046.png
new file mode 100644
index 0000000..d144a51
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-046.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-047.png b/src/main/resources/GUIImages/Fronts/card-047.png
new file mode 100644
index 0000000..6bc6920
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-047.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-048.png b/src/main/resources/GUIImages/Fronts/card-048.png
new file mode 100644
index 0000000..6521a0f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-048.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-049.png b/src/main/resources/GUIImages/Fronts/card-049.png
new file mode 100644
index 0000000..a112f1d
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-049.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-050.png b/src/main/resources/GUIImages/Fronts/card-050.png
new file mode 100644
index 0000000..ff3fb1e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-050.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-051.png b/src/main/resources/GUIImages/Fronts/card-051.png
new file mode 100644
index 0000000..33eaac8
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-051.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-052.png b/src/main/resources/GUIImages/Fronts/card-052.png
new file mode 100644
index 0000000..9c12672
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-052.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-053.png b/src/main/resources/GUIImages/Fronts/card-053.png
new file mode 100644
index 0000000..3b6ac1b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-053.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-054.png b/src/main/resources/GUIImages/Fronts/card-054.png
new file mode 100644
index 0000000..2417082
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-054.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-055.png b/src/main/resources/GUIImages/Fronts/card-055.png
new file mode 100644
index 0000000..54786a8
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-055.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-056.png b/src/main/resources/GUIImages/Fronts/card-056.png
new file mode 100644
index 0000000..de23fad
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-056.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-057.png b/src/main/resources/GUIImages/Fronts/card-057.png
new file mode 100644
index 0000000..8aa0fe3
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-057.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-058.png b/src/main/resources/GUIImages/Fronts/card-058.png
new file mode 100644
index 0000000..d901205
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-058.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-059.png b/src/main/resources/GUIImages/Fronts/card-059.png
new file mode 100644
index 0000000..4e060fc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-059.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-060.png b/src/main/resources/GUIImages/Fronts/card-060.png
new file mode 100644
index 0000000..8ec9df7
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-060.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-061.png b/src/main/resources/GUIImages/Fronts/card-061.png
new file mode 100644
index 0000000..6b56265
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-061.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-062.png b/src/main/resources/GUIImages/Fronts/card-062.png
new file mode 100644
index 0000000..231d77e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-062.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-063.png b/src/main/resources/GUIImages/Fronts/card-063.png
new file mode 100644
index 0000000..cfaa742
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-063.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-064.png b/src/main/resources/GUIImages/Fronts/card-064.png
new file mode 100644
index 0000000..ba715cd
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-064.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-065.png b/src/main/resources/GUIImages/Fronts/card-065.png
new file mode 100644
index 0000000..a94ea31
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-065.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-066.png b/src/main/resources/GUIImages/Fronts/card-066.png
new file mode 100644
index 0000000..e1f5924
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-066.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-067.png b/src/main/resources/GUIImages/Fronts/card-067.png
new file mode 100644
index 0000000..ef3f47a
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-067.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-068.png b/src/main/resources/GUIImages/Fronts/card-068.png
new file mode 100644
index 0000000..c74f545
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-068.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-069.png b/src/main/resources/GUIImages/Fronts/card-069.png
new file mode 100644
index 0000000..1d77e43
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-069.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-070.png b/src/main/resources/GUIImages/Fronts/card-070.png
new file mode 100644
index 0000000..d144a51
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-070.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-071.png b/src/main/resources/GUIImages/Fronts/card-071.png
new file mode 100644
index 0000000..6bc6920
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-071.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-072.png b/src/main/resources/GUIImages/Fronts/card-072.png
new file mode 100644
index 0000000..d144a51
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-072.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-073.png b/src/main/resources/GUIImages/Fronts/card-073.png
new file mode 100644
index 0000000..f0446a3
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-073.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-074.png b/src/main/resources/GUIImages/Fronts/card-074.png
new file mode 100644
index 0000000..a9e3503
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-074.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-075.png b/src/main/resources/GUIImages/Fronts/card-075.png
new file mode 100644
index 0000000..70334c2
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-075.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-076.png b/src/main/resources/GUIImages/Fronts/card-076.png
new file mode 100644
index 0000000..6521a0f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-076.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-077.png b/src/main/resources/GUIImages/Fronts/card-077.png
new file mode 100644
index 0000000..34f1a6d
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-077.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-078.png b/src/main/resources/GUIImages/Fronts/card-078.png
new file mode 100644
index 0000000..8eed959
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-078.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-079.png b/src/main/resources/GUIImages/Fronts/card-079.png
new file mode 100644
index 0000000..ff46927
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-079.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-080.png b/src/main/resources/GUIImages/Fronts/card-080.png
new file mode 100644
index 0000000..7dfaa33
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-080.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-081.png b/src/main/resources/GUIImages/Fronts/card-081.png
new file mode 100644
index 0000000..a2e09a2
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-081.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-082.png b/src/main/resources/GUIImages/Fronts/card-082.png
new file mode 100644
index 0000000..2417082
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-082.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-083.png b/src/main/resources/GUIImages/Fronts/card-083.png
new file mode 100644
index 0000000..a2e09a2
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-083.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-084.png b/src/main/resources/GUIImages/Fronts/card-084.png
new file mode 100644
index 0000000..d22b90e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-084.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-085.png b/src/main/resources/GUIImages/Fronts/card-085.png
new file mode 100644
index 0000000..b4ce5ac
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-085.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-086.png b/src/main/resources/GUIImages/Fronts/card-086.png
new file mode 100644
index 0000000..6557c97
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-086.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-087.png b/src/main/resources/GUIImages/Fronts/card-087.png
new file mode 100644
index 0000000..2ac46e1
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-087.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-088.png b/src/main/resources/GUIImages/Fronts/card-088.png
new file mode 100644
index 0000000..c0e6851
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-088.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-089.png b/src/main/resources/GUIImages/Fronts/card-089.png
new file mode 100644
index 0000000..7c6071a
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-089.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-090.png b/src/main/resources/GUIImages/Fronts/card-090.png
new file mode 100644
index 0000000..0685a4b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-090.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-091.png b/src/main/resources/GUIImages/Fronts/card-091.png
new file mode 100644
index 0000000..ba1af1c
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-091.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-092.png b/src/main/resources/GUIImages/Fronts/card-092.png
new file mode 100644
index 0000000..b81cf07
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-092.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-093.png b/src/main/resources/GUIImages/Fronts/card-093.png
new file mode 100644
index 0000000..3e628fe
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-093.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-094.png b/src/main/resources/GUIImages/Fronts/card-094.png
new file mode 100644
index 0000000..21fa6d7
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-094.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-095.png b/src/main/resources/GUIImages/Fronts/card-095.png
new file mode 100644
index 0000000..ebca752
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-095.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-096.png b/src/main/resources/GUIImages/Fronts/card-096.png
new file mode 100644
index 0000000..2743bad
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-096.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-097.png b/src/main/resources/GUIImages/Fronts/card-097.png
new file mode 100644
index 0000000..42ec113
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-097.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-098.png b/src/main/resources/GUIImages/Fronts/card-098.png
new file mode 100644
index 0000000..de64247
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-098.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-099.png b/src/main/resources/GUIImages/Fronts/card-099.png
new file mode 100644
index 0000000..067805c
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-099.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-100.png b/src/main/resources/GUIImages/Fronts/card-100.png
new file mode 100644
index 0000000..f9f1bf9
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-100.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-101.png b/src/main/resources/GUIImages/Fronts/card-101.png
new file mode 100644
index 0000000..e31fa39
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-101.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-102.png b/src/main/resources/GUIImages/Fronts/card-102.png
new file mode 100644
index 0000000..b9ebe66
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-102.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-103.png b/src/main/resources/GUIImages/Fronts/card-103.png
new file mode 100644
index 0000000..ade84ac
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-103.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-104.png b/src/main/resources/GUIImages/Fronts/card-104.png
new file mode 100644
index 0000000..c39591f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-104.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-105.png b/src/main/resources/GUIImages/Fronts/card-105.png
new file mode 100644
index 0000000..9e6ec4c
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-105.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-106.png b/src/main/resources/GUIImages/Fronts/card-106.png
new file mode 100644
index 0000000..a0034f2
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-106.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-107.png b/src/main/resources/GUIImages/Fronts/card-107.png
new file mode 100644
index 0000000..f9131fc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-107.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-108.png b/src/main/resources/GUIImages/Fronts/card-108.png
new file mode 100644
index 0000000..bf6b3dc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-108.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-109.png b/src/main/resources/GUIImages/Fronts/card-109.png
new file mode 100644
index 0000000..ea4b997
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-109.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-110.png b/src/main/resources/GUIImages/Fronts/card-110.png
new file mode 100644
index 0000000..457610b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-110.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-111.png b/src/main/resources/GUIImages/Fronts/card-111.png
new file mode 100644
index 0000000..f5af84e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-111.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-112.png b/src/main/resources/GUIImages/Fronts/card-112.png
new file mode 100644
index 0000000..f21d96c
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-112.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-113.png b/src/main/resources/GUIImages/Fronts/card-113.png
new file mode 100644
index 0000000..b1d241c
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-113.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-114.png b/src/main/resources/GUIImages/Fronts/card-114.png
new file mode 100644
index 0000000..b1668c5
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-114.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-115.png b/src/main/resources/GUIImages/Fronts/card-115.png
new file mode 100644
index 0000000..1f063c1
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-115.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-116.png b/src/main/resources/GUIImages/Fronts/card-116.png
new file mode 100644
index 0000000..276758e
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-116.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-117.png b/src/main/resources/GUIImages/Fronts/card-117.png
new file mode 100644
index 0000000..ae1e1f4
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-117.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-118.png b/src/main/resources/GUIImages/Fronts/card-118.png
new file mode 100644
index 0000000..2b09acc
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-118.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-A.png b/src/main/resources/GUIImages/Fronts/card-A.png
new file mode 100644
index 0000000..805ba49
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-A.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-B.png b/src/main/resources/GUIImages/Fronts/card-B.png
new file mode 100644
index 0000000..43ce33b
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-B.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-C.png b/src/main/resources/GUIImages/Fronts/card-C.png
new file mode 100644
index 0000000..a1ff0f8
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-C.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-D.png b/src/main/resources/GUIImages/Fronts/card-D.png
new file mode 100644
index 0000000..c2c06cd
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-D.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-E.png b/src/main/resources/GUIImages/Fronts/card-E.png
new file mode 100644
index 0000000..d11087f
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-E.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-F.png b/src/main/resources/GUIImages/Fronts/card-F.png
new file mode 100644
index 0000000..d387692
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-F.png differ
diff --git a/src/main/resources/GUIImages/Fronts/card-G.png b/src/main/resources/GUIImages/Fronts/card-G.png
new file mode 100644
index 0000000..88d1515
Binary files /dev/null and b/src/main/resources/GUIImages/Fronts/card-G.png differ
diff --git a/src/main/resources/GUIScene/login.fxml b/src/main/resources/GUIScene/login.fxml
new file mode 100644
index 0000000..9e55c8f
--- /dev/null
+++ b/src/main/resources/GUIScene/login.fxml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/GUIScene/main.fxml b/src/main/resources/GUIScene/main.fxml
new file mode 100644
index 0000000..3e7f1cf
--- /dev/null
+++ b/src/main/resources/GUIScene/main.fxml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java
index aa89a2a..3e95055 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java
@@ -18,10 +18,7 @@ class GameControllerTest {
private Game createStartedGame() {
Game game = new Game(3);
GameController controller = new GameController(game);
- assertEquals( controller.getModel(),game);
- controller = new GameController();
- controller.setModel(game);
- assertEquals( controller.getModel(),game);
+
assertTrue(controller.addPlayer("Giorgio"));
assertTrue(controller.addPlayer("Marco"));
assertTrue(controller.addPlayer("Luca"));
@@ -32,14 +29,14 @@ class GameControllerTest {
private Queue completeSlotChoice(Game game, GameController controller) {
Queue order = new LinkedList<>();
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < game.getNPlayers(); i++) {
Player current = game.getCurrentState().getCurrentPlayer();
order.add(current);
assertTrue(controller.slotChoice(current.getUserName(), i));
}
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
return order;
}
@@ -92,34 +89,74 @@ class GameControllerTest {
private void resolveActionsUntilOptionalCardEffect(Game game, GameController controller) {
int guard = 0;
- while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 20) {
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && guard < 100) {
guard++;
-
- Player current = game.getCurrentState().getCurrentPlayer();
- assertNotNull(current);
-
- if (game.getCurrentState().getNLower() > 0) {
- int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards());
-
- if (index == -1) {
- fail("No non-event lower tribe card available.");
- }
-
- assertTrue(controller.drawLowerTribeCard(current.getUserName(), index));
- } else if (game.getCurrentState().getNUpper() > 0) {
- int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
-
- if (index == -1) {
- fail("No non-event upper tribe card available.");
- }
-
- assertTrue(controller.drawUpperTribeCard(current.getUserName(), index));
- } else {
- fail("Current player has no remaining upper or lower draws.");
- }
+ resolveOneMandatoryAction(game, controller);
}
- assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
+ }
+
+ private void resolveOneMandatoryAction(Game game, GameController controller) {
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ String username = current.getUserName();
+
+ if (game.getCurrentState().getNLower() > 0) {
+ int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards());
+
+ if (index != -1) {
+ assertTrue(controller.drawLowerTribeCard(username, index));
+ return;
+ }
+
+ if (!game.getLowerListBuilding().isEmpty()) {
+ current.addFood(100);
+ assertTrue(controller.drawLowerBuildingCard(username, 0));
+ return;
+ }
+
+ assertTrue(controller.SkipLowerDrawing(username));
+ return;
+ }
+
+ if (game.getCurrentState().getNUpper() > 0) {
+ int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
+
+ if (index != -1) {
+ assertTrue(controller.drawUpperTribeCard(username, index));
+ return;
+ }
+
+ if (!game.getUpperListBuilding().isEmpty()) {
+ current.addFood(100);
+ assertTrue(controller.drawUpperBuildingCard(username, 0));
+ return;
+ }
+
+ assertTrue(controller.SkipUpperDrawing(username));
+ return;
+ }
+
+ fail("Current player has no remaining draw actions.");
+ }
+
+ private Queue completeSlotChoiceWithSlots(Game game, GameController controller, int... slotIndexes) {
+ assertEquals(game.getNPlayers(), slotIndexes.length);
+
+ Queue order = new LinkedList<>();
+
+ for (int i = 0; i < game.getNPlayers(); i++) {
+ Player current = game.getCurrentState().getCurrentPlayer();
+ order.add(current);
+
+ assertTrue(controller.slotChoice(current.getUserName(), slotIndexes[i]));
+ }
+
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
+
+ return order;
}
@@ -150,8 +187,11 @@ class GameControllerTest {
assertFalse(controller.drawLowerTribeCard("ghost", 0));
assertFalse(controller.drawUpperBuildingCard("ghost", 0));
assertFalse(controller.drawLowerBuildingCard("ghost", 0));
+ assertFalse(controller.SkipUpperDrawing("ghost"));
+ assertFalse(controller.SkipLowerDrawing("ghost"));
assertFalse(controller.pickOptionalTribeCard("ghost", 0));
assertFalse(controller.pickOptionalBuildingCard("ghost", 0));
+ assertFalse(controller.noOptionalCard("ghost"));
}
@Test
@@ -166,7 +206,7 @@ class GameControllerTest {
Queue order = completeSlotChoice(game, controller);
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
assertEquals(order.poll(), game.getCurrentState().getCurrentPlayer());
}
@@ -243,7 +283,13 @@ class GameControllerTest {
Player current = game.getCurrentState().getCurrentPlayer();
- assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0));
+ while (current.getFoodValue() > 0) {
+ assertTrue(current.removeFood(1));
+ }
+
+ if (current.builders.isEmpty()) {
+ assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0));
+ }
current.addFood(100);
int foodBefore = current.getFoodValue();
@@ -251,7 +297,7 @@ class GameControllerTest {
assertTrue(controller.drawUpperBuildingCard(current.getUserName(), 0));
- assertTrue(current.getFoodValue() < foodBefore);
+ assertTrue(current.getFoodValue() <= foodBefore);
assertEquals(buildingsBefore + 1, current.buildingCards.size());
}
@@ -267,14 +313,14 @@ class GameControllerTest {
Queue players = new LinkedList<>();
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < game.getNPlayers(); i++) {
Player current = game.getCurrentState().getCurrentPlayer();
players.add(current);
assertTrue(controller.slotChoice(current.getUserName(), i));
}
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
Player tempPlayer = players.poll();
assertNotNull(tempPlayer);
@@ -349,7 +395,7 @@ class GameControllerTest {
completeSlotChoice(game, controller);
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
@@ -408,7 +454,7 @@ class GameControllerTest {
assertTrue(controller.pickOptionalBuildingCard(optionalPlayer.getUserName(), 0));
- assertTrue(optionalPlayer.getFoodValue() < foodBefore);
+ assertTrue(optionalPlayer.getFoodValue() <= foodBefore);
assertEquals(buildingsBefore + 1, optionalPlayer.buildingCards.size());
}
@@ -456,4 +502,133 @@ class GameControllerTest {
assertFalse(controller.slotChoice(second.getUserName(), 0));
}
+
+ @Test
+ void noOptionalCardShouldWorkDuringOptionalCardEffectState() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ giveOptionalEffectToAllPlayers(game);
+
+ completeSlotChoice(game, controller);
+ resolveActionsUntilOptionalCardEffect(game, controller);
+
+ Player optionalPlayer = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(optionalPlayer);
+
+ assertTrue(optionalPlayer.buildingCards.stream()
+ .anyMatch(building -> building.getEffectId() == 12));
+
+ assertTrue(controller.noOptionalCard(optionalPlayer.getUserName()));
+ }
+
+ @Test
+ void constructorsGetModelAndSetModelShouldWork() {
+ Game game = new Game(3);
+
+ GameController controller = new GameController(game);
+ assertEquals(game, controller.getModel());
+
+ GameController emptyController = new GameController();
+ emptyController.setModel(game);
+ assertEquals(game, emptyController.getModel());
+ }
+
+ @Test
+ void slotChoiceShouldReturnFalseForInvalidIndexes() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+
+ assertFalse(controller.slotChoice(current.getUserName(), -1));
+ assertFalse(controller.slotChoice(current.getUserName(), 999));
+ }
+
+ @Test
+ void optionalCardMethodsShouldReturnFalseForInvalidIndexesDuringOptionalCardEffectState() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ giveOptionalEffectToAllPlayers(game);
+
+ completeSlotChoice(game, controller);
+ resolveActionsUntilOptionalCardEffect(game, controller);
+
+ Player optionalPlayer = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(optionalPlayer);
+
+ String username = optionalPlayer.getUserName();
+
+ assertFalse(controller.pickOptionalTribeCard(username, -1));
+ assertFalse(controller.pickOptionalTribeCard(username, 999));
+
+ assertFalse(controller.pickOptionalBuildingCard(username, -1));
+ assertFalse(controller.pickOptionalBuildingCard(username, 999));
+ }
+
+ @Test
+ void optionalCardMethodsShouldReturnFalseForWrongPlayer() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ giveOptionalEffectToAllPlayers(game);
+
+ completeSlotChoice(game, controller);
+ resolveActionsUntilOptionalCardEffect(game, controller);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ Player wrongPlayer = game.getPlayers().stream()
+ .filter(player -> !player.equals(current))
+ .findFirst()
+ .orElse(null);
+
+ assertNotNull(wrongPlayer);
+
+ assertFalse(controller.pickOptionalTribeCard(wrongPlayer.getUserName(), 0));
+ assertFalse(controller.pickOptionalBuildingCard(wrongPlayer.getUserName(), 0));
+ assertFalse(controller.noOptionalCard(wrongPlayer.getUserName()));
+ }
+
+ @Test
+ void skipLowerDrawingShouldReturnFalseWhenLowerCharacterIsAvailable() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ completeSlotChoiceWithSlots(game, controller, 0, 1, 2);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ assertEquals(1, game.getCurrentState().getNLower());
+ assertEquals(0, game.getCurrentState().getNUpper());
+
+ assertFalse(game.getLowerListTribeCards().isEmpty());
+ assertTrue(firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1);
+
+ assertFalse(controller.SkipLowerDrawing(current.getUserName()));
+ }
+
+ @Test
+ void skipUpperDrawingShouldReturnFalseWhenUpperCharacterIsAvailable() {
+ Game game = createStartedGame();
+ GameController controller = new GameController(game);
+
+ completeSlotChoiceWithSlots(game, controller, 1, 2, 3);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ assertEquals(0, game.getCurrentState().getNLower());
+ assertEquals(1, game.getCurrentState().getNUpper());
+
+ assertFalse(game.getUpperListTribeCards().isEmpty());
+ assertTrue(firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1);
+
+ assertFalse(controller.SkipUpperDrawing(current.getUserName()));
+ }
+
+
}
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java
index a3d907a..89359e5 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java
@@ -112,6 +112,7 @@ class Building11Test {
@Test
@DisplayName("toString")
void testToString(){
+ int ID = 11;
int era = 1;
int price = 1;
int prestigeValue = 3;
@@ -119,26 +120,26 @@ class Building11Test {
int pm = 5;
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;
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;
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;
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;
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;
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());
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java
index cfd9ef4..0019f12 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java
@@ -70,22 +70,34 @@ class Building1Test {
@Test
@DisplayName("toString")
void testToString(){
- Building1 b1 = new Building1(1,2,3, CharacterType.INVENTOR);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: INVENTOR", b1.toString());
+ int ID = 1;
+ int era = 1;
+ int price = 1;
+ int prestigeValue = 3;
+ CharacterType ct = CharacterType.ARTIST;
+ int pm = 5;
- b1 = new Building1(1,2,3, CharacterType.BUILDER);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: BUILDER", b1.toString());
+ Building1 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.GATHERER);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: GATHERER", b1.toString());
+ ct = CharacterType.BUILDER;
+ 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);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: ARTIST", b1.toString());
+ ct = CharacterType.GATHERER;
+ 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);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: SHAMAN", b1.toString());
+ ct = CharacterType.HUNTER;
+ 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);
- assertEquals("Era:1 Price:2 Prestige:3 Icon: HUNTER", b1.toString());
+ ct = CharacterType.INVENTOR;
+ 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());
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java
index 15372ed..fc6268a 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java
@@ -57,13 +57,14 @@ class Building8Test {
b8.applyEffect(p);
assertEquals(1, p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count());
- assertEquals(PrestigeMul * 2 * p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count(), p.getPrestigeValue());
+ assertEquals(PrestigeMul* p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count(), p.getPrestigeValue());
+ p.removePrestige(p.getPrestigeValue());
Builder b2 = new Builder(Era, 1, PrestigeMul);
p.builders.add(b2);
b8.applyEffect(p);
- assertEquals(2 + 4, p.getPrestigeValue());
+ assertEquals(PrestigeMul * 2, p.getPrestigeValue());
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java
index 0f713fa..c5fd426 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCardTest.java
@@ -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.Effects.Building13;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -149,12 +150,162 @@ class BuildingCardTest {
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
@DisplayName("Testing toString method")
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
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java
index a4c79b5..925cffb 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ArtistTest.java
@@ -14,7 +14,7 @@ class ArtistTest {
String s = a.toString();
assertNotNull(s);
- assertTrue(s.contains(CharacterType.ARTIST.toString()));
+ assertTrue(s.contains("⎕:"));
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java
index afe9457..0ad64a9 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/BuilderTest.java
@@ -27,9 +27,8 @@ class BuilderTest {
String s = b.toString();
assertNotNull(s);
- assertTrue(s.contains(CharacterType.BUILDER.toString()));
- assertTrue(s.contains("Reduction Value: 2"));
- assertTrue(s.contains("Prestige Value: 3"));
+ assertFalse(s.contains(CharacterType.BUILDER.toString()));
+ assertEquals("⎕:" + " RV:" + b.getReductionValue() + " PV:" + b.getPrestigeValue(), s);
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java
index 96d3c83..e4529ee 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/GathererTest.java
@@ -14,7 +14,8 @@ class GathererTest {
String s = g.toString();
assertNotNull(s);
- assertTrue(s.contains(CharacterType.GATHERER.toString()));
+ assertFalse(s.contains(CharacterType.GATHERER.toString()));
+ assertTrue(s.contains("⎕:"));
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java
index 9da7e97..4313efe 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/HunterTest.java
@@ -18,13 +18,19 @@ class HunterTest {
@Test
void testToString() {
Hunter h = new Hunter(1, true);
- String s = h.toString();
-
- assertNotNull(s);
- assertTrue(s.contains(" I"));
+ assertTrue(h.toString().contains(" I"));
Hunter h2 = new Hunter(3, false);
- assertTrue(!h2.toString().contains("I"));
+ assertFalse(h2.toString().contains("I"));
+ }
+
+ @Test
+ void testToStringBoard() {
+ Hunter h = new Hunter(1, true);
+ assertTrue(h.toStringBoard().contains(" I"));
+
+ Hunter h2 = new Hunter(3, false);
+ assertFalse(h2.toStringBoard().contains("I"));
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java
index e89dcf2..fc0e85f 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/InventorTest.java
@@ -24,9 +24,8 @@ class InventorTest {
String s = i.toString();
assertNotNull(s);
- assertTrue(s.contains(CharacterType.INVENTOR.toString()));
- assertTrue(s.contains("Symbol:"));
- assertTrue(s.contains("5"));
+ assertFalse(s.contains(CharacterType.INVENTOR.toString()));
+ assertEquals("⎕:" + " I_ID:" + i.Icon(), i.toString());
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java
index c3111e4..b41cb69 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/ShamanTest.java
@@ -21,8 +21,8 @@ class ShamanTest {
String str = s.toString();
assertNotNull(str);
- assertTrue(str.contains(CharacterType.SHAMAN.toString()));
- assertTrue(str.contains("Icon: 4"));
+ assertFalse(str.contains(CharacterType.SHAMAN.toString()));
+ assertEquals("⎕: *:" + s.getIcon(), str);
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java
index d0c695a..ce6f322 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintingsTest.java
@@ -94,6 +94,36 @@ class CavePaintingsTest {
assertEquals(7, p1.getFoodValue());
}
+ @Test
+ @DisplayName("Not Building 9 test")
+ void activateEvent3() {
+ Player p1 = new Player("Marco");
+ ArrayList players = new ArrayList<>(Arrays.asList(p1));
+ CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
+ BuildingCard bc1 = new BuildingCard(9,1,5,5);
+ p1.addFood(5);
+ bc1.buy(p1);
+ new Artist(1).insert(p1);
+ cp1.activateEvent(players);
+
+ assertEquals(2, p1.getPrestigeValue());
+ assertEquals(1 * 1, p1.getFoodValue());
+
+ p1.removeFood(p1.getFoodValue());
+
+ BuildingCard bc2 = new BuildingCard(7,1,5,5);
+ BuildingCard bc3 = new BuildingCard(9,1,5,5);
+ p1.addFood(10);
+ bc2.buy(p1);
+ bc3.buy(p1);
+ new Artist(1).insert(p1);
+ new Artist(1).insert(p1);
+ cp1.activateEvent(players);
+
+ assertEquals(8, p1.getPrestigeValue());
+ assertEquals(2 * 3, p1.getFoodValue());
+ }
+
@Test
@DisplayName("Clone testing")
void cloneTest() {
@@ -111,6 +141,18 @@ class CavePaintingsTest {
void toStringTest() {
CavePaintings cv1 = new CavePaintings(1, 1,1,1);
- assertEquals("Era:1, CAVE_PAINTINGS", cv1.toString());
+ assertEquals("⎕:(Event)CAVE_PAINTINGS", cv1.toString());
+ }
+
+ @Test
+ @DisplayName("ToStringBoard testing")
+ void toStringBoardTest() {
+ int Era = 1;
+ int NLower = 1;
+ int NPrestigeRem = 2;
+ int NPrestigeMul = 3;
+ CavePaintings cv1 = new CavePaintings(Era, NLower,NPrestigeRem,NPrestigeMul);
+
+ assertEquals("⎕:(Event)" + cv1.getType() + " 0-"+(NLower-1)+":"+NPrestigeRem+" "+NLower+"+:"+NPrestigeMul, cv1.toStringBoard());
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java
index c38d1b0..f637d8e 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/HuntTest.java
@@ -41,8 +41,8 @@ class HuntTest {
new Hunter(1, false).insert(p2);
h1.activateEvent(players);
- assertEquals(6, p1.getPrestigeValue());
- assertEquals(2, p1.getFoodValue());
+ assertEquals(3*2, p1.getPrestigeValue());
+ assertEquals(1+2, p1.getFoodValue());
assertEquals(3, p2.getPrestigeValue());
assertEquals(1, p2.getFoodValue());
}
@@ -73,26 +73,63 @@ class HuntTest {
ArrayList players = new ArrayList<>(Arrays.asList(p1, p2, p3));
Hunt h1 = new Hunt(1, 3);
+ assertEquals(0, p1.getFoodValue());
+
new Hunter(1, true).insert(p1);
new Hunter(1, false).insert(p1);
new Hunter(1, false).insert(p2);
BuildingCard bc = new BuildingCard(7, 1, 5, 5);
p2.addFood(5);
+
bc.buy(p2);
+ assertEquals(5 - bc.getPrice(), p2.getFoodValue());
+ assertEquals(0, p2.getFoodValue());
new Hunter(1, false).insert(p3);
-
+ assertEquals(0, p3.getFoodValue());
h1.activateEvent(players);
- assertEquals(6, p1.getPrestigeValue());
- assertEquals(2, p1.getFoodValue());
+ assertEquals(3*2, p1.getPrestigeValue());
+ assertEquals(1 + 2, p1.getFoodValue());
assertEquals(4, p2.getPrestigeValue());
assertEquals(2, p2.getFoodValue());
assertEquals(3, p3.getPrestigeValue());
assertEquals(1, p3.getFoodValue());
}
+ @Test
+ @DisplayName("p2 doesnt have building 7")
+ void activateEvent4() {
+ Player p1 = new Player("Giacomo");
+ Player p2 = new Player("xiaomi");
+ Player p3 = new Player("test");
+
+ ArrayList players = new ArrayList<>(Arrays.asList(p1, p2, p3));
+ Hunt h1 = new Hunt(1, 3);
+
+ assertEquals(0, p1.getFoodValue());
+
+ new Hunter(1, true).insert(p1);
+ new Hunter(1, false).insert(p1);
+ new Hunter(1, false).insert(p2);
+ new Hunter(1, false).insert(p2);
+
+ assertEquals(0, p2.getFoodValue());
+ assertEquals(0, p2.getPrestigeValue());
+
+ new Hunter(1, false).insert(p3);
+ assertEquals(0, p3.getFoodValue());
+
+ h1.activateEvent(players);
+ assertEquals(3*2, p1.getPrestigeValue());
+ assertEquals(1 + 2, p1.getFoodValue());
+ assertEquals(3 * 2, p2.getPrestigeValue());
+ assertEquals(2, p2.getFoodValue());
+ assertEquals(3, p3.getPrestigeValue());
+ assertEquals(1, p3.getFoodValue());
+ }
+
@Test
@DisplayName("clone testing")
void cloneTest() {
@@ -113,6 +150,16 @@ class HuntTest {
void toStringTest() {
Hunt h1 = new Hunt(1, 3);
- assertEquals("Era:1, HUNT", h1.toString());
+ assertEquals("⎕:(Event)HUNT", h1.toString());
+ }
+
+ @Test
+ @DisplayName("ToStringBoard testing")
+ void toStringBoardTest() {
+ int Era = 1;
+ int prestigeMultiplier = 3;
+ Hunt cv1 = new Hunt(Era, prestigeMultiplier);
+
+ assertEquals("⎕:(Event)" + cv1.getType() + " 1F+" + prestigeMultiplier + "PP" + " X N Hunter", cv1.toStringBoard());
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java
index 0b7fd6c..c32fee7 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitualTest.java
@@ -190,6 +190,29 @@ class ShamanicRitualTest {
assertEquals(-5, p3.getPrestigeValue());
}
+ @Test
+ @DisplayName("p1 does not have building 6")
+ void ApplyEvent6() {
+ Player p1 = new Player("Marco");
+ Player p2 = new Player("Luca");
+
+
+ ArrayList players = new ArrayList<>(Arrays.asList(p1, p2));
+
+ new Shaman(1, 3).insert(p1);
+ new Shaman(1, 1).insert(p2);
+
+ BuildingCard b = new BuildingCard(2, 1, 5, 1);
+ p1.addFood(5);
+ b.buy(p1);
+
+ ShamanicRitual ritual = new ShamanicRitual(1, 10, 5);
+ ritual.activateEvent(players);
+
+ assertEquals(10, p1.getPrestigeValue());
+ assertEquals(-5, p2.getPrestigeValue());
+ }
+
@Test
@DisplayName("Clone testing")
void cloneTest() {
@@ -212,6 +235,17 @@ class ShamanicRitualTest {
void toStringTest() {
ShamanicRitual sr1 = new ShamanicRitual(1, 5,2);
- assertEquals("Era:1, SHAMANIC_RITUAL", sr1.toString());
+ assertEquals("⎕:(Event)SHAMANIC_RITUAL", sr1.toString());
+ }
+
+ @Test
+ @DisplayName("ToStringBoard testing")
+ void toStringBoardTest() {
+ int Era = 1;
+ int prestigeToAdd = 1;
+ int prestigeToRem = 2;
+ ShamanicRitual cv1 = new ShamanicRitual(Era, prestigeToAdd, prestigeToRem);
+
+ assertEquals("⎕:(Event)" + cv1.getType() + " *>:" + prestigeToAdd + " *<:" + prestigeToRem, cv1.toStringBoard());
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java
index 7dc452d..bbf060c 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/SustenanceTest.java
@@ -49,13 +49,13 @@ class SustenanceTest {
new Shaman(1, 5).insert(p1);
new Builder(1, 5, 5).insert(p1);
new Artist(1).insert(p1);
- new Hunter(1, true).insert(p1);
+ new Hunter(1, false).insert(p1);
new Gatherer(1).insert(p1);
p2.addFood(1);
new Artist(1).insert(p2);
- new Hunter(1, true).insert(p2);
- new Hunter(1, true).insert(p2);
+ new Hunter(1, false).insert(p2);
+ new Hunter(1, false).insert(p2);
@@ -79,7 +79,7 @@ class SustenanceTest {
new Shaman(1, 5).insert(p1);
new Builder(1, 5, 5).insert(p1);
new Artist(1).insert(p1);
- new Hunter(1, true).insert(p1);
+ new Hunter(1, false).insert(p1);
new Gatherer(1).insert(p1);
p2.addFood(2);
@@ -94,6 +94,39 @@ class SustenanceTest {
bd1.buy(p1);
bd2.buy(p2);
+ Sustenance s = new Sustenance(1,2);
+ s.activateEvent(players);
+ assertEquals(3, p1.getFoodValue());
+ assertEquals(1, p2.getFoodValue());
+ assertEquals(0, p1.getPrestigeValue());
+ assertEquals(0, p2.getPrestigeValue());
+ }
+
+ @Test
+ @DisplayName("Missing Building 1 testing")
+ void activateEvent3() {
+ Player p1 = new Player("marco");
+ Player p2 = new Player("giacomo");
+ ArrayList players = new ArrayList<>(Arrays.asList(p1,p2));
+
+ p1.addFood(5);
+ new Inventor(1, 1).insert(p1);
+ new Shaman(1, 5).insert(p1);
+ new Builder(1, 5, 5).insert(p1);
+ new Artist(1).insert(p1);
+ new Hunter(1, false).insert(p1);
+ new Gatherer(1).insert(p1);
+
+ p2.addFood(2);
+ new Artist(1).insert(p2);
+ new Artist(1).insert(p2);
+ new Artist(1).insert(p2);
+
+
+ Building1 bd2 = new Building1(1, 1, 1, CharacterType.ARTIST);
+
+ bd2.buy(p2);
+
Sustenance s = new Sustenance(1,2);
s.activateEvent(players);
assertEquals(2, p1.getFoodValue());
@@ -122,7 +155,17 @@ class SustenanceTest {
void toStringTest() {
Sustenance s1 = new Sustenance(1, 5);
- assertEquals("Era:1, SUSTENANCE", s1.toString());
+ assertEquals("⎕:(Event)SUSTENANCE", s1.toString());
+ }
+
+ @Test
+ @DisplayName("ToStringBoard testing")
+ void toStringBoardTest() {
+ int Era = 3;
+ int prestigeDebt = 15;
+ Sustenance cv1 = new Sustenance(Era, prestigeDebt);
+
+ assertEquals("⎕:(Event)" + cv1.getType() + " -1F/-" + prestigeDebt + "PP", cv1.toStringBoard());
}
}
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java
index f270740..dd9db49 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java
@@ -125,11 +125,11 @@ class BoardTest {
void removeUpperTribeCard() {
Board bd = new Board(3);
- List before = bd.upperListTribe;
- TribeCard cardToRemove = before.get(2);
+ List before = new ArrayList<>( bd.upperListTribe);
+ TribeCard cardToRemove = before.get(0);
- before.remove(2);
- bd.removeUpperTribeCard(cardToRemove);
+ assertEquals(cardToRemove, before.remove(0));
+ assertTrue( bd.removeUpperTribeCard(cardToRemove));
assertEquals(before, bd.upperListTribe);
}
@@ -139,25 +139,25 @@ class BoardTest {
void removeLowerTribeCard() {
Board bd = new Board(3);
- List before = bd.lowerListTribe;
- TribeCard cardToRemove = before.get(2);
+ List before = new ArrayList<>(bd.lowerListTribe);
+ TribeCard cardToRemove = before.get(0);
- before.remove(2);
- bd.removeLowerTribeCard(cardToRemove);
+ assertEquals(cardToRemove, before.remove(0));
+ assertTrue( bd.removeLowerTribeCard(cardToRemove));
assertEquals(before, bd.lowerListTribe);
}
@Test
- @DisplayName("RemgetTribeDeckSizeoving a card from upper row of building cards")
+ @DisplayName("Removing a card from upper row of building cards")
void removeUpperBuildingCard() {
Board bd = new Board(3);
- List before = bd.upperListBuilding;
+ List before = new ArrayList<>(bd.upperListBuilding);
BuildingCard cardToRemove = before.get(0);
- before.remove(0);
- bd.removeUpperBuildingCard(cardToRemove);
+ assertEquals(cardToRemove, before.remove(0));
+ assertTrue( bd.removeUpperBuildingCard(cardToRemove));
assertEquals(before, bd.upperListBuilding);
}
@@ -171,12 +171,10 @@ class BoardTest {
bd.nextRound(); // Skip to era 2
}
- List before = bd.lowerListBuilding;
+ List before = new ArrayList<>( bd.lowerListBuilding);
BuildingCard cardToRemove = before.get(0);
-
- before.remove(0);
- bd.removeLowerBuildingCard(cardToRemove);
-
+ assertEquals(cardToRemove, before.remove(0));
+ assertTrue(bd.removeLowerBuildingCard(cardToRemove));
assertEquals(before, bd.lowerListBuilding);
}
@@ -214,6 +212,8 @@ class BoardTest {
assertEquals(upperListBefore, bd1.lowerListBuilding);
assertNotEquals(upperListBefore, bd1.upperListBuilding);
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
@@ -227,7 +227,8 @@ class BoardTest {
assertEquals(upperListBefore, bd2.lowerListBuilding);
assertNotEquals(upperListBefore, bd2.upperListBuilding);
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
numPlayer = 2;
@@ -243,6 +244,8 @@ class BoardTest {
assertEquals(upperListBefore, bd3.lowerListBuilding);
assertNotEquals(upperListBefore, bd3.upperListBuilding);
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
@@ -259,6 +262,8 @@ class BoardTest {
assertEquals(upperListBefore, bd4.lowerListBuilding);
assertNotEquals(upperListBefore, bd4.upperListBuilding);
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
@@ -275,6 +280,8 @@ class BoardTest {
assertEquals(upperListBefore, bd5.lowerListBuilding);
assertNotEquals(upperListBefore, bd5.upperListBuilding);
assertEquals(4, bd5.upperListBuilding.size());
+ assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3));
+ assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
}
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java
index b07549a..6fe34e9 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java
@@ -70,7 +70,7 @@ class CurrentStateTest {
void getGameStage() {
Player p = new Player("test");
Slot s = new Slot('A');
- GameStages g = GameStages.RESOLVING_ACTIONS;
+ GameStages g = GameStages.RES_ACTIONS;
CurrentState curr = new CurrentState();
curr.PlayerUpdate(p, s);
curr.GameStageUpdate(g);
@@ -122,12 +122,12 @@ class CurrentStateTest {
void gameStageUpdate() {
Player p = new Player("test");
Slot s = new Slot('A');
- GameStages g = GameStages.RESOLVING_ACTIONS;
+ GameStages g = GameStages.RES_ACTIONS;
CurrentState curr = new CurrentState();
assertEquals(GameStages.WAITING, curr.getGameStage());
curr.PlayerUpdate(p, s);
curr.GameStageUpdate(g);
- assertEquals(GameStages.RESOLVING_ACTIONS, curr.getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, curr.getGameStage());
}
@Test
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java
index 959dd13..1f5bb4e 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java
@@ -5,10 +5,12 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
+import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -28,7 +30,7 @@ class GameTest {
assertTrue(game.SlotChoiceByIndex(current, i));
}
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
return order;
}
@@ -61,7 +63,7 @@ class GameTest {
}
private void resolveAllMandatoryActions(Game game) {
- while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) {
resolveOneMandatoryAction(game);
}
}
@@ -70,57 +72,69 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current);
- if (game.getCurrentState().getNLower() > 0 && hasDrawableLower(game)) {
+ if (game.getCurrentState().getNLower() > 0) {
int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards());
if (index != -1) {
assertTrue(game.DrawLowerTribeCardByIndex(current, index));
- } else {
- current.addFood(100);
- assertTrue(game.DrawLowerBuildingCardByIndex(current, 0));
+ return;
}
- } else if (game.getCurrentState().getNUpper() > 0 && hasDrawableUpper(game)) {
+ if (!game.getLowerListBuilding().isEmpty()
+ && game.DrawLowerBuildingCardByIndex(current, 0)) {
+ return;
+ }
+
+ assertTrue(game.SkipLowerDrawing(current));
+ return;
+ }
+
+ if (game.getCurrentState().getNUpper() > 0) {
int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
if (index != -1) {
assertTrue(game.DrawUpperTribeCardByIndex(current, index));
- } else {
- current.addFood(100);
- assertTrue(game.DrawUpperBuildingCardByIndex(current, 0));
+ return;
}
- } else {
- fail(
- "Current player has no drawable cards, although the game is still resolving actions.\n" +
- "Current player: " + current + "\n" +
- "Round: " + game.getCurrentState().getRound() + "\n" +
- "Stage: " + game.getCurrentState().getGameStage() + "\n" +
- "Slot: " + (game.getCurrentState().getSlot() == null
- ? "null"
- : game.getCurrentState().getSlot().getSlotId()) + "\n" +
- "NLower: " + game.getCurrentState().getNLower() + "\n" +
- "NUpper: " + game.getCurrentState().getNUpper() + "\n" +
- "Lower tribe size: " + game.getLowerListTribeCards().size() + "\n" +
- "Upper tribe size: " + game.getUpperListTribeCards().size() + "\n" +
- "Lower building size: " + game.getLowerListBuilding().size() + "\n" +
- "Upper building size: " + game.getUpperListBuilding().size() + "\n" +
- "First lower non-event: " + firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) + "\n" +
- "First upper non-event: " + firstNonEventIndexOrMinusOne(game.getUpperListTribeCards())
- );
+ if (!game.getUpperListBuilding().isEmpty()
+ && game.DrawUpperBuildingCardByIndex(current, 0)) {
+ return;
+ }
+
+ assertTrue(game.SkipUpperDrawing(current));
+ return;
}
+
+ fail(
+ "Current player has no remaining draw actions.\n" +
+ "Current player: " + current + "\n" +
+ "Round: " + game.getCurrentState().getRound() + "\n" +
+ "Stage: " + game.getCurrentState().getGameStage() + "\n" +
+ "Slot: " + (game.getCurrentState().getSlot() == null
+ ? "null"
+ : game.getCurrentState().getSlot().getSlotId()) + "\n" +
+ "NLower: " + game.getCurrentState().getNLower() + "\n" +
+ "NUpper: " + game.getCurrentState().getNUpper() + "\n" +
+ "Lower tribe size: " + game.getLowerListTribeCards().size() + "\n" +
+ "Upper tribe size: " + game.getUpperListTribeCards().size() + "\n" +
+ "Lower building size: " + game.getLowerListBuilding().size() + "\n" +
+ "Upper building size: " + game.getUpperListBuilding().size() + "\n" +
+ "First lower non-event: " + firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) + "\n" +
+ "First upper non-event: " + firstNonEventIndexOrMinusOne(game.getUpperListTribeCards())
+ );
}
private void resolveActionsUntilOptionalCardEffect(Game game) {
- while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) {
resolveOneMandatoryAction(game);
}
- assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
}
private void resolveOptionalPhaseIfPresent(Game game) {
- while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) {
+ while (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) {
Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current);
@@ -133,21 +147,20 @@ class GameTest {
completeSlotChoice(game);
- assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
resolveAllMandatoryActions(game);
resolveOptionalPhaseIfPresent(game);
}
- private boolean hasDrawableLower(Game game) {
- return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1
- || !game.getLowerListBuilding().isEmpty();
- }
+ private void resolveCurrentPlayerCompletely(Game game, Player expectedPlayer) {
+ assertEquals(expectedPlayer, game.getCurrentState().getCurrentPlayer());
- private boolean hasDrawableUpper(Game game) {
- return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1
- || !game.getUpperListBuilding().isEmpty();
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS
+ && expectedPlayer.equals(game.getCurrentState().getCurrentPlayer())) {
+ resolveOneMandatoryAction(game);
+ }
}
@Test
@@ -282,7 +295,7 @@ class GameTest {
assertTrue(game.addPlayer(p3));
Queue players = new LinkedList<>();
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < game.getNPlayers(); i++) {
players.add(game.getCurrentState().getCurrentPlayer());
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
}
@@ -325,11 +338,14 @@ class GameTest {
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, eventIndex));
}
- temp_player.addFood(100);
-
assertFalse(game.getUpperListBuilding().isEmpty());
+ temp_player.builders.clear();
+
index = 0;
+ BuildingCard selectedBuilding = game.getUpperListBuilding().get(index);
+ temp_player.addFood(selectedBuilding.getPrice());
+
assertTrue(game.DrawUpperBuildingCardByIndex(temp_player, index));
int remainingTribeIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
@@ -341,15 +357,12 @@ class GameTest {
assertNotNull(thirdPlayer);
assertEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer());
- while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS
&& thirdPlayer.equals(game.getCurrentState().getCurrentPlayer())) {
resolveOneMandatoryAction(game);
}
assertNotEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer());
-
- System.out.println(game);
-
}
private void drawTribeTest(HashMap nCardsByType,
@@ -436,15 +449,30 @@ class GameTest {
assertFalse(game.getUpperListBuilding().isEmpty());
- current.addFood(100);
+ current.builders.clear();
+
+ BuildingCard selectedBuilding = game.getUpperListBuilding().get(0);
+ int expectedCost = selectedBuilding.getPrice();
+
+ current.addFood(expectedCost);
- int foodBefore = current.getFoodValue();
int buildingsBefore = current.buildingCards.size();
+ int upperBuildingsBefore = game.getUpperListBuilding().size();
+ int foodBefore = current.getFoodValue();
assertTrue(game.PickOptionalBuildingCard(current, 0));
- assertTrue(current.getFoodValue() < foodBefore);
assertEquals(buildingsBefore + 1, current.buildingCards.size());
+ assertEquals(upperBuildingsBefore - 1, game.getUpperListBuilding().size());
+
+ assertTrue(current.buildingCards.stream()
+ .anyMatch(building ->
+ building.getPrice() == selectedBuilding.getPrice()
+ && building.getPrestigeValue() == selectedBuilding.getPrestigeValue()
+ && building.getEffectId() == selectedBuilding.getEffectId()
+ ));
+
+ assertEquals(foodBefore - expectedCost, current.getFoodValue());
}
@Test
@@ -469,7 +497,7 @@ class GameTest {
assertTrue(game.NoOptionalCard(current));
- assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
}
@@ -634,7 +662,7 @@ class GameTest {
assertDoesNotThrow(() -> resolveAllMandatoryActions(game));
- assertNotEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
+ assertNotEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
}
@@ -671,6 +699,8 @@ class GameTest {
assertTrue(game.addPlayer(new Player("p" + nPlayers + "_" + i)));
}
+ assertEquals(nPlayers, game.getCurrentPlayerNumber());
+ assertEquals(nPlayers, game.getPlayers().size());
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
assertEquals(1, game.getCurrentState().getRound());
assertNotNull(game.getCurrentState().getCurrentPlayer());
@@ -678,6 +708,7 @@ class GameTest {
for (int expectedRound = 1; expectedRound < 10; expectedRound++) {
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
assertEquals(expectedRound, game.getCurrentState().getRound());
+ assertEquals(nPlayers, game.getCurrentPlayerNumber());
playOneFullRound(game);
@@ -693,6 +724,7 @@ class GameTest {
"The round should increase after completing round " + expectedRound + "."
);
+ assertEquals(nPlayers, game.getCurrentPlayerNumber());
assertNotNull(game.getCurrentState().getCurrentPlayer());
}
@@ -707,11 +739,8 @@ class GameTest {
"The game should end after completing round 10 with " + nPlayers + " players."
);
- assertEquals(
- 10,
- game.getCurrentState().getRound(),
- "The game should end at round 10 with " + nPlayers + " players."
- );
+ assertEquals(10, game.getCurrentState().getRound());
+ assertEquals(nPlayers, game.getPlayers().size());
}
}
@@ -798,6 +827,8 @@ class GameTest {
assertTrue(current.removeFood(1));
}
+ current.builders.clear();
+
assertEquals(0, current.getFoodValue());
assertFalse(
@@ -807,8 +838,9 @@ class GameTest {
assertFalse(game.PickOptionalBuildingCard(current, 0));
}
+
@Test
- void toStringModel() throws IOException, InterruptedException {
+ void toStringModel() {
Game game=new Game(5);
Player p1=new Player("p1");
Player p2=new Player("p2");
@@ -823,11 +855,346 @@ class GameTest {
assertTrue(game.addPlayer(p5));
Queueplayers=new LinkedList<>();
- for(int i=0;i<3;i++) {
- players.add( game.getCurrentState().getCurrentPlayer());
+ for (int i = 0; i < game.getNPlayers(); i++) {
+ players.add(game.getCurrentState().getCurrentPlayer());
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
}
- System.out.println(game.toString());
+ String result = game.toString();
+
+ assertNotNull(result);
+ assertFalse(result.isBlank());
+ assertTrue(result.contains("CURRENT STATE"));
}
+
+ @Test
+ @Timeout(value = 5, unit = TimeUnit.SECONDS)
+ void shouldDrawLowerBuildingWhenAvailableAndPlayerCanPay() {
+ Game game = new Game(3);
+
+ addPlayers(game, 3, "lower_building_");
+
+ for (int safety = 0; safety < 300; safety++) {
+
+ if (game.getCurrentState().getGameStage() == GameStages.SLOT_CHOICE) {
+ completeSlotChoice(game);
+ }
+
+ if (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) {
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ if (game.getCurrentState().getNLower() > 0
+ && !game.getLowerListBuilding().isEmpty()) {
+
+ current.builders.clear();
+
+ BuildingCard selectedBuilding = game.getLowerListBuilding().get(0);
+ int expectedCost = selectedBuilding.getPrice();
+
+ current.addFood(expectedCost);
+
+ int buildingsBefore = current.buildingCards.size();
+ int lowerBuildingsBefore = game.getLowerListBuilding().size();
+ int foodBefore = current.getFoodValue();
+
+ assertTrue(
+ game.DrawLowerBuildingCardByIndex(current, 0),
+ "DrawLowerBuildingCardByIndex should return true when lower building exists, player can draw lower, and player has food."
+ );
+
+ assertEquals(buildingsBefore + 1, current.buildingCards.size());
+ assertEquals(lowerBuildingsBefore - 1, game.getLowerListBuilding().size());
+ assertTrue(current.buildingCards.stream()
+ .anyMatch(building ->
+ building.getPrice() == selectedBuilding.getPrice()
+ && building.getPrestigeValue() == selectedBuilding.getPrestigeValue()
+ && building.getEffectId() == selectedBuilding.getEffectId()
+ ));
+ assertTrue(
+ current.getFoodValue() >= foodBefore - expectedCost,
+ "After buying the building, food should not be lower than the price paid because later effects may add food."
+ );
+ return;
+ }
+
+ resolveOneMandatoryAction(game);
+ }
+
+ if (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) {
+ resolveOptionalPhaseIfPresent(game);
+ }
+
+ if (game.getCurrentState().getGameStage() == GameStages.ENDED) {
+ break;
+ }
+ }
+
+ fail("The test never reached a state with NLower > 0 and at least one lower building.");
+ }
+
+ @Test
+ void drawBuildingShouldReturnFalseIfPlayerCannotPay() {
+ Game game = new Game(3);
+ addPlayers(game, 3, "no_food_building_");
+
+ completeSlotChoice(game);
+
+ while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) {
+ Player current = game.getCurrentState().getCurrentPlayer();
+
+ if (game.getCurrentState().getNUpper() > 0
+ && !game.getUpperListBuilding().isEmpty()) {
+
+ while (current.getFoodValue() > 0) {
+ assertTrue(current.removeFood(1));
+ }
+
+ current.builders.clear();
+
+ assertEquals(0, current.getFoodValue());
+
+ assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
+ return;
+ }
+
+ resolveOneMandatoryAction(game);
+ }
+
+ fail("No upper building draw state reached.");
+ }
+
+ @Test
+ void shouldResolvePlayersAccordingToSlotOrder() {
+ Game game = new Game(3);
+ addPlayers(game, 3, "slot_order_");
+
+ Player firstChooser = game.getCurrentState().getCurrentPlayer();
+ assertTrue(game.SlotChoiceByIndex(firstChooser, 2));
+
+ Player secondChooser = game.getCurrentState().getCurrentPlayer();
+ assertTrue(game.SlotChoiceByIndex(secondChooser, 0));
+
+ Player thirdChooser = game.getCurrentState().getCurrentPlayer();
+ assertTrue(game.SlotChoiceByIndex(thirdChooser, 1));
+
+ assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage());
+
+ assertEquals(secondChooser, game.getCurrentState().getCurrentPlayer());
+
+ resolveCurrentPlayerCompletely(game, secondChooser);
+
+ assertEquals(thirdChooser, game.getCurrentState().getCurrentPlayer());
+
+ resolveCurrentPlayerCompletely(game, thirdChooser);
+
+ assertEquals(firstChooser, game.getCurrentState().getCurrentPlayer());
+ }
+
+ @Test
+ @Timeout(value = 20, unit = TimeUnit.SECONDS)
+ void endGameShouldNotCrashWhenTriggeredAfterRoundTen() {
+ Game game = new Game(3);
+
+ List players = addPlayers(game, 3, "end_game_");
+
+ giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
+
+ while (game.getCurrentState().getRound() < 10) {
+ playOneFullRound(game);
+ }
+
+ assertEquals(10, game.getCurrentState().getRound());
+ assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
+
+ completeSlotChoice(game);
+ resolveAllMandatoryActions(game);
+
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
+
+ assertDoesNotThrow(() -> resolveOptionalPhaseIfPresent(game));
+
+ assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
+ }
+
+ @Test
+ @Timeout(value = 20, unit = TimeUnit.SECONDS)
+ void endGameShouldAddBuildingPrestigeValues() {
+ Game game = new Game(3);
+
+ List players = addPlayers(game, 3, "building_prestige_");
+
+ giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
+
+ while (game.getCurrentState().getRound() < 10) {
+ playOneFullRound(game);
+ }
+
+ completeSlotChoice(game);
+ resolveAllMandatoryActions(game);
+
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
+
+ Player player = players.get(0);
+
+ int prestigeBefore = player.getPrestigeValue();
+
+ player.buildingCards.add(new BuildingCard(12, 1, 1, 7));
+ player.buildingCards.add(new BuildingCard(12, 1, 1, 5));
+
+ int expectedMinimumIncrease = 7 + 5;
+
+ resolveOptionalPhaseIfPresent(game);
+
+ assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
+
+ assertTrue(
+ player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease,
+ "Final scoring should add at least the prestige values of the two added building cards."
+ );
+ }
+
+ @Test
+ @Timeout(value = 20, unit = TimeUnit.SECONDS)
+ void endGameShouldApplyFinalCharacterPrestigeBonuses() {
+ Game game = new Game(3);
+
+ List players = addPlayers(game, 3, "final_characters_");
+ giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
+
+ while (game.getCurrentState().getRound() < 10) {
+ playOneFullRound(game);
+ }
+
+ completeSlotChoice(game);
+ resolveAllMandatoryActions(game);
+
+ assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
+
+ Player player = players.get(0);
+ assertNotNull(player);
+
+ int prestigeBefore = player.getPrestigeValue();
+
+ player.builders.add(new Builder(1, 0, 4));
+
+ player.inventors.add(new Inventor(1, 0));
+ player.inventors.add(new Inventor(1, 1));
+
+ player.artists.add(new Artist(1));
+ player.artists.add(new Artist(1));
+
+ int expectedMinimumIncrease = 4 + 4 + 10;
+
+ resolveOptionalPhaseIfPresent(game);
+
+ assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
+
+ assertTrue(
+ player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease,
+ "Final scoring should add at least builder prestige, inventor bonus, and artist pair bonus."
+ );
+ }
+
+ @Test
+ void skipDrawingShouldRejectWrongPlayer() {
+ Game game = new Game(3);
+
+ List players = addPlayers(game, 3, "skip_wrong_");
+
+ completeSlotChoice(game);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ Player wrongPlayer = players.stream()
+ .filter(p -> !p.equals(current))
+ .findFirst()
+ .orElseThrow();
+
+ assertFalse(game.SkipLowerDrawing(wrongPlayer));
+ assertFalse(game.SkipUpperDrawing(wrongPlayer));
+ }
+
+ @Test
+ void skipDrawingShouldReturnFalseWhenDrawableCardsExist() {
+ Game game = new Game(3);
+
+ addPlayers(game, 3, "skip_drawable_");
+
+ completeSlotChoice(game);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ boolean checkedAtLeastOneSkip = false;
+
+ if (game.getCurrentState().getNLower() > 0
+ && firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1) {
+ assertFalse(game.SkipLowerDrawing(current));
+ checkedAtLeastOneSkip = true;
+ }
+
+ if (game.getCurrentState().getNUpper() > 0
+ && firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1) {
+ assertFalse(game.SkipUpperDrawing(current));
+ checkedAtLeastOneSkip = true;
+ }
+
+ assertTrue(
+ checkedAtLeastOneSkip,
+ "The test should check at least one skip rejection when drawable cards exist."
+ );
+ }
+
+ @Test
+ void pickOptionalTribeCardShouldRejectEventCard() {
+ Game game = new Game(3);
+
+ List players = addPlayers(game, 3, "optional_event_");
+
+ giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
+
+ completeSlotChoice(game);
+ resolveActionsUntilOptionalCardEffect(game);
+
+ Player current = game.getCurrentState().getCurrentPlayer();
+ assertNotNull(current);
+
+ int eventIndex = firstEventIndexOrMinusOne(game.getUpperListTribeCards());
+
+ assertNotEquals(
+ -1,
+ eventIndex,
+ "There should be at least one event card in the upper tribe list to test rejection."
+ );
+
+ assertFalse(game.PickOptionalTribeCardByIndex(current, eventIndex));
+ }
+
+ @Test
+ void cardListsShouldReturnCopiesOfLists() {
+ Game game = new Game(3);
+
+ List upper = game.getUpperListTribeCards();
+ int originalSize = upper.size();
+
+ upper.clear();
+
+ assertEquals(originalSize, game.getUpperListTribeCards().size());
+ }
+
+ @Test
+ void getPlayersShouldReturnAddedPlayers() {
+ Game game = new Game(3);
+
+ Player p1 = new Player("gp1");
+ Player p2 = new Player("gp2");
+
+ assertTrue(game.addPlayer(p1));
+ assertTrue(game.addPlayer(p2));
+
+ assertEquals(2, game.getPlayers().size());
+ assertTrue(game.getPlayers().contains(p1));
+ assertTrue(game.getPlayers().contains(p2));
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java
index 22347b3..0971e8a 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order2Test.java
@@ -155,16 +155,52 @@ class Order2Test {
assertEquals(p1, order.getFirst());
assertEquals(p1, order.getFirst());
}
+
@Test
void toStringTest() throws NoSuchFieldException, IllegalAccessException {
- Player p1 = new Player("wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p2 = new Player("L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk");
+ String usr1 = "wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz";
+ String usr2 = "L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk";
+
+ Player p1 = new Player(usr1);
+ Player p2 = new Player(usr2);
Order2 order = new Order2(new ArrayList<>(Arrays.asList(p1, p2)));
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
order.pull();
order.pull();
+
+ assertFalse(order.toString().contains(usr1));
+ assertFalse(order.toString().contains(usr2));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
order.push(p2);
order.push(p1);
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
order.pull().getUserName();
- System.out.println(order);
+
+ assertTrue(order.toString().contains(usr1));
+ assertFalse(order.toString().contains(usr2));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ Player extraPlayer = new Player("px");
+ //TODO testare IndexOutOfBoundsException
+// assertThrows(IndexOutOfBoundsException.class, () -> {
+// Order2 ox = new Order2(new ArrayList<>(Arrays.asList(p1, p2)));;
+// ox.pull();
+// ox.pull();
+// ox.pull();
+// ox.push(extraPlayer);
+// });
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java
index 3e24680..686172a 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java
@@ -183,28 +183,54 @@ class Order3Test {
}
@Test
void toStringTest() throws NoSuchFieldException, IllegalAccessException {
- Player p1 = new Player("wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p2 = new Player("L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk");
- Player p3 = new Player("L*Ncw1ryyrF2xn%H@4P1iC@&NNIooQQk");
- Order3 order = new Order3(new ArrayList<>(Arrays.asList(p1, p2,p3)));
- Field field = Order3.class.getSuperclass().getDeclaredField("playerList");
- field.setAccessible(true);
- List values =(ArrayList)field.get(order);
+ String usr1 = "wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz";
+ String usr2 = "L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk";
+ String usr3 = "L*Ncw1rjjrF2xn%H@4d1iC@&NNIooQQk";
- String userPulled=order.pull().getUserName();
- userPulled=order.pull().getUserName();
- userPulled=order.pull().getUserName();
+ Player p1 = new Player(usr1);
+ Player p2 = new Player(usr2);
+ Player p3 = new Player(usr3);
+ Order3 order = new Order3(new ArrayList<>(Arrays.asList(p1, p2, p3)));
- System.out.println(values);
- order.push(p1);
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull();
+ order.pull();
+ order.pull();
+
+ assertFalse(order.toString().contains(usr1));
+ assertFalse(order.toString().contains(usr2));
+ assertFalse(order.toString().contains(usr3));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.push(p3);
order.push(p2);
- values =(ArrayList)field.get(order);
- System.out.println(order);
-// assertEquals("TURN ORDER\n" +
-// "╔════════════════════════════════════╦════════════════════════════════════╦════════════════════════════════════╗\n" +
-// "║ 0. ║ 1. "+values.get(1).getUserName() +"║ 2. "+values.get(2).getUserName()+"║\n" +
-// "║ +2 Food ║ -- ║ -1 Food / -2 Prestige ║\n"+
-// "╚════════════════════════════════════╩════════════════════════════════════╩════════════════════════════════════╝\n", order.toString());
+ order.push(p1);
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull().getUserName();
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertFalse(order.toString().contains(usr3));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ //TODO testare IndexOutOfBoundsException
}
}
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java
index 78e731f..67d4023 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order4Test.java
@@ -274,13 +274,65 @@ class Order4Test {
@Test
void toStringTest() throws NoSuchFieldException, IllegalAccessException {
- Player p1 = new Player("wPIshNQhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p2 = new Player("L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk");
- Player p3 = new Player("wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p4 = new Player("wPIshOThiOpRRnIBFfM89s2$@q$9FGbz");
- Order4 order = new Order4(new ArrayList<>(Arrays.asList(p1, p2,p3,p4)));
- String userPulled=order.pull().getUserName();
- System.out.println(order);
+ String usr1 = "wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz";
+ String usr2 = "L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk";
+ String usr3 = "L*Ncw1rjjrF2xn%H@4d1iC@&NNIooQQk";
+ String usr4 = "L*Ncw1rjkrF2xn%H@4d1iC@&NNIooQQk";
+ Player p1 = new Player(usr1);
+ Player p2 = new Player(usr2);
+ Player p3 = new Player(usr3);
+ Player p4 = new Player(usr4);
+ Order4 order = new Order4(new ArrayList<>(Arrays.asList(p1, p2, p3, p4)));
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains(usr4));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull();
+ order.pull();
+ order.pull();
+ order.pull();
+
+ assertFalse(order.toString().contains(usr1));
+ assertFalse(order.toString().contains(usr2));
+ assertFalse(order.toString().contains(usr3));
+ assertFalse(order.toString().contains(usr4));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.push(p4);
+ order.push(p3);
+ order.push(p2);
+ order.push(p1);
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains(usr4));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull().getUserName();
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertFalse(order.toString().contains(usr4));
+ assertTrue(order.toString().contains("+2 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ //TODO testare IndexOutOfBoundsException
}
}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java
index 9e838fb..a43efb8 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order5Test.java
@@ -369,20 +369,74 @@ class Order5Test {
}
@Test
void toStringTest() throws NoSuchFieldException, IllegalAccessException {
- Player p1 = new Player("wPIshUEhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p2 = new Player("L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk");
- Player p3 = new Player("wPIshOUhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p4 = new Player("wPIshNUhiOpRRnIBFfM89s2$@q$9FGbz");
- Player p5 = new Player("wPIshKUhiOpRRnIBFfM89s2$@q$9FGbz");
- Order5 order = new Order5(new ArrayList<>(Arrays.asList(p1, p2,p3,p4,p5)));
- order.pull();
- order.pull();
- order.pull();
- order.pull();
- order.pull();
- order.push(p1);
- System.out.println(order);
+ String usr1 = "wPIshEUhiOpRRnIBFfM89s2$@q$9FGbz";
+ String usr2 = "L*Ncw1rjjrF2xn%H@4P1iC@&NNIooQQk";
+ String usr3 = "L*Ncw1rjjrF2xn%H@4d1iC@&NNIooQQk";
+ String usr4 = "L*Ncw1rjkrF2xn%H@4d1iC@&NNIooQQk";
+ String usr5 = "L*pcw1rjjrF2xn%H@4d1iC@&NNIooQQk";
+ Player p1 = new Player(usr1);
+ Player p2 = new Player(usr2);
+ Player p3 = new Player(usr3);
+ Player p4 = new Player(usr4);
+ Player p5 = new Player(usr5);
+ Order5 order = new Order5(new ArrayList<>(Arrays.asList(p1, p2, p3, p4, p5)));
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains(usr4));
+ assertTrue(order.toString().contains(usr5));
+ assertTrue(order.toString().contains("+3 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull();
+ order.pull();
+ order.pull();
+ order.pull();
+ order.pull();
+
+ assertFalse(order.toString().contains(usr1));
+ assertFalse(order.toString().contains(usr2));
+ assertFalse(order.toString().contains(usr3));
+ assertFalse(order.toString().contains(usr4));
+ assertFalse(order.toString().contains(usr5));
+ assertTrue(order.toString().contains("+3 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.push(p5);
+ order.push(p4);
+ order.push(p3);
+ order.push(p2);
+ order.push(p1);
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains(usr4));
+ assertTrue(order.toString().contains(usr5));
+ assertTrue(order.toString().contains("+3 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ order.pull();
+
+ assertTrue(order.toString().contains(usr1));
+ assertTrue(order.toString().contains(usr2));
+ assertTrue(order.toString().contains(usr3));
+ assertTrue(order.toString().contains(usr4));
+ assertFalse(order.toString().contains(usr5));
+ assertTrue(order.toString().contains("+3 Food"));
+ assertTrue(order.toString().contains("+1 Food"));
+ assertTrue(order.toString().contains("--"));
+ assertTrue(order.toString().contains("-1 Food / -2 PP"));
+
+ //TODO capire come è testato IndexOutOfBoundsExceptions
}
}
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayerTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayerTest.java
new file mode 100644
index 0000000..780564a
--- /dev/null
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/OrderPlayerTest.java
@@ -0,0 +1,26 @@
+package it.polimi.ingsw.gc14.Model.Orders;
+
+import it.polimi.ingsw.gc14.Model.Player;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+
+class OrderPlayerTest {
+
+ @Test
+ void toStringShouldReturnUsernameAndPlayedStatusTrue() {
+ Player player = new Player("Marco");
+ OrderPlayer orderPlayer = new OrderPlayer(player, true);
+
+ assertEquals("Marco true", orderPlayer.toString());
+ }
+
+ @Test
+ void toStringShouldReturnUsernameAndPlayedStatusFalse() {
+ Player player = new Player("Luca");
+ OrderPlayer orderPlayer = new OrderPlayer(player, false);
+
+ assertEquals("Luca false", orderPlayer.toString());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java
index 1a30d9b..b0fdc51 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/PlayerTest.java
@@ -220,7 +220,6 @@ class PlayerTest {
p.buildingCards.add(new Building1(2, 5, 5, CharacterType.INVENTOR));
p.buildingCards.add(new Building1(2, 5, 5, CharacterType.SHAMAN));
p.buildingCards.add(new Building11(1, 5, 7, CharacterType.ARTIST , 3));
- System.out.println(p.toString());
assertEquals(""+
"╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗\n" +
"║ test_usr ║\n" +
diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java
index ca32b35..b307ccc 100644
--- a/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java
+++ b/src/test/java/it/polimi/ingsw/gc14/Model/SlotTest.java
@@ -46,7 +46,6 @@ class SlotTest {
assertEquals(0, s.getNLower());
assertEquals(0, s.getNUpper());
assertEquals(5, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
@@ -60,7 +59,6 @@ class SlotTest {
assertEquals(1, s.getNLower());
assertEquals(0, s.getNUpper());
assertEquals(0, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
@@ -74,7 +72,6 @@ class SlotTest {
assertEquals(0, s.getNLower());
assertEquals(1, s.getNUpper());
assertEquals(0, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString()); }
@Test
@@ -87,7 +84,6 @@ class SlotTest {
assertEquals(2, s.getNLower());
assertEquals(0, s.getNUpper());
assertEquals(3, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
@@ -101,7 +97,6 @@ class SlotTest {
assertEquals(1, s.getNLower());
assertEquals(1, s.getNUpper());
assertEquals(0, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
@@ -115,7 +110,6 @@ class SlotTest {
assertEquals(0, s.getNLower());
assertEquals(2, s.getNUpper());
assertEquals(0, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
@@ -129,7 +123,6 @@ class SlotTest {
assertEquals(1, s.getNLower());
assertEquals(2, s.getNUpper());
assertEquals(4, s.getNMinPlayer());
- System.out.println(s);
assertEquals("SlotID: "+slotID+"\nNUpper: "+s.getNUpper()+"\nNLower: "+s.getNLower()+"\nFood: "+s.getFood()+"\n", s.toString());
}
}
\ No newline at end of file