Merge branch 'main' into javadoc-fixes
This commit is contained in:
@@ -1,53 +1,85 @@
|
|||||||
package it.polimi.ingsw.gc14;
|
package it.polimi.ingsw.gc14;
|
||||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||||
|
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ClientLauncherTUI {
|
public class ClientLauncherTUI {
|
||||||
//TODO Javadoc
|
//TODO Javadoc
|
||||||
public void main() throws InterruptedException {
|
public void main() throws InterruptedException {
|
||||||
ClientController controller = new ClientController();
|
TUI view=new TUI(null);
|
||||||
|
ClientController controller = new ClientController(view);
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
System.out.println("Selezionare nome utente: ");
|
System.out.println("Selezionare nome utente: ");
|
||||||
String username = scanner.next();
|
String username = scanner.next();
|
||||||
System.out.println(username);
|
|
||||||
|
|
||||||
System.out.println("Selezionare numero di giocatori desiderato: ");
|
System.out.println("Selezionare numero di giocatori desiderato: ");
|
||||||
int proposedNumPlayers = scanner.nextInt();
|
int proposedNumPlayers = scanner.nextInt();
|
||||||
System.out.println(proposedNumPlayers);
|
|
||||||
|
|
||||||
System.out.println("Selezionare RMI[0] o TCP[1]: ");
|
System.out.println("Selezionare RMI[0] o TCP[1]: ");
|
||||||
int networkType = scanner.nextInt();
|
int networkType = scanner.nextInt();
|
||||||
System.out.println(networkType);
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
|
|
||||||
|
// RMI
|
||||||
if (networkType == 0) {
|
if (networkType == 0) {
|
||||||
RMIClient client = new RMIClient("localhost", 1099);
|
// Connect
|
||||||
if (client.connect(username, proposedNumPlayers, controller)) {
|
RMIClient client = new RMIClient(controller, "localhost", 1099);
|
||||||
|
if (client.connect(username, proposedNumPlayers)) {
|
||||||
System.out.println("Succesfully connected to RMI server\n\n");
|
System.out.println("Succesfully connected to RMI server\n\n");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("RMI connection refused\n\n");
|
System.out.println("RMI connection refused\n\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
controller.setClient(client);
|
||||||
|
|
||||||
|
// Play
|
||||||
|
//while(controller.localController.getModel()==null){
|
||||||
|
// scanner.nextInt();
|
||||||
|
//}
|
||||||
while(true) {
|
while(true) {
|
||||||
System.out.flush();
|
getInput(scanner, controller, username);
|
||||||
if (controller.localModel!=null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Thread.sleep(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Model set\n\n");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TCP
|
||||||
} else if (networkType == 1) {
|
} else if (networkType == 1) {
|
||||||
return;
|
// Connect
|
||||||
|
TCPClient client = new TCPClient(controller, "localhost", 8080);
|
||||||
|
if (client.connect(username, proposedNumPlayers)) {
|
||||||
|
System.out.println("Succesfully connected to TCP server\n\n");
|
||||||
|
} else {
|
||||||
|
System.out.println("TCP connection refused\n\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller.setClient(client);
|
||||||
|
|
||||||
|
// Play
|
||||||
|
while(true) {
|
||||||
|
getInput(scanner, controller, username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void getInput(Scanner scanner, ClientController controller, String username) {
|
||||||
|
int action = scanner.nextInt();
|
||||||
|
int pos = scanner.nextInt();
|
||||||
|
|
||||||
|
switch(action) {
|
||||||
|
case 1 -> controller.drawLowerBuildingCard(username, pos);
|
||||||
|
case 2 -> controller.drawLowerTribeCard(username, pos);
|
||||||
|
case 3 -> controller.drawUpperBuildingCard(username, pos);
|
||||||
|
case 4 -> controller.drawUpperTribeCard(username, pos);
|
||||||
|
case 5 -> controller.pickOptionalBuildingCard(username, pos);
|
||||||
|
case 6 -> controller.slotChoice(username, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,119 @@
|
|||||||
package it.polimi.ingsw.gc14.Controller;
|
package it.polimi.ingsw.gc14.Controller;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
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.Network.Observer;
|
||||||
import it.polimi.ingsw.gc14.View.IView;
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
|
|
||||||
//TODO Javadoc
|
//TODO Javadoc
|
||||||
public class ClientController {
|
public class ClientController {
|
||||||
//TODO Javadoc
|
|
||||||
public Game localModel;
|
|
||||||
|
|
||||||
//TODO Javadoc
|
|
||||||
public GameController localController;
|
public GameController localController;
|
||||||
|
|
||||||
//TODO Javadoc
|
//TODO Javadoc
|
||||||
public IView view=null;
|
public IView view=null;
|
||||||
|
private IClient client;
|
||||||
|
|
||||||
//TODO Javadoc
|
public ClientController(IView view) {
|
||||||
public ClientController(IView view,Game localModel) {
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.localModel = localModel;
|
this.localController = new GameController();
|
||||||
this.localController = new GameController(localModel);
|
|
||||||
}
|
}
|
||||||
|
public void setClient(IClient client) {
|
||||||
//TODO Javadoc
|
this.client = client;
|
||||||
public ClientController() {
|
|
||||||
this.localController = new GameController(localModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(Game model) {
|
public void setModel(Game model) {
|
||||||
this.localModel = model;
|
|
||||||
localController.setModel(model);
|
localController.setModel(model);
|
||||||
// localModel.addObserver((Observer) view); // registra la view come observer
|
view.update(localController.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Javadoc
|
|
||||||
public void onError(String message) {
|
public void onError(String message) {
|
||||||
view.showError(message);
|
view.showError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to draw an upper tribe card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the upper tribe card to draw.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the draw operation fails.
|
||||||
|
*/
|
||||||
|
public void drawUpperTribeCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to draw a lower tribe card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the lower tribe card to draw.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the draw operation fails.
|
||||||
|
*/
|
||||||
|
public void drawLowerTribeCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new DrawLowerTribeCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to draw an upper building card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the upper building card to draw.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the draw operation fails.
|
||||||
|
*/
|
||||||
|
public void drawUpperBuildingCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to draw a lower building card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the lower building card to draw.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the draw operation fails.
|
||||||
|
*/
|
||||||
|
public void drawLowerBuildingCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to pick an optional tribe card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the optional tribe card to pick.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the pick operation fails.
|
||||||
|
*/
|
||||||
|
public void pickOptionalTribeCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to pick an optional building card for the specified player from the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the optional building card to pick.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the pick operation fails.
|
||||||
|
*/
|
||||||
|
public void pickOptionalBuildingCard(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to perform the slot choice action for the specified player at the specified position.
|
||||||
|
*
|
||||||
|
* @param playerUsername the username of the player performing the action.
|
||||||
|
* @param pos the position of the chosen slot.
|
||||||
|
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
|
||||||
|
* or if the slot choice operation fails.
|
||||||
|
*/
|
||||||
|
public void slotChoice(String playerUsername,int pos) {
|
||||||
|
client.doEvent(new SlotChoice(playerUsername,pos));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,8 +169,9 @@ public class Game implements Serializable {
|
|||||||
* @throws IllegalArgumentException if {@code nPlayers < 0} or {@code nPlayers > 5}.
|
* @throws IllegalArgumentException if {@code nPlayers < 0} or {@code nPlayers > 5}.
|
||||||
*/
|
*/
|
||||||
public Game(int nPlayers) throws IllegalArgumentException{
|
public Game(int nPlayers) throws IllegalArgumentException{
|
||||||
if(nPlayers < 0||nPlayers > 5)
|
if(nPlayers !=0 && (nPlayers < 2 || nPlayers > 5)) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
this.nPlayers = nPlayers;
|
this.nPlayers = nPlayers;
|
||||||
board=new Board(nPlayers);
|
board=new Board(nPlayers);
|
||||||
slotMap = new LinkedHashMap<>();
|
slotMap = new LinkedHashMap<>();
|
||||||
@@ -312,10 +313,9 @@ public class Game implements Serializable {
|
|||||||
tempCard.insert(player);
|
tempCard.insert(player);
|
||||||
board.removeUpperTribeCard(tempCard);
|
board.removeUpperTribeCard(tempCard);
|
||||||
currentState.UpperDrawn();
|
currentState.UpperDrawn();
|
||||||
if(currentState.getNUpper() ==0 && currentState.getNLower() ==0)
|
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -354,7 +354,7 @@ public class Game implements Serializable {
|
|||||||
tempCard.insert(player);
|
tempCard.insert(player);
|
||||||
board.removeLowerTribeCard(tempCard);
|
board.removeLowerTribeCard(tempCard);
|
||||||
currentState.LowerDrawn();
|
currentState.LowerDrawn();
|
||||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ public class Game implements Serializable {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -433,7 +433,7 @@ public class Game implements Serializable {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
if(currentState.getNLower() ==0 && currentState.getNUpper() ==0)
|
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0)))
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -509,8 +509,8 @@ public class Game implements Serializable {
|
|||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nextPlayerSetup();
|
|
||||||
OptionalCardQueue.removeIf(x->x.equals(player));
|
OptionalCardQueue.removeIf(x->x.equals(player));
|
||||||
|
nextPlayerSetup();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,10 +566,16 @@ public class Game implements Serializable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
||||||
for (Map.Entry<Slot,Player> s : slotMap.entrySet()) {
|
for (Slot s : slotMap.keySet()) {
|
||||||
if (s.getValue()!=null) {
|
if (slotMap.get(s) != null) {
|
||||||
currentState.PlayerUpdate(s.getValue(), s.getKey());
|
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||||
return;
|
if(!((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0))))
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||||
|
slotMap.put(currentState.getSlot(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -581,7 +587,15 @@ public class Game implements Serializable {
|
|||||||
for (Slot s : slotMap.keySet()) {
|
for (Slot s : slotMap.keySet()) {
|
||||||
if (slotMap.get(s) != null) {
|
if (slotMap.get(s) != null) {
|
||||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||||
break;
|
if((currentState.getNLower() ==0 ||( getLowerListTribeCards().size()==0 && getLowerListBuilding().size()==0)) && ((currentState.getNUpper() ==0)||( getUpperListTribeCards().size()==0 && getUpperListBuilding().size()==0))) {
|
||||||
|
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||||
|
|
||||||
|
slotMap.put(currentState.getSlot(), null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(slotMap.values().stream().allMatch(v -> v == null))
|
if(slotMap.values().stream().allMatch(v -> v == null))
|
||||||
@@ -600,31 +614,51 @@ public class Game implements Serializable {
|
|||||||
{
|
{
|
||||||
OptionalCardQueue.add(e.getKey());
|
OptionalCardQueue.add(e.getKey());
|
||||||
}
|
}
|
||||||
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
|
Player optionalPlayer = OptionalCardQueue.poll();
|
||||||
if(currentState.getCurrentPlayer()==null)
|
|
||||||
{
|
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
|
||||||
if(currentState.getRound()<10)
|
|
||||||
{
|
|
||||||
nextRound();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EventResolution();
|
|
||||||
currentState.GameStageUpdate(GameStages.ENDING);
|
|
||||||
endGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (optionalPlayer != null) {
|
||||||
|
currentState.PlayerUpdate(optionalPlayer, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if(GameStages.OPTIONAL_CARD_EFFECT==currentState.getGameStage()) {
|
|
||||||
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
|
|
||||||
if(currentState.getCurrentPlayer()==null)
|
|
||||||
{
|
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||||
|
|
||||||
|
if (currentState.getRound() < 10) {
|
||||||
|
nextRound();
|
||||||
|
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||||
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
|
} else {
|
||||||
|
EventResolution();
|
||||||
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
|
endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
|
||||||
|
Player optionalPlayer = OptionalCardQueue.poll();
|
||||||
|
|
||||||
|
if (optionalPlayer != null) {
|
||||||
|
currentState.PlayerUpdate(optionalPlayer, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||||
|
|
||||||
|
if (currentState.getRound() < 10) {
|
||||||
|
nextRound();
|
||||||
|
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||||
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
|
} else {
|
||||||
|
EventResolution();
|
||||||
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
|
endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,9 +703,13 @@ public class Game implements Serializable {
|
|||||||
{
|
{
|
||||||
currentState.GameStageUpdate(GameStages.ENDING);
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
endGame();
|
endGame();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(currentState.getEra()!= board.nextRound())
|
|
||||||
|
if(currentState.getEra()!= board.nextRound()) {
|
||||||
currentState.EraUpdate();
|
currentState.EraUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
currentState.RoundUpdate();
|
currentState.RoundUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -695,11 +733,28 @@ public class Game implements Serializable {
|
|||||||
* @param nPlayers the new configured number of players.
|
* @param nPlayers the new configured number of players.
|
||||||
* @return {@code true} if the number of players is updated, {@code false} otherwise.
|
* @return {@code true} if the number of players is updated, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean setNPlayer(int nPlayers)
|
public boolean setNPlayer(int nPlayers) {
|
||||||
{
|
if (this.nPlayers != 0) {
|
||||||
if(this.nPlayers!=0)
|
|
||||||
return false;
|
return false;
|
||||||
this.nPlayers=nPlayers;
|
}
|
||||||
|
|
||||||
|
if (nPlayers < 2 || nPlayers > 5) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nPlayers = nPlayers;
|
||||||
|
|
||||||
|
board = new Board(nPlayers);
|
||||||
|
|
||||||
|
slotMap = new LinkedHashMap<>();
|
||||||
|
for (Slot s : board.getSlotList()) {
|
||||||
|
slotMap.put(s, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentState = new CurrentState();
|
||||||
|
playersList = new ArrayList<>();
|
||||||
|
OptionalCardQueue = new LinkedList<>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,88 +770,76 @@ public class Game implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
var table = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
|
return PlayersStamp()+"\n"+BoardStamp()+"\n";
|
||||||
List<String> stringUp=new ArrayList<>();
|
}
|
||||||
List<String> stringEmpty=new ArrayList<>();
|
public String PlayersStamp()
|
||||||
List<String> stringDown=new ArrayList<>();
|
{
|
||||||
|
StringBuilder stringBuilder=new StringBuilder();
|
||||||
|
for(int i=0;i<playersList.size()/2;i++)
|
||||||
|
{
|
||||||
|
stringBuilder.append(AsciiTable.sideBySide(List.of(playersList.get((i*2)).toString().split("\n")),List.of(playersList.get((i*2+1)).toString().split("\n")),2));
|
||||||
|
}
|
||||||
|
stringBuilder.append("\n");
|
||||||
|
if(playersList.size()%2!=0)
|
||||||
|
{
|
||||||
|
stringBuilder.append(playersList.get(playersList.size()-1).toString());
|
||||||
|
stringBuilder.append("\n");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
public String BoardStamp()
|
||||||
|
{
|
||||||
|
var offerTrack = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
|
||||||
|
List<String> stringUpOffer=new ArrayList<>();
|
||||||
|
List<String> stringDownOffer=new ArrayList<>();
|
||||||
|
|
||||||
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
|
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
|
||||||
{
|
{
|
||||||
stringEmpty.add(" ");
|
stringDownOffer.add(entry.getKey().toStringTUI());
|
||||||
stringDown.add(entry.getKey().toStringTUI());
|
|
||||||
if(entry.getValue()!=null)
|
if(entry.getValue()!=null)
|
||||||
stringUp.add(entry.getValue().getUserName());
|
stringUpOffer.add(entry.getValue().getUserName());
|
||||||
else
|
else
|
||||||
stringUp.add(" ");
|
stringUpOffer.add(" ");
|
||||||
}
|
}
|
||||||
table.addRow(stringUp);
|
|
||||||
table.addRow(stringEmpty);
|
|
||||||
table.addRow(stringDown);
|
|
||||||
|
|
||||||
List<String>lines=List.of(orderLogicCard.toString().split("\n"));
|
var TribeTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
|
||||||
List<String> lines2=new ArrayList<>();
|
var TribeTableLower = new AsciiTable(BorderStyle.UNICODE,1);
|
||||||
lines2.add("OFFER TRACK");
|
|
||||||
lines2.addAll(List.of(table.build().split("\n")));
|
|
||||||
|
|
||||||
String boardToString=AsciiTable.sideBySide(lines,lines2,1);
|
List<String> stringUpperListTribe=new ArrayList<>();
|
||||||
|
List<String> stringLowerListTribe=new ArrayList<>();
|
||||||
|
stringUpperListTribe.add("Char/Events");
|
||||||
|
stringLowerListTribe.add("Char/Events");
|
||||||
var table2 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size()));
|
|
||||||
List<String> stringUp2=new ArrayList<>();
|
|
||||||
List<String> stringDown2=new ArrayList<>();
|
|
||||||
for(int i=0;i<Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size());i++)
|
for(int i=0;i<Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size());i++)
|
||||||
{
|
{
|
||||||
if(i<getUpperListTribeCards().size())
|
if(i<getUpperListTribeCards().size())
|
||||||
{
|
{
|
||||||
stringUp2.add(getUpperListTribeCards().get(i).toStringBoard());
|
stringUpperListTribe.add(getUpperListTribeCards().get(i).toStringBoard());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stringUp2.add("");
|
|
||||||
}
|
}
|
||||||
if(i<getLowerListTribeCards().size())
|
if(i<getLowerListTribeCards().size())
|
||||||
{
|
{
|
||||||
stringDown2.add(getLowerListTribeCards().get(i).toStringBoard());
|
stringLowerListTribe.add(getLowerListTribeCards().get(i).toStringBoard());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stringDown2.add("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table2.addRow(stringUp2);
|
var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
|
||||||
table2.addRow(stringDown2);
|
BuildTableUpper.addHeader("Building ");
|
||||||
|
var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1);
|
||||||
|
BuildTableLower.addHeader("Building ");
|
||||||
|
|
||||||
var table3 = new AsciiTable(BorderStyle.UNICODE, Math.max(getUpperListBuilding().size(),getLowerListBuilding().size()));
|
|
||||||
List<String> stringUp3=new ArrayList<>();
|
|
||||||
List<String> stringDown3=new ArrayList<>();
|
|
||||||
for(int i=0;i<Math.max(getUpperListBuilding().size(),getLowerListBuilding().size());i++)
|
for(int i=0;i<Math.max(getUpperListBuilding().size(),getLowerListBuilding().size());i++)
|
||||||
{
|
{
|
||||||
if(i<getUpperListBuilding().size())
|
if(i<getUpperListBuilding().size())
|
||||||
{
|
{
|
||||||
stringUp3.add(getUpperListBuilding().get(i).toString());
|
BuildTableUpper.addRow(getUpperListBuilding().get(i).toString());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stringUp3.add("-");
|
|
||||||
}
|
}
|
||||||
if(i<getLowerListBuilding().size())
|
if(i<getLowerListBuilding().size())
|
||||||
{
|
{
|
||||||
stringDown3.add(getLowerListBuilding().get(i).toString());
|
BuildTableLower.addRow(getLowerListBuilding().get(i).toString());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stringDown3.add("-");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table3.addRow(stringUp3);
|
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));
|
||||||
table3.addRow(stringDown3);
|
stringLowerListTribe.forEach(x->TribeTableLower.addRow(x));
|
||||||
|
offerTrack.addRow(stringUpOffer);
|
||||||
String PlayerToString ="";
|
offerTrack.addRow(stringDownOffer);
|
||||||
for(Player p:playersList)
|
return "CURRENT STATE\n"+getCurrentState()+"\n"+orderLogicCard.toString()+"\n"+ AsciiTable.sideBySide(Arrays.stream((TribeTableUpper.build().split("\n"))).toList(), Arrays.stream(BuildTableUpper.build().split("\n")).toList(),2)+"\n"+offerTrack.build()+"\n"+AsciiTable.sideBySide(List.of(TribeTableLower.build().split("\n")), Arrays.stream(BuildTableLower.build().split("\n")).toList(),2);
|
||||||
{
|
|
||||||
PlayerToString+=p.toString()+"\n";
|
|
||||||
}
|
|
||||||
return PlayerToString+"\n"+ boardToString +"UPPERList\\LOWERList\n"+table2.build() + "\nBUILDING\n"+table3.build() + "\n";
|
|
||||||
//return s.toString()+"\n"++"\nOFFER TRACK\n"+ table.build()+"\n" ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
|
|||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
import it.polimi.ingsw.gc14.Model.Slot;
|
import it.polimi.ingsw.gc14.Model.Slot;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
|
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
|
||||||
|
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the current state of the game.
|
* Represents the current state of the game.
|
||||||
@@ -194,5 +199,27 @@ public class CurrentState implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
var table= new AsciiTable(BorderStyle.UNICODE,6);
|
||||||
|
List<String>header= new ArrayList<>();
|
||||||
|
header.add("Player");
|
||||||
|
header.add("NUpper");
|
||||||
|
header.add("NLower");
|
||||||
|
header.add("Round");
|
||||||
|
header.add("Era");
|
||||||
|
header.add("GameStage");
|
||||||
|
table.addRow(header);
|
||||||
|
table.addSeparator();
|
||||||
|
List<String>values= new ArrayList<>();
|
||||||
|
values.add(player.getUserName());
|
||||||
|
values.add(Integer.toString(NUpper));
|
||||||
|
values.add(Integer.toString(NLower));
|
||||||
|
values.add(Integer.toString(round));
|
||||||
|
values.add(Integer.toString(Era));
|
||||||
|
values.add(GameStage.toString());
|
||||||
|
table.addRow(values);
|
||||||
|
return table.build();
|
||||||
|
}
|
||||||
// endregion functions
|
// endregion functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package it.polimi.ingsw.gc14.Model.Orders;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for all order {@code logic cards}.
|
* Abstract base class for all order {@code logic cards}.
|
||||||
* An {@code OrderLogicCard} manages a queue of {@code players} and defines the effects
|
* An {@code OrderLogicCard} manages a queue of {@code players} and defines the effects
|
||||||
* applied when they are pushed back into the queue.
|
* applied when they are pushed back into the queue.
|
||||||
* @see it.polimi.ingsw.gc14.Model.Player Player
|
* @see it.polimi.ingsw.gc14.Model.Player Player
|
||||||
*/
|
*/
|
||||||
public class OrderPlayer{
|
public class OrderPlayer implements Serializable {
|
||||||
public Player player;
|
public Player player;
|
||||||
public boolean played;
|
public boolean played;
|
||||||
public OrderPlayer(Player player,boolean played){
|
public OrderPlayer(Player player,boolean played){
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network;
|
||||||
|
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
|
||||||
|
public interface IClient {
|
||||||
|
public boolean connect(String username,int preferredInt);
|
||||||
|
public void doEvent(NetworkEvent event) ;
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
@Override
|
@Override
|
||||||
public void onGameInit(Game model) throws RemoteException {
|
public void onGameInit(Game model) throws RemoteException {
|
||||||
clientController.setModel(model);
|
clientController.setModel(model);
|
||||||
|
clientController.view.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
System.out.println(event.toString());
|
System.out.println(event.toString());
|
||||||
} else {
|
} else {
|
||||||
event.apply(clientController.localController);
|
event.apply(clientController.localController);
|
||||||
//clientController.view.update(); TODO
|
clientController.view.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.rmi.registry.LocateRegistry;
|
|||||||
import java.rmi.registry.Registry;
|
import java.rmi.registry.Registry;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
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.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
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.Common.IGameServer;
|
||||||
@@ -11,7 +12,7 @@ import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
|||||||
/**
|
/**
|
||||||
* Client RMI. Uses the methods exposed by the server RMI.
|
* Client RMI. Uses the methods exposed by the server RMI.
|
||||||
*/
|
*/
|
||||||
public class RMIClient {
|
public class RMIClient implements IClient {
|
||||||
|
|
||||||
/** The host address of the RMI server */
|
/** The host address of the RMI server */
|
||||||
private final String host;
|
private final String host;
|
||||||
@@ -22,13 +23,18 @@ public class RMIClient {
|
|||||||
/** The remote stub used to call methods on the server */
|
/** The remote stub used to call methods on the server */
|
||||||
private IGameServer stub;
|
private IGameServer stub;
|
||||||
|
|
||||||
|
/** Client game's controller */
|
||||||
|
ClientController controller;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor.
|
* Class constructor.
|
||||||
|
* @param controller the client controller used to create the callback
|
||||||
* @param host the host address of the RMI server
|
* @param host the host address of the RMI server
|
||||||
* @param port the port of the RMI server
|
* @param port the port of the RMI server
|
||||||
*/
|
*/
|
||||||
public RMIClient(String host, int port) {
|
public RMIClient(ClientController controller, String host, int port) {
|
||||||
|
this.controller=controller;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
@@ -40,14 +46,13 @@ public class RMIClient {
|
|||||||
* Then, creates a {@link ClientCallbackImpl} and calls {@link RMIServer#joinGame(String, int, IClientCallback)}.
|
* Then, creates a {@link ClientCallbackImpl} and calls {@link RMIServer#joinGame(String, int, IClientCallback)}.
|
||||||
* @param username the player's username
|
* @param username the player's username
|
||||||
* @param preferredInt the desired number of players
|
* @param preferredInt the desired number of players
|
||||||
* @param clientController the client controller used to create the callback
|
|
||||||
* @return true if the player successfully joined the game, false otherwise
|
* @return true if the player successfully joined the game, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean connect(String username,int preferredInt, ClientController clientController) {
|
public boolean connect(String username,int preferredInt) {
|
||||||
try {
|
try {
|
||||||
Registry registry = LocateRegistry.getRegistry(host, port);
|
Registry registry = LocateRegistry.getRegistry(host, port);
|
||||||
this.stub = (IGameServer) registry.lookup("RMIGameServer");
|
this.stub = (IGameServer) registry.lookup("RMIGameServer");
|
||||||
ClientCallbackImpl callback = new ClientCallbackImpl(clientController);
|
ClientCallbackImpl callback = new ClientCallbackImpl(controller);
|
||||||
|
|
||||||
return stub.joinGame(username, preferredInt, callback);
|
return stub.joinGame(username, preferredInt, callback);
|
||||||
}
|
}
|
||||||
@@ -63,8 +68,12 @@ public class RMIClient {
|
|||||||
* @param event the event to send
|
* @param event the event to send
|
||||||
* @throws RemoteException if any RMI error occurs
|
* @throws RemoteException if any RMI error occurs
|
||||||
*/
|
*/
|
||||||
public void doEvent(NetworkEvent event) throws RemoteException {
|
public void doEvent(NetworkEvent event) {
|
||||||
stub.doEvent(event);
|
try {
|
||||||
|
stub.doEvent(event);
|
||||||
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package it.polimi.ingsw.gc14.Network.TCP.Client;
|
package it.polimi.ingsw.gc14.Network.TCP.Client;
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
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.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ import java.net.*;
|
|||||||
/**
|
/**
|
||||||
* Client TCP. Sends and receives messages with the TCP server.
|
* Client TCP. Sends and receives messages with the TCP server.
|
||||||
*/
|
*/
|
||||||
public class TCPClient {
|
public class TCPClient implements IClient {
|
||||||
|
|
||||||
/** Socket TCP */
|
/** Socket TCP */
|
||||||
Socket communicationSocket;
|
Socket communicationSocket;
|
||||||
@@ -23,7 +24,7 @@ public class TCPClient {
|
|||||||
ObjectOutputStream socketSend;
|
ObjectOutputStream socketSend;
|
||||||
|
|
||||||
/** Client game's controller */
|
/** Client game's controller */
|
||||||
GameController controller;
|
ClientController controller;
|
||||||
|
|
||||||
/** IP address of the server to connect to */
|
/** IP address of the server to connect to */
|
||||||
String hostname;
|
String hostname;
|
||||||
@@ -38,7 +39,7 @@ public class TCPClient {
|
|||||||
* @param hostname The IP address of the server
|
* @param hostname The IP address of the server
|
||||||
* @param port The TCP port of the server
|
* @param port The TCP port of the server
|
||||||
*/
|
*/
|
||||||
public TCPClient(GameController controller, String hostname, int port) {
|
public TCPClient(ClientController controller, String hostname, int port) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
@@ -53,13 +54,15 @@ public class TCPClient {
|
|||||||
* @param proposedNPlayers The desired number of players for the game
|
* @param proposedNPlayers The desired number of players for the game
|
||||||
* @return true if the connection is successful, false otherwise.
|
* @return true if the connection is successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean start(String user, int proposedNPlayers) {
|
public boolean connect(String user, int proposedNPlayers) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
communicationSocket = new Socket(hostname, port);
|
communicationSocket = new Socket(hostname, port);
|
||||||
socketSend = new ObjectOutputStream(communicationSocket.getOutputStream());
|
socketSend = new ObjectOutputStream(communicationSocket.getOutputStream());
|
||||||
socketReceive = new ObjectInputStream(communicationSocket.getInputStream());
|
socketReceive = new ObjectInputStream(communicationSocket.getInputStream());
|
||||||
|
|
||||||
sendEvent(new AddPlayer(user, proposedNPlayers));
|
|
||||||
|
doEvent(new AddPlayer(user, proposedNPlayers));
|
||||||
if (communicationSocket.getInputStream().read() == -1) {
|
if (communicationSocket.getInputStream().read() == -1) {
|
||||||
System.out.println("Could not connect to server");
|
System.out.println("Could not connect to server");
|
||||||
return false;
|
return false;
|
||||||
@@ -89,11 +92,12 @@ public class TCPClient {
|
|||||||
if (event.getIsError()) {
|
if (event.getIsError()) {
|
||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
} else {
|
} else {
|
||||||
event.apply(controller);
|
event.apply(controller.localController);
|
||||||
//clientController.view.update(); TODO
|
controller.view.render();
|
||||||
}
|
}
|
||||||
} else if (read instanceof Game model) {
|
} else if (read instanceof Game model) {
|
||||||
controller.setModel(model);
|
controller.setModel(model);
|
||||||
|
controller.view.render();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -108,7 +112,7 @@ public class TCPClient {
|
|||||||
* Sends a {@link NetworkEvent} to the server.
|
* Sends a {@link NetworkEvent} to the server.
|
||||||
* @param event The NetworkEvent to send.
|
* @param event The NetworkEvent to send.
|
||||||
*/
|
*/
|
||||||
private void sendEvent(NetworkEvent event) {
|
public void doEvent(NetworkEvent event) {
|
||||||
try {
|
try {
|
||||||
socketSend.writeObject(event);
|
socketSend.writeObject(event);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ public class ClientHandler implements Runnable {
|
|||||||
* @param clientHandlers The shared list of all active client handlers
|
* @param clientHandlers The shared list of all active client handlers
|
||||||
* @param actionQueue The queue containing incoming events
|
* @param actionQueue The queue containing incoming events
|
||||||
*/
|
*/
|
||||||
public ClientHandler(Socket clientSocket, List<ClientHandler> clientHandlers, BlockingQueue<NetworkEvent> actionQueue) {
|
public ClientHandler(Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List<ClientHandler> clientHandlers, BlockingQueue<NetworkEvent> actionQueue) {
|
||||||
this.clientSocket = clientSocket;
|
this.clientSocket = clientSocket;
|
||||||
|
this.in = in;
|
||||||
|
this.out = out;
|
||||||
this.clientHandlers = clientHandlers;
|
this.clientHandlers = clientHandlers;
|
||||||
this.actionQueue = actionQueue;
|
this.actionQueue = actionQueue;
|
||||||
}
|
}
|
||||||
@@ -55,8 +57,7 @@ public class ClientHandler implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
in = new ObjectInputStream(clientSocket.getInputStream());
|
|
||||||
out = new ObjectOutputStream(clientSocket.getOutputStream());
|
|
||||||
while (true) {
|
while (true) {
|
||||||
NetworkEvent event = (NetworkEvent) in.readObject();
|
NetworkEvent event = (NetworkEvent) in.readObject();
|
||||||
if (!actionQueue.add(event)) {
|
if (!actionQueue.add(event)) {
|
||||||
@@ -76,15 +77,13 @@ public class ClientHandler implements Runnable {
|
|||||||
* Sends a {@link NetworkEvent} to the client.
|
* Sends a {@link NetworkEvent} to the client.
|
||||||
* @param event The network event to send to the client.
|
* @param event The network event to send to the client.
|
||||||
*/
|
*/
|
||||||
public void notifyEvent(NetworkEvent event) {
|
public synchronized void notifyEvent(NetworkEvent event) {
|
||||||
synchronized (out) {
|
try {
|
||||||
try {
|
out.writeObject(event);
|
||||||
out = new ObjectOutputStream(clientSocket.getOutputStream());
|
} catch (IOException e) {
|
||||||
out.writeObject(event);
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -92,14 +91,11 @@ public class ClientHandler implements Runnable {
|
|||||||
* Sends the current game model to this client.
|
* Sends the current game model to this client.
|
||||||
* @param game The current state of the game to send to the client.
|
* @param game The current state of the game to send to the client.
|
||||||
*/
|
*/
|
||||||
public void notifyModel(Game game) {
|
public synchronized void notifyModel(Game game) {
|
||||||
synchronized (out) {
|
try {
|
||||||
try {
|
out.writeObject(game);
|
||||||
out = new ObjectOutputStream(clientSocket.getOutputStream());
|
} catch (IOException e) {
|
||||||
out.writeObject(game);
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,8 +88,9 @@ public class TCPServer {
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
clientSocket = socketTCP.accept();
|
clientSocket = socketTCP.accept();
|
||||||
ObjectInputStream clientSocketObj = new ObjectInputStream(clientSocket.getInputStream());
|
ObjectOutputStream clientSend = new ObjectOutputStream(clientSocket.getOutputStream());
|
||||||
NetworkEvent event = (NetworkEvent) clientSocketObj.readObject();
|
ObjectInputStream clientReceive = new ObjectInputStream(clientSocket.getInputStream());
|
||||||
|
NetworkEvent event = (NetworkEvent) clientReceive.readObject();
|
||||||
|
|
||||||
if(!(event.getEventType() == EventType.ADD_PLAYER)){
|
if(!(event.getEventType() == EventType.ADD_PLAYER)){
|
||||||
clientSocket.getOutputStream().write((int)(-1));
|
clientSocket.getOutputStream().write((int)(-1));
|
||||||
@@ -114,7 +115,7 @@ public class TCPServer {
|
|||||||
clientSocket.getOutputStream().write((int) (1));
|
clientSocket.getOutputStream().write((int) (1));
|
||||||
|
|
||||||
System.out.println("Accepted player: " + eventAddPlayer.getUsername());
|
System.out.println("Accepted player: " + eventAddPlayer.getUsername());
|
||||||
ClientHandler clientHandler = new ClientHandler(clientSocket, clientHandlers, actionQueue);
|
ClientHandler clientHandler = new ClientHandler(clientSocket, clientSend, clientReceive, clientHandlers, actionQueue);
|
||||||
clientHandlers.add(clientHandler);
|
clientHandlers.add(clientHandler);
|
||||||
ConnectedPlayers++;
|
ConnectedPlayers++;
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import it.polimi.ingsw.gc14.Model.Game;
|
|||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
|
||||||
public interface IView {
|
public interface IView {
|
||||||
|
public void update(Game game);
|
||||||
void render(Game model);
|
public void render();
|
||||||
void showMessage(String message);
|
public void showMessage(String message);
|
||||||
void showError(String message);
|
public void showError(String message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class AsciiTable {
|
|||||||
|
|
||||||
//TODO javadoc
|
//TODO javadoc
|
||||||
public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); }
|
public void addHeader(String... cells) { rows.add(0, Arrays.asList(cells)); separators.add(0); }
|
||||||
|
public void addSeparator() { separators.add(rows.size()-1); }
|
||||||
|
|
||||||
//TODO javadoc
|
//TODO javadoc
|
||||||
public void addSeparator() { separators.add(rows.size()-1); }
|
public void addSeparator() { separators.add(rows.size()-1); }
|
||||||
|
|||||||
@@ -1,93 +1,103 @@
|
|||||||
//package it.polimi.ingsw.gc14.View.TUI;
|
package it.polimi.ingsw.gc14.View.TUI;
|
||||||
//import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
//
|
import it.polimi.ingsw.gc14.View.IView;
|
||||||
//public class TUI {
|
|
||||||
//
|
public class TUI implements IView {
|
||||||
// // ── dati di stato ───────────────────────────────────────────
|
|
||||||
// private BorderStyle style = BorderStyle.UNICODE;
|
// ── dati di stato ───────────────────────────────────────────
|
||||||
// private Game model;
|
private BorderStyle style = BorderStyle.UNICODE;
|
||||||
// // ── punto di ingresso ───────────────────────────────────────
|
private Game model;
|
||||||
// public String render() {
|
private String username;
|
||||||
// var sb = new StringBuilder();
|
public TUI(Game model) {
|
||||||
// sb.append(renderHeader());
|
this.model = model;
|
||||||
// sb.append(renderTurnOrder());
|
this.username="";
|
||||||
// sb.append(renderOfferTrack());
|
}
|
||||||
// sb.append(renderCardRows());
|
public void setUsername(String username) {
|
||||||
// sb.append(renderTableaux());
|
this.username = username;
|
||||||
// sb.append(renderFooter());
|
}
|
||||||
// return sb.toString();
|
|
||||||
// }
|
@Override
|
||||||
//
|
public void update(Game model) {
|
||||||
// // ── sezioni ─────────────────────────────────────────────────
|
this.model = model;
|
||||||
// private String renderTurnOrder() {
|
}
|
||||||
// var table = new AsciiTable(style, 4, 10); // 4 colonne, largh 10
|
|
||||||
// table.addRow(model.getPlayers().stream()
|
// ── punto di ingresso ───────────────────────────────────────
|
||||||
// .map(p -> + ". " + p.getUserName())
|
public void render()
|
||||||
// .toList());
|
{
|
||||||
// table.addRow(state.getPlayers().stream()
|
try{
|
||||||
// .map(p -> p.getTotemPosition() != null
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
// ? "totem: " + p.getTotemPosition()
|
ProcessBuilder pb;
|
||||||
// : "(da piaz)")
|
if (os.contains("win")) {
|
||||||
// .toList());
|
pb = new ProcessBuilder("cmd", "/c", "cls");
|
||||||
// return " TURN ORDER\n" + table.build() + "\n";
|
} else {
|
||||||
// }
|
pb = new ProcessBuilder("clear");
|
||||||
//
|
}
|
||||||
// private String renderOfferTrack() {
|
pb.inheritIO().start().waitFor();
|
||||||
// var table = new AsciiTable(style, 5, 14);
|
}
|
||||||
// table.addRow(state.getOfferTiles().stream()
|
catch(Exception e){
|
||||||
// .map(t -> t.getId() + ": " + t.getLabel()).toList());
|
}
|
||||||
// table.addRow(state.getOfferTiles().stream()
|
System.out.println(model.toString());
|
||||||
// .map(OfferTile::getRowsLabel).toList());
|
}
|
||||||
// table.addRow(state.getOfferTiles().stream()
|
|
||||||
// .map(t -> state.getTotemOnTile(t.getId())).toList());
|
public void renderBoard()
|
||||||
// return " OFFER TRACK\n" + table.build() + "\n";
|
{
|
||||||
// }
|
try{
|
||||||
//
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
// private String renderCardRows() {
|
ProcessBuilder pb;
|
||||||
// int cols = state.getTopRow().size();
|
if (os.contains("win")) {
|
||||||
// var table = new AsciiTable(style, cols, 13);
|
pb = new ProcessBuilder("cmd", "/c", "cls");
|
||||||
// table.addRow(state.getTopRow().stream()
|
} else {
|
||||||
// .map(c -> "[" + c.getTypeLabel() + "]").toList());
|
pb = new ProcessBuilder("clear");
|
||||||
// table.addRow(state.getTopRow().stream()
|
}
|
||||||
// .map(Card::getName).toList());
|
pb.inheritIO().start().waitFor();
|
||||||
// table.addSeparator();
|
}
|
||||||
// table.addRow(state.getBotRow().stream()
|
catch(Exception e){
|
||||||
// .map(c -> "[" + c.getTypeLabel() + "]").toList());
|
}
|
||||||
// table.addRow(state.getBotRow().stream()
|
System.out.println(model.BoardStamp());
|
||||||
// .map(Card::getName).toList());
|
}
|
||||||
// return " CARTE IN GIOCO\n" + prefix("TOP ", "BOT ", table.build()) + "\n";
|
public void renderPlayer()
|
||||||
// }
|
{
|
||||||
//
|
try{
|
||||||
// private String renderTableaux() {
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
// var sb = new StringBuilder(" TABLEAU GIOCATORI\n\n");
|
ProcessBuilder pb;
|
||||||
// for (Player p : state.getPlayers()) {
|
if (os.contains("win")) {
|
||||||
// String marker = p.isActive() ? ">>>" : " ";
|
pb = new ProcessBuilder("cmd", "/c", "cls");
|
||||||
// sb.append(String.format(" %s %s%s Food:%d PP:%d%n",
|
} else {
|
||||||
// marker, p.getName(),
|
pb = new ProcessBuilder("clear");
|
||||||
// p.isActive() ? " [TUO TURNO]" : "",
|
}
|
||||||
// p.getFood(), p.getPP()));
|
pb.inheritIO().start().waitFor();
|
||||||
// sb.append(renderPlayerTableau(p));
|
}
|
||||||
// sb.append("\n");
|
catch(Exception e){
|
||||||
// }
|
}
|
||||||
// return sb.toString();
|
System.out.println(model.BoardStamp());
|
||||||
// }
|
}
|
||||||
//
|
public void renderMyHand()
|
||||||
// private String renderPlayerTableau(Player p) {
|
{
|
||||||
// var table = new AsciiTable(style, 3, 14);
|
try{
|
||||||
// table.addHeader("PERSONAGGI", "EDIFICI", "RISORSE");
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
// int rows = Math.max(p.getChars().size(),
|
ProcessBuilder pb;
|
||||||
// Math.max(p.getBuildings().size(), 3));
|
if (os.contains("win")) {
|
||||||
// for (int i = 0; i < rows; i++) {
|
pb = new ProcessBuilder("cmd", "/c", "cls");
|
||||||
// String ch = i < p.getChars().size() ? p.getChars().get(i) : "";
|
} else {
|
||||||
// String bd = i < p.getBuildings().size() ? p.getBuildings().get(i) : "";
|
pb = new ProcessBuilder("clear");
|
||||||
// String rs = switch (i) {
|
}
|
||||||
// case 0 -> "Food: " + "O".repeat(p.getFood());
|
pb.inheritIO().start().waitFor();
|
||||||
// case 1 -> "PP: " + p.getPP();
|
}
|
||||||
// case 2 -> "Chars:" + p.getChars().size() + " Edif:" + p.getBuildings().size();
|
catch(Exception e){
|
||||||
// default -> "";
|
}
|
||||||
// };
|
System.out.println(model.getPlayerByUsername(username));
|
||||||
// table.addRow(ch, bd, rs);
|
}
|
||||||
// }
|
|
||||||
// return " " + table.build().replace("\n", "\n ");
|
|
||||||
// }
|
public void showMessage(String message)
|
||||||
//}
|
{
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void showError(String message)
|
||||||
|
{
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package it.polimi.ingsw.gc14.Controller;
|
package it.polimi.ingsw.gc14.Controller;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
@@ -14,6 +15,114 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
class GameControllerTest {
|
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"));
|
||||||
|
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Queue<Player> completeSlotChoice(Game game, GameController controller) {
|
||||||
|
Queue<Player> order = new LinkedList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
order.add(current);
|
||||||
|
|
||||||
|
assertTrue(controller.slotChoice(current.getUserName(), i));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstNonEventIndex(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (!cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("No non-event tribe card available.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstEventIndexOrMinusOne(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstNonEventIndexOrMinusOne(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (!cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void giveOptionalEffectToAllPlayers(Game game) {
|
||||||
|
Player first = game.getPlayerByUsername("Giorgio");
|
||||||
|
Player second = game.getPlayerByUsername("Marco");
|
||||||
|
Player third = game.getPlayerByUsername("Luca");
|
||||||
|
|
||||||
|
assertNotNull(first);
|
||||||
|
assertNotNull(second);
|
||||||
|
assertNotNull(third);
|
||||||
|
|
||||||
|
first.buildingCards.add(new BuildingCard(12, 1, 1, 0));
|
||||||
|
second.buildingCards.add(new BuildingCard(12, 1, 1, 0));
|
||||||
|
third.buildingCards.add(new BuildingCard(12, 1, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveActionsUntilOptionalCardEffect(Game game, GameController controller) {
|
||||||
|
int guard = 0;
|
||||||
|
|
||||||
|
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 20) {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addPlayer() {
|
void addPlayer() {
|
||||||
Game game = new Game(3);
|
Game game = new Game(3);
|
||||||
@@ -47,23 +156,15 @@ class GameControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void slotChoice() {
|
void slotChoice() {
|
||||||
Game game = new Game(3);
|
Game game = createStartedGame();
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giorgio"));
|
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
|
||||||
|
|
||||||
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
|
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||||
String other = cur.equals("Giorgio") ? "Marco" : "Giorgio";
|
String other = cur.equals("Giorgio") ? "Marco" : "Giorgio";
|
||||||
|
|
||||||
assertFalse(controller.slotChoice(other, 0));
|
assertFalse(controller.slotChoice(other, 0));
|
||||||
|
|
||||||
Queue<Player> order = new LinkedList<>();
|
Queue<Player> order = completeSlotChoice(game, controller);
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
order.add(p);
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
assertEquals(order.poll(), game.getCurrentState().getCurrentPlayer());
|
assertEquals(order.poll(), game.getCurrentState().getCurrentPlayer());
|
||||||
@@ -71,66 +172,43 @@ class GameControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void drawLowerTribeCard() {
|
void drawLowerTribeCard() {
|
||||||
Game game = new Game(3);
|
Game game = createStartedGame();
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giorgio"));
|
Queue<Player> order = completeSlotChoice(game, controller);
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
|
||||||
|
|
||||||
Queue<Player> order = new LinkedList<>();
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
order.add(p);
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
Player first = order.poll();
|
Player first = order.poll();
|
||||||
assertEquals(first, game.getCurrentState().getCurrentPlayer());
|
assertEquals(first, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
List<TribeCard> cards = game.getLowerListTribeCards();
|
List<TribeCard> cards = game.getLowerListTribeCards();
|
||||||
int idx = cards.indexOf(
|
int idx = firstNonEventIndex(cards);
|
||||||
cards.stream()
|
|
||||||
.filter(c -> !c.IsEventCard())
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow()
|
|
||||||
);
|
|
||||||
|
|
||||||
Player wrongPlayer = order.peek();
|
Player wrongPlayer = order.peek();
|
||||||
assertNotNull(wrongPlayer);
|
assertNotNull(wrongPlayer);
|
||||||
|
|
||||||
|
assertFalse(controller.drawLowerTribeCard(wrongPlayer.getUserName(), idx));
|
||||||
|
|
||||||
int before = first.getTotCharacters();
|
int before = first.getTotCharacters();
|
||||||
|
|
||||||
assertTrue(controller.drawLowerTribeCard(first.getUserName(), idx));
|
assertTrue(controller.drawLowerTribeCard(first.getUserName(), idx));
|
||||||
|
|
||||||
assertEquals(before + 1, first.getTotCharacters());
|
assertEquals(before + 1, first.getTotCharacters());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void drawUpperTribeCard() {
|
void drawUpperTribeCard() {
|
||||||
Game game = new Game(3);
|
Game game = createStartedGame();
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giorgio"));
|
completeSlotChoice(game, controller);
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
|
||||||
|
|
||||||
while (game.getCurrentState().getNUpper() == 0) {
|
while (game.getCurrentState().getNUpper() == 0) {
|
||||||
assertTrue(game.getCurrentState().getNLower() > 0);
|
assertTrue(game.getCurrentState().getNLower() > 0);
|
||||||
|
|
||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
List<TribeCard> lower = game.getLowerListTribeCards();
|
List<TribeCard> lower = game.getLowerListTribeCards();
|
||||||
int lowerIdx = lower.indexOf(
|
int lowerIdx = firstNonEventIndex(lower);
|
||||||
lower.stream()
|
|
||||||
.filter(c -> !c.IsEventCard())
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow()
|
|
||||||
);
|
|
||||||
|
|
||||||
assertTrue(controller.drawLowerTribeCard(current.getUserName(), lowerIdx));
|
assertTrue(controller.drawLowerTribeCard(current.getUserName(), lowerIdx));
|
||||||
}
|
}
|
||||||
@@ -139,12 +217,7 @@ class GameControllerTest {
|
|||||||
int beforeTot = current.getTotCharacters();
|
int beforeTot = current.getTotCharacters();
|
||||||
|
|
||||||
List<TribeCard> upper = game.getUpperListTribeCards();
|
List<TribeCard> upper = game.getUpperListTribeCards();
|
||||||
int upperIdx = upper.indexOf(
|
int upperIdx = firstNonEventIndex(upper);
|
||||||
upper.stream()
|
|
||||||
.filter(c -> !c.IsEventCard())
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow()
|
|
||||||
);
|
|
||||||
|
|
||||||
assertTrue(controller.drawUpperTribeCard(current.getUserName(), upperIdx));
|
assertTrue(controller.drawUpperTribeCard(current.getUserName(), upperIdx));
|
||||||
assertEquals(beforeTot + 1, current.getTotCharacters());
|
assertEquals(beforeTot + 1, current.getTotCharacters());
|
||||||
@@ -152,31 +225,18 @@ class GameControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void drawUpperBuildingCard() {
|
void drawUpperBuildingCard() {
|
||||||
Game game = new Game(3);
|
Game game = createStartedGame();
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giacomo"));
|
completeSlotChoice(game, controller);
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
|
||||||
|
|
||||||
while (game.getCurrentState().getNUpper() == 0) {
|
while (game.getCurrentState().getNUpper() == 0) {
|
||||||
assertTrue(game.getCurrentState().getNLower() > 0);
|
assertTrue(game.getCurrentState().getNLower() > 0);
|
||||||
|
|
||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
List<TribeCard> lower = game.getLowerListTribeCards();
|
List<TribeCard> lower = game.getLowerListTribeCards();
|
||||||
int lowerIdx = lower.indexOf(
|
int lowerIdx = firstNonEventIndex(lower);
|
||||||
lower.stream()
|
|
||||||
.filter(c -> !c.IsEventCard())
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow()
|
|
||||||
);
|
|
||||||
|
|
||||||
assertTrue(controller.drawLowerTribeCard(current.getUserName(), lowerIdx));
|
assertTrue(controller.drawLowerTribeCard(current.getUserName(), lowerIdx));
|
||||||
}
|
}
|
||||||
@@ -186,43 +246,214 @@ class GameControllerTest {
|
|||||||
assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0));
|
assertFalse(controller.drawUpperBuildingCard(current.getUserName(), 0));
|
||||||
|
|
||||||
current.addFood(100);
|
current.addFood(100);
|
||||||
|
int foodBefore = current.getFoodValue();
|
||||||
|
int buildingsBefore = current.buildingCards.size();
|
||||||
|
|
||||||
assertTrue(controller.drawUpperBuildingCard(current.getUserName(), 0));
|
assertTrue(controller.drawUpperBuildingCard(current.getUserName(), 0));
|
||||||
|
|
||||||
|
assertTrue(current.getFoodValue() < foodBefore);
|
||||||
|
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void drawLowerBuildingCard() {
|
void drawingByIndexThroughController() {
|
||||||
Game game = new Game(3);
|
Game game = new Game(3);
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giacomo"));
|
assertTrue(controller.addPlayer("p1"));
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
assertTrue(controller.addPlayer("p2"));
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
assertFalse(controller.addPlayer("p2"));
|
||||||
|
assertTrue(controller.addPlayer("p3"));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
Queue<Player> players = new LinkedList<>();
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
for (int i = 0; i < 3; i++) {
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
players.add(current);
|
||||||
|
|
||||||
|
assertTrue(controller.slotChoice(current.getUserName(), i));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
Player tempPlayer = players.poll();
|
||||||
|
assertNotNull(tempPlayer);
|
||||||
|
assertEquals(tempPlayer, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
|
List<TribeCard> cards = game.getLowerListTribeCards();
|
||||||
|
int index = firstNonEventIndex(cards);
|
||||||
|
|
||||||
|
assertTrue(controller.drawLowerTribeCard(tempPlayer.getUserName(), index));
|
||||||
|
|
||||||
|
tempPlayer = players.poll();
|
||||||
|
assertNotNull(tempPlayer);
|
||||||
|
assertEquals(tempPlayer, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
|
while (game.getCurrentState().getNUpper() > 1) {
|
||||||
|
cards = game.getUpperListTribeCards();
|
||||||
|
|
||||||
|
index = firstNonEventIndexOrMinusOne(cards);
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
|
int before = tempPlayer.getTotCharacters();
|
||||||
assertFalse(controller.drawLowerBuildingCard(cur, 0));
|
|
||||||
|
assertTrue(controller.drawUpperTribeCard(tempPlayer.getUserName(), index));
|
||||||
|
|
||||||
|
assertEquals(before + 1, tempPlayer.getTotCharacters());
|
||||||
|
}
|
||||||
|
|
||||||
|
cards = game.getUpperListTribeCards();
|
||||||
|
|
||||||
|
int eventIndex = firstEventIndexOrMinusOne(cards);
|
||||||
|
|
||||||
|
if (eventIndex != -1) {
|
||||||
|
assertFalse(controller.drawUpperTribeCard(tempPlayer.getUserName(), eventIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
tempPlayer.addFood(100);
|
||||||
|
|
||||||
|
assertFalse(controller.drawUpperBuildingCard(tempPlayer.getUserName(), 999));
|
||||||
|
|
||||||
|
if (!game.getUpperListBuilding().isEmpty() && game.getCurrentState().getNUpper() > 0) {
|
||||||
|
assertTrue(controller.drawUpperBuildingCard(tempPlayer.getUserName(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
cards = game.getUpperListTribeCards();
|
||||||
|
|
||||||
|
int nonEventIndex = firstNonEventIndexOrMinusOne(cards);
|
||||||
|
|
||||||
|
if (nonEventIndex != -1) {
|
||||||
|
assertFalse(controller.drawUpperTribeCard(tempPlayer.getUserName(), nonEventIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pickOptionalCards() {
|
void drawLowerBuildingCardShouldReturnFalseForUnavailableLowerBuildingCard() {
|
||||||
Game game = new Game(3);
|
Game game = createStartedGame();
|
||||||
GameController controller = new GameController(game);
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
assertTrue(controller.addPlayer("Giacomo"));
|
completeSlotChoice(game, controller);
|
||||||
assertTrue(controller.addPlayer("Marco"));
|
|
||||||
assertTrue(controller.addPlayer("Luca"));
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
Player p = game.getCurrentState().getCurrentPlayer();
|
|
||||||
assertTrue(controller.slotChoice(p.getUserName(), i));
|
|
||||||
}
|
|
||||||
|
|
||||||
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
|
assertFalse(controller.drawLowerBuildingCard(current.getUserName(), 0));
|
||||||
assertFalse(controller.pickOptionalTribeCard(cur, 0));
|
}
|
||||||
assertFalse(controller.pickOptionalBuildingCard(cur, 0));
|
|
||||||
|
@Test
|
||||||
|
void pickOptionalCardsShouldReturnFalseOutsideOptionalCardEffectState() {
|
||||||
|
Game game = createStartedGame();
|
||||||
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
|
completeSlotChoice(game, controller);
|
||||||
|
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
String cur = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||||
|
|
||||||
|
assertFalse(controller.pickOptionalTribeCard(cur, 0));
|
||||||
|
assertFalse(controller.pickOptionalBuildingCard(cur, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pickOptionalTribeCardShouldWorkDuringOptionalCardEffectState() {
|
||||||
|
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));
|
||||||
|
|
||||||
|
List<TribeCard> upperCards = game.getUpperListTribeCards();
|
||||||
|
int index = firstNonEventIndex(upperCards);
|
||||||
|
|
||||||
|
int charactersBefore = optionalPlayer.getTotCharacters();
|
||||||
|
|
||||||
|
assertTrue(controller.pickOptionalTribeCard(optionalPlayer.getUserName(), index));
|
||||||
|
|
||||||
|
assertEquals(charactersBefore + 1, optionalPlayer.getTotCharacters());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pickOptionalBuildingCardShouldWorkDuringOptionalCardEffectState() {
|
||||||
|
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));
|
||||||
|
|
||||||
|
assertFalse(game.getUpperListBuilding().isEmpty());
|
||||||
|
|
||||||
|
optionalPlayer.addFood(100);
|
||||||
|
|
||||||
|
int foodBefore = optionalPlayer.getFoodValue();
|
||||||
|
int buildingsBefore = optionalPlayer.buildingCards.size();
|
||||||
|
|
||||||
|
assertTrue(controller.pickOptionalBuildingCard(optionalPlayer.getUserName(), 0));
|
||||||
|
|
||||||
|
assertTrue(optionalPlayer.getFoodValue() < foodBefore);
|
||||||
|
assertEquals(buildingsBefore + 1, optionalPlayer.buildingCards.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addPlayerShouldRejectDuplicateUsername() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
|
assertTrue(controller.addPlayer("Giorgio"));
|
||||||
|
assertFalse(controller.addPlayer("Giorgio"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void drawingMethodsShouldReturnFalseForInvalidIndexes() {
|
||||||
|
Game game = createStartedGame();
|
||||||
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
|
completeSlotChoice(game, controller);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
String username = current.getUserName();
|
||||||
|
|
||||||
|
assertFalse(controller.drawLowerTribeCard(username, -1));
|
||||||
|
assertFalse(controller.drawLowerTribeCard(username, 999));
|
||||||
|
|
||||||
|
assertFalse(controller.drawUpperTribeCard(username, -1));
|
||||||
|
assertFalse(controller.drawUpperTribeCard(username, 999));
|
||||||
|
|
||||||
|
assertFalse(controller.drawLowerBuildingCard(username, -1));
|
||||||
|
assertFalse(controller.drawLowerBuildingCard(username, 999));
|
||||||
|
|
||||||
|
assertFalse(controller.drawUpperBuildingCard(username, -1));
|
||||||
|
assertFalse(controller.drawUpperBuildingCard(username, 999));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void slotChoiceShouldReturnFalseForAlreadyOccupiedSlot() {
|
||||||
|
Game game = createStartedGame();
|
||||||
|
GameController controller = new GameController(game);
|
||||||
|
|
||||||
|
Player first = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertTrue(controller.slotChoice(first.getUserName(), 0));
|
||||||
|
|
||||||
|
Player second = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
|
assertFalse(controller.slotChoice(second.getUserName(), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,186 +5,381 @@ 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.Character;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
import org.junit.jupiter.api.RepeatedTest;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.platform.commons.annotation.Testable;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@Timeout(value = 10, unit = TimeUnit.SECONDS)
|
||||||
class GameTest {
|
class GameTest {
|
||||||
@Test void Game()
|
|
||||||
{
|
|
||||||
int nPlayers = 3;
|
|
||||||
Game game=new Game(nPlayers);
|
|
||||||
assertEquals(nPlayers,game.getNPlayers());
|
|
||||||
assertEquals(GameStages.WAITING,game.getCurrentState().getGameStage());
|
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class,()->new Game(6));
|
|
||||||
game=new Game();
|
private Queue<Player> completeSlotChoice(Game game) {
|
||||||
|
Queue<Player> order = new LinkedList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < game.getNPlayers(); i++) {
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
order.add(current);
|
||||||
|
|
||||||
|
assertTrue(game.SlotChoiceByIndex(current, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstNonEventIndex(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (!cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("No non-event tribe card available.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstNonEventIndexOrMinusOne(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (!cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void giveOptionalEffectToAllPlayers(Player... players) {
|
||||||
|
for (Player player : players) {
|
||||||
|
player.buildingCards.add(new BuildingCard(12, 1, 1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveAllMandatoryActions(Game game) {
|
||||||
|
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveOneMandatoryAction(Game game) {
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
if (game.getCurrentState().getNLower() > 0 && hasDrawableLower(game)) {
|
||||||
|
int index = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards());
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
assertTrue(game.DrawLowerTribeCardByIndex(current, index));
|
||||||
|
} else {
|
||||||
|
current.addFood(100);
|
||||||
|
assertTrue(game.DrawLowerBuildingCardByIndex(current, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (game.getCurrentState().getNUpper() > 0 && hasDrawableUpper(game)) {
|
||||||
|
int index = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
assertTrue(game.DrawUpperTribeCardByIndex(current, index));
|
||||||
|
} else {
|
||||||
|
current.addFood(100);
|
||||||
|
assertTrue(game.DrawUpperBuildingCardByIndex(current, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
} 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())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveActionsUntilOptionalCardEffect(Game game) {
|
||||||
|
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveOptionalPhaseIfPresent(Game game) {
|
||||||
|
while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) {
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertTrue(game.NoOptionalCard(current));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playOneFullRound(Game game) {
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
resolveAllMandatoryActions(game);
|
||||||
|
|
||||||
|
resolveOptionalPhaseIfPresent(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasDrawableLower(Game game) {
|
||||||
|
return firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1
|
||||||
|
|| !game.getLowerListBuilding().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasDrawableUpper(Game game) {
|
||||||
|
return firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1
|
||||||
|
|| !game.getUpperListBuilding().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void constructorShouldInitializeGameCorrectly() {
|
||||||
|
int nPlayers = 3;
|
||||||
|
Game game = new Game(nPlayers);
|
||||||
|
|
||||||
|
assertEquals(nPlayers, game.getNPlayers());
|
||||||
|
assertEquals(GameStages.WAITING, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> new Game(6));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> new Game(-1));
|
||||||
|
|
||||||
|
game = new Game();
|
||||||
|
|
||||||
assertFalse(game.addPlayer(new Player("p1")));
|
assertFalse(game.addPlayer(new Player("p1")));
|
||||||
game.setNPlayer(nPlayers);
|
|
||||||
|
|
||||||
|
assertTrue(game.setNPlayer(nPlayers));
|
||||||
assertTrue(game.addPlayer(new Player("p1")));
|
assertTrue(game.addPlayer(new Player("p1")));
|
||||||
assertEquals(nPlayers,game.getNPlayers());
|
|
||||||
assertEquals(GameStages.WAITING,game.getCurrentState().getGameStage());
|
assertEquals(nPlayers, game.getNPlayers());
|
||||||
|
assertEquals(GameStages.WAITING, game.getCurrentState().getGameStage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getUpperListTribeCards() {
|
void getUpperListTribeCards() {
|
||||||
int nPlayers = 3;
|
int nPlayers = 3;
|
||||||
Game game=new Game(nPlayers);
|
Game game = new Game(nPlayers);
|
||||||
assertEquals(nPlayers+4 ,game.getUpperListTribeCards().size());
|
assertEquals(nPlayers + 4, game.getUpperListTribeCards().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getUpperListBuildingCards() {
|
void getUpperListBuildingCards() {
|
||||||
int nPlayers = 3;
|
int nPlayers = 3;
|
||||||
Game game=new Game(nPlayers);
|
Game game = new Game(nPlayers);
|
||||||
assertEquals(2 ,game.getUpperListBuilding().size());
|
assertEquals(2, game.getUpperListBuilding().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getLowerListBuildingCards() {
|
void getLowerListBuildingCards() {
|
||||||
int nPlayers = 3;
|
int nPlayers = 3;
|
||||||
Game game=new Game(nPlayers);
|
Game game = new Game(nPlayers);
|
||||||
assertEquals(0 ,game.getLowerListBuilding().size());
|
assertEquals(0, game.getLowerListBuilding().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getLowerListTribeCards() {
|
void getLowerListTribeCards() {
|
||||||
int nPlayers = 3;
|
int nPlayers = 3;
|
||||||
Game game=new Game(nPlayers);
|
Game game = new Game(nPlayers);
|
||||||
assertEquals(nPlayers+1 ,game.getLowerListTribeCards().size());
|
assertEquals(nPlayers + 1, game.getLowerListTribeCards().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getPlayerByIndex() {
|
void getPlayerByUsernameShouldReturnPlayerOrNull() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
Player p1 = new Player("p1");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
|
||||||
|
assertEquals(p1, game.getPlayerByUsername("p1"));
|
||||||
|
assertNull(game.getPlayerByUsername("ghost"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getNPlayers() {
|
void setNPlayerShouldWorkOnlyIfGameWasCreatedWithZeroPlayers() {
|
||||||
|
Game game = new Game();
|
||||||
|
|
||||||
|
assertTrue(game.setNPlayer(3));
|
||||||
|
assertEquals(3, game.getNPlayers());
|
||||||
|
|
||||||
|
assertFalse(game.setNPlayer(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addPlayer() {
|
void addPlayerShouldRejectDuplicatesAndStartSlotChoiceWhenFull() {
|
||||||
Game game=new Game(3);
|
Game game = new Game(3);
|
||||||
Player p1=new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2=new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3=new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
Player p4=new Player("p3");
|
Player p4 = new Player("p4");
|
||||||
|
|
||||||
assertTrue(game.addPlayer(p1));
|
assertTrue(game.addPlayer(p1));
|
||||||
assertTrue(game.addPlayer(p2));
|
assertTrue(game.addPlayer(p2));
|
||||||
assertFalse(game.addPlayer(p2));
|
assertFalse(game.addPlayer(p2));
|
||||||
assertTrue(game.addPlayer(p3));
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
assertEquals(GameStages.SLOT_CHOICE,game.getCurrentState().getGameStage());
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
assertFalse(game.addPlayer(p4));
|
assertFalse(game.addPlayer(p4));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void init() {
|
void shouldRejectInvalidSlotChoices() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
}
|
Player p1 = new Player("p1");
|
||||||
|
Player p2 = new Player("p2");
|
||||||
|
Player p3 = new Player("p3");
|
||||||
|
|
||||||
@Test
|
assertTrue(game.addPlayer(p1));
|
||||||
void slotChoiceByIndex() {
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
|
assertFalse(game.SlotChoiceByIndex(current, -1));
|
||||||
|
assertFalse(game.SlotChoiceByIndex(current, 999));
|
||||||
|
|
||||||
|
Player wrongPlayer = current.equals(p1) ? p2 : p1;
|
||||||
|
assertFalse(game.SlotChoiceByIndex(wrongPlayer, 0));
|
||||||
|
|
||||||
|
assertTrue(game.SlotChoiceByIndex(current, 0));
|
||||||
|
|
||||||
|
Player next = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertFalse(game.SlotChoiceByIndex(next, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void drawingByIndex() {
|
void drawingByIndex() {
|
||||||
Game game=new Game(3);
|
Game game = new Game(3);
|
||||||
Player p1=new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2=new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3=new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
Player p4=new Player("p3");
|
|
||||||
|
|
||||||
assertTrue(game.addPlayer(p1));
|
assertTrue(game.addPlayer(p1));
|
||||||
assertTrue(game.addPlayer(p2));
|
assertTrue(game.addPlayer(p2));
|
||||||
assertFalse(game.addPlayer(p2));
|
assertFalse(game.addPlayer(p2));
|
||||||
assertTrue(game.addPlayer(p3));
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
Queue<Player>players=new LinkedList<>();
|
Queue<Player> players = new LinkedList<>();
|
||||||
for(int i=0;i<3;i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
players.add( game.getCurrentState().getCurrentPlayer());
|
players.add(game.getCurrentState().getCurrentPlayer());
|
||||||
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
||||||
}
|
}
|
||||||
Player temp_player;
|
Player temp_player;
|
||||||
System.out.println(game);
|
|
||||||
temp_player=players.poll();
|
temp_player = players.poll();
|
||||||
assertEquals(temp_player,game.getCurrentState().getCurrentPlayer());
|
assertEquals(temp_player, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
List<TribeCard> cards=game.getLowerListTribeCards();
|
List<TribeCard> cards = game.getLowerListTribeCards();
|
||||||
|
|
||||||
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
|
index = firstNonEventIndex(cards);
|
||||||
assertTrue(game.DrawLowerTribeCardByIndex(temp_player,index));
|
assertTrue(game.DrawLowerTribeCardByIndex(temp_player, index));
|
||||||
|
|
||||||
temp_player=players.poll();
|
temp_player = players.poll();
|
||||||
assertEquals(temp_player,game.getCurrentState().getCurrentPlayer());
|
assertEquals(temp_player, game.getCurrentState().getCurrentPlayer());
|
||||||
int nCards=game.getUpperListTribeCards().size();
|
|
||||||
int countCards=0;
|
int nCards = game.getUpperListTribeCards().size();
|
||||||
HashMap<CharacterType,Integer>nCardsByType=new HashMap<CharacterType, Integer>();
|
int countCards = 0;
|
||||||
Arrays.stream(CharacterType.values()).forEach(type->nCardsByType.put(type,0));
|
HashMap<CharacterType, Integer> nCardsByType = new HashMap<CharacterType, Integer>();
|
||||||
while(game.getCurrentState().getNUpper()>1) {
|
Arrays.stream(CharacterType.values()).forEach(type -> nCardsByType.put(type, 0));
|
||||||
cards=game.getUpperListTribeCards();
|
while (game.getCurrentState().getNUpper() > 1) {
|
||||||
TribeCard temp_card=cards.stream().filter(x->!x.IsEventCard()).findFirst().get();
|
cards = game.getUpperListTribeCards();
|
||||||
index=cards.indexOf(temp_card);
|
index = firstNonEventIndexOrMinusOne(cards);
|
||||||
assertEquals(nCards-countCards,game.getUpperListTribeCards().size()-countCards);
|
|
||||||
drawTribeTest(nCardsByType,nCards,countCards,temp_card,temp_player,game);
|
if (index == -1) {
|
||||||
assertTrue(game.DrawUpperTribeCardByIndex(temp_player,index));
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TribeCard temp_card = cards.get(index);
|
||||||
|
assertEquals(nCards - countCards, game.getUpperListTribeCards().size());
|
||||||
|
assertTrue(game.DrawUpperTribeCardByIndex(temp_player, index));
|
||||||
|
drawTribeTest(nCardsByType, temp_card, temp_player);
|
||||||
countCards++;
|
countCards++;
|
||||||
}
|
}
|
||||||
cards=game.getUpperListTribeCards();
|
cards = game.getUpperListTribeCards();
|
||||||
try {
|
|
||||||
index = cards.indexOf(cards.stream().filter(TribeCard::IsEventCard).findFirst().get());
|
|
||||||
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, index));
|
|
||||||
}catch (Exception e) {
|
|
||||||
|
|
||||||
|
int eventIndex = firstEventIndexOrMinusOne(cards);
|
||||||
|
if (eventIndex != -1) {
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, eventIndex));
|
||||||
}
|
}
|
||||||
//index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
|
|
||||||
//assertTrue(game.DrawUpperTribeCardByIndex(temp_player,index));
|
temp_player.addFood(100);
|
||||||
List<BuildingCard> buildings=game.getUpperListBuilding();
|
|
||||||
temp_player.addFood(10);
|
assertFalse(game.getUpperListBuilding().isEmpty());
|
||||||
index=0;
|
|
||||||
assertTrue(game.DrawUpperBuildingCardByIndex(temp_player,index));
|
index = 0;
|
||||||
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
|
assertTrue(game.DrawUpperBuildingCardByIndex(temp_player, index));
|
||||||
assertFalse(game.DrawUpperTribeCardByIndex(temp_player,index));
|
|
||||||
|
int remainingTribeIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
|
||||||
|
if (remainingTribeIndex != -1) {
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, remainingTribeIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
Player thirdPlayer = players.poll();
|
||||||
|
assertNotNull(thirdPlayer);
|
||||||
|
assertEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
|
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS
|
||||||
|
&& thirdPlayer.equals(game.getCurrentState().getCurrentPlayer())) {
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNotEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
System.out.println(game);
|
System.out.println(game);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void drawTribeTest(HashMap<CharacterType,Integer>nCardsByType,int nCards,int countCards,TribeCard temp_card,Player temp_player,Game game) {
|
|
||||||
|
|
||||||
switch (((Character)temp_card).getType()) {
|
private void drawTribeTest(HashMap<CharacterType, Integer> nCardsByType,
|
||||||
case CharacterType.ARTIST:
|
TribeCard temp_card,
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.artists.size());
|
Player temp_player) {
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
|
||||||
|
switch (((Character) temp_card).getType()) {
|
||||||
|
case ARTIST:
|
||||||
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.artists.size());
|
||||||
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
case CharacterType.INVENTOR:
|
case INVENTOR:
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.inventors.size());
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.inventors.size());
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
case CharacterType.HUNTER:
|
case HUNTER:
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.hunters.size());
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.hunters.size());
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
case CharacterType.SHAMAN:
|
case SHAMAN:
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.shamans.size());
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.shamans.size());
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
case CharacterType.BUILDER:
|
case BUILDER:
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.builders.size());
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.builders.size());
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
case CharacterType.GATHERER:
|
case GATHERER:
|
||||||
assertEquals( nCardsByType.get(((Character)temp_card).getType())+1,temp_player.gatherers.size());
|
assertEquals(nCardsByType.get(((Character) temp_card).getType()) + 1, temp_player.gatherers.size());
|
||||||
nCardsByType.merge(((Character)temp_card).getType(),1,Integer::sum);
|
nCardsByType.merge(((Character) temp_card).getType(), 1, Integer::sum);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -192,30 +387,447 @@ class GameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pickOptionalTribeCard() {
|
void pickOptionalTribeCard() {
|
||||||
}
|
Game game = new Game(3);
|
||||||
@Test
|
|
||||||
void pickOptionalBuildingCard() {
|
Player p1 = new Player("p1");
|
||||||
}
|
Player p2 = new Player("p2");
|
||||||
@Test
|
Player p3 = new Player("p3");
|
||||||
void noOptionalCard() {
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
void toStringModel()
|
|
||||||
{
|
|
||||||
Game game=new Game(3);
|
|
||||||
Player p1=new Player("p1");
|
|
||||||
Player p2=new Player("p2");
|
|
||||||
Player p3=new Player("p3");
|
|
||||||
|
|
||||||
assertTrue(game.addPlayer(p1));
|
assertTrue(game.addPlayer(p1));
|
||||||
assertTrue(game.addPlayer(p2));
|
assertTrue(game.addPlayer(p2));
|
||||||
assertTrue(game.addPlayer(p3));
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(p1, p2, p3);
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
int index = firstNonEventIndex(game.getUpperListTribeCards());
|
||||||
|
|
||||||
|
int charactersBefore = current.getTotCharacters();
|
||||||
|
|
||||||
|
assertTrue(game.PickOptionalTribeCardByIndex(current, index));
|
||||||
|
|
||||||
|
assertEquals(charactersBefore + 1, current.getTotCharacters());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pickOptionalBuildingCard() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
Player p1 = new Player("p1");
|
||||||
|
Player p2 = new Player("p2");
|
||||||
|
Player p3 = new Player("p3");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(p1, p2, p3);
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertFalse(game.getUpperListBuilding().isEmpty());
|
||||||
|
|
||||||
|
current.addFood(100);
|
||||||
|
|
||||||
|
int foodBefore = current.getFoodValue();
|
||||||
|
int buildingsBefore = current.buildingCards.size();
|
||||||
|
|
||||||
|
assertTrue(game.PickOptionalBuildingCard(current, 0));
|
||||||
|
|
||||||
|
assertTrue(current.getFoodValue() < foodBefore);
|
||||||
|
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void noOptionalCard() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
Player p1 = new Player("p1");
|
||||||
|
Player p2 = new Player("p2");
|
||||||
|
Player p3 = new Player("p3");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(p1, p2, p3);
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertTrue(game.NoOptionalCard(current));
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Player> addPlayers(Game game, int nPlayers, String prefix) {
|
||||||
|
List<Player> players = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 1; i <= nPlayers; i++) {
|
||||||
|
Player player = new Player(prefix + i);
|
||||||
|
players.add(player);
|
||||||
|
assertTrue(game.addPlayer(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstEventIndexOrMinusOne(List<TribeCard> cards) {
|
||||||
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
|
if (cards.get(i).IsEventCard()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getCurrentPlayerNumberShouldTrackAddedPlayers() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
assertEquals(0, game.getCurrentPlayerNumber());
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(new Player("a")));
|
||||||
|
assertEquals(1, game.getCurrentPlayerNumber());
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(new Player("b")));
|
||||||
|
assertEquals(2, game.getCurrentPlayerNumber());
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(new Player("c")));
|
||||||
|
assertEquals(3, game.getCurrentPlayerNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void slotChoiceByIndexShouldReturnFalseOutsideSlotChoiceStage() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
addPlayers(game, 3, "slot_out_");
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertFalse(game.SlotChoiceByIndex(current, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldRejectInvalidDrawRequests() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
Player p1 = new Player("p1");
|
||||||
|
Player p2 = new Player("p2");
|
||||||
|
Player p3 = new Player("p3");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertFalse(game.DrawLowerTribeCardByIndex(current, 0));
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(current, 0));
|
||||||
|
assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
|
||||||
|
assertFalse(game.DrawLowerBuildingCardByIndex(current, 0));
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
|
||||||
|
current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
Player wrongPlayer = current.equals(p1) ? p2 : p1;
|
||||||
|
|
||||||
|
assertFalse(game.DrawLowerTribeCardByIndex(current, -1));
|
||||||
|
assertFalse(game.DrawLowerTribeCardByIndex(current, 999));
|
||||||
|
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(current, -1));
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(current, 999));
|
||||||
|
|
||||||
|
assertFalse(game.DrawUpperBuildingCardByIndex(current, -1));
|
||||||
|
assertFalse(game.DrawUpperBuildingCardByIndex(current, 999));
|
||||||
|
|
||||||
|
assertFalse(game.DrawLowerBuildingCardByIndex(current, -1));
|
||||||
|
assertFalse(game.DrawLowerBuildingCardByIndex(current, 999));
|
||||||
|
|
||||||
|
int lowerIndex = firstNonEventIndexOrMinusOne(game.getLowerListTribeCards());
|
||||||
|
if (lowerIndex != -1) {
|
||||||
|
assertFalse(game.DrawLowerTribeCardByIndex(wrongPlayer, lowerIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
int upperIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
|
||||||
|
if (upperIndex != -1) {
|
||||||
|
assertFalse(game.DrawUpperTribeCardByIndex(wrongPlayer, upperIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.getUpperListBuilding().isEmpty()) {
|
||||||
|
assertFalse(game.DrawUpperBuildingCardByIndex(wrongPlayer, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void optionalMethodsShouldReturnFalseOutsideOptionalState() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
addPlayers(game, 3, "optional_out_");
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertFalse(game.PickOptionalTribeCardByIndex(current, 0));
|
||||||
|
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
||||||
|
assertFalse(game.NoOptionalCard(current));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void optionalMethodsShouldRejectWrongPlayerAndInvalidIndexes() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
List<Player> players = addPlayers(game, 3, "optional_invalid_");
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
Player wrongPlayer = current.equals(players.get(0)) ? players.get(1) : players.get(0);
|
||||||
|
|
||||||
|
assertFalse(game.PickOptionalTribeCardByIndex(wrongPlayer, 0));
|
||||||
|
assertFalse(game.PickOptionalBuildingCard(wrongPlayer, 0));
|
||||||
|
assertFalse(game.NoOptionalCard(wrongPlayer));
|
||||||
|
|
||||||
|
assertFalse(game.PickOptionalTribeCardByIndex(current, -1));
|
||||||
|
assertFalse(game.PickOptionalTribeCardByIndex(current, 999));
|
||||||
|
|
||||||
|
assertFalse(game.PickOptionalBuildingCard(current, -1));
|
||||||
|
assertFalse(game.PickOptionalBuildingCard(current, 999));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||||
|
void shouldNotCrashWhenNoPlayerHasOptionalEffect() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
addPlayers(game, 3, "no_optional_");
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> resolveAllMandatoryActions(game));
|
||||||
|
|
||||||
|
assertNotEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void constructorShouldRejectOnePlayerGame() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> new Game(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void setNPlayerShouldAllowCompleteGameSetup() {
|
||||||
|
Game game = new Game();
|
||||||
|
|
||||||
|
assertTrue(game.setNPlayer(3));
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(new Player("p1")));
|
||||||
|
assertTrue(game.addPlayer(new Player("p2")));
|
||||||
|
assertTrue(game.addPlayer(new Player("p3")));
|
||||||
|
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertTrue(game.SlotChoiceByIndex(current, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 20, unit = TimeUnit.SECONDS)
|
||||||
|
void shouldCompleteFullGameThroughRealFlow() {
|
||||||
|
for (int nPlayers : new int[]{2, 3, 4, 5}) {
|
||||||
|
Game game = new Game(nPlayers);
|
||||||
|
|
||||||
|
for (int i = 1; i <= nPlayers; i++) {
|
||||||
|
assertTrue(game.addPlayer(new Player("p" + nPlayers + "_" + i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(1, game.getCurrentState().getRound());
|
||||||
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
|
for (int expectedRound = 1; expectedRound < 10; expectedRound++) {
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(expectedRound, game.getCurrentState().getRound());
|
||||||
|
|
||||||
|
playOneFullRound(game);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
GameStages.SLOT_CHOICE,
|
||||||
|
game.getCurrentState().getGameStage(),
|
||||||
|
"After round " + expectedRound + ", the game should return to SLOT_CHOICE."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
expectedRound + 1,
|
||||||
|
game.getCurrentState().getRound(),
|
||||||
|
"The round should increase after completing round " + expectedRound + "."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(10, game.getCurrentState().getRound());
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
playOneFullRound(game);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
GameStages.ENDED,
|
||||||
|
game.getCurrentState().getGameStage(),
|
||||||
|
"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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void setNPlayerShouldRejectInvalidPlayerCounts() {
|
||||||
|
assertFalse(new Game().setNPlayer(-1));
|
||||||
|
assertFalse(new Game().setNPlayer(1));
|
||||||
|
assertFalse(new Game().setNPlayer(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addPlayerShouldRejectDifferentPlayerWithSameUsername() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(new Player("same_name")));
|
||||||
|
assertFalse(game.addPlayer(new Player("same_name")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||||
|
void roundShouldAdvanceAfterOnlyOptionalPlayerSkipsOptionalCard() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
List<Player> players = addPlayers(game, 3, "single_optional_");
|
||||||
|
|
||||||
|
players.get(0).buildingCards.add(new BuildingCard(12, 1, 1, 1));
|
||||||
|
|
||||||
|
int roundBefore = game.getCurrentState().getRound();
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
assertTrue(game.NoOptionalCard(current));
|
||||||
|
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(roundBefore + 1, game.getCurrentState().getRound());
|
||||||
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||||
|
void roundShouldAdvanceAfterAllOptionalPlayersSkipOptionalCard() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
Player p1 = new Player("p1");
|
||||||
|
Player p2 = new Player("p2");
|
||||||
|
Player p3 = new Player("p3");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(p1, p2, p3);
|
||||||
|
|
||||||
|
int roundBefore = game.getCurrentState().getRound();
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
resolveOptionalPhaseIfPresent(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(roundBefore + 1, game.getCurrentState().getRound());
|
||||||
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pickOptionalBuildingCardShouldReturnFalseIfPlayerCannotPay() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
List<Player> players = addPlayers(game, 3, "no_food_");
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
assertNotNull(current);
|
||||||
|
|
||||||
|
while (current.getFoodValue() > 0) {
|
||||||
|
assertTrue(current.removeFood(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(0, current.getFoodValue());
|
||||||
|
|
||||||
|
assertFalse(
|
||||||
|
game.getUpperListBuilding().isEmpty(),
|
||||||
|
"There must be at least one upper building card to test that the player cannot buy it."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void toStringModel() throws IOException, InterruptedException {
|
||||||
|
Game game=new Game(5);
|
||||||
|
Player p1=new Player("p1");
|
||||||
|
Player p2=new Player("p2");
|
||||||
|
Player p3=new Player("p3");
|
||||||
|
Player p4=new Player("p4");
|
||||||
|
Player p5=new Player("p5");
|
||||||
|
|
||||||
|
assertTrue(game.addPlayer(p1));
|
||||||
|
assertTrue(game.addPlayer(p2));
|
||||||
|
assertTrue(game.addPlayer(p3));
|
||||||
|
assertTrue(game.addPlayer(p4));
|
||||||
|
assertTrue(game.addPlayer(p5));
|
||||||
|
|
||||||
Queue<Player>players=new LinkedList<>();
|
Queue<Player>players=new LinkedList<>();
|
||||||
for(int i=0;i<3;i++) {
|
for(int i=0;i<3;i++) {
|
||||||
players.add( game.getCurrentState().getCurrentPlayer());
|
players.add( game.getCurrentState().getCurrentPlayer());
|
||||||
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
||||||
}
|
}
|
||||||
System.out.println(game);
|
|
||||||
|
System.out.println(game.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class Order3Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void thirdReturnPaysFoodAndLosesPrestige() {
|
void thirdReturnPaysFoodWithoutLosingPrestige() {
|
||||||
Player p1 = new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2 = new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3 = new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
@@ -90,33 +90,7 @@ class Order3Test {
|
|||||||
order.push(thirdToAct);
|
order.push(thirdToAct);
|
||||||
|
|
||||||
assertEquals(0, thirdToAct.getFoodValue());
|
assertEquals(0, thirdToAct.getFoodValue());
|
||||||
assertEquals(-2, thirdToAct.getPrestigeValue());
|
assertEquals(0, thirdToAct.getPrestigeValue());
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void thirdReturnWithoutFoodNoEffect() {
|
|
||||||
Player p1 = new Player("p1");
|
|
||||||
Player p2 = new Player("p2");
|
|
||||||
Player p3 = new Player("p3");
|
|
||||||
ArrayList<Player> players = new ArrayList<>();
|
|
||||||
players.add(p1);
|
|
||||||
players.add(p2);
|
|
||||||
players.add(p3);
|
|
||||||
Order3 order = new Order3(players);
|
|
||||||
|
|
||||||
Player firstToAct = order.pull();
|
|
||||||
Player secondToAct = order.pull();
|
|
||||||
Player thirdToAct = order.pull();
|
|
||||||
|
|
||||||
int initialFood = thirdToAct.getFoodValue();
|
|
||||||
int initialPrestige = thirdToAct.getPrestigeValue();
|
|
||||||
|
|
||||||
order.push(firstToAct);
|
|
||||||
order.push(secondToAct);
|
|
||||||
order.push(thirdToAct);
|
|
||||||
|
|
||||||
assertEquals(initialFood, thirdToAct.getFoodValue());
|
|
||||||
assertEquals(initialPrestige, thirdToAct.getPrestigeValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class Order4Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fourthReturnPaysFoodAndLosesPrestige() {
|
void fourthReturnPaysFoodWithoutLosingPrestige() {
|
||||||
Player p1 = new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2 = new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3 = new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
@@ -127,11 +127,11 @@ class Order4Test {
|
|||||||
order.push(fourthToAct);
|
order.push(fourthToAct);
|
||||||
|
|
||||||
assertEquals(0, fourthToAct.getFoodValue());
|
assertEquals(0, fourthToAct.getFoodValue());
|
||||||
assertEquals(-2, fourthToAct.getPrestigeValue());
|
assertEquals(0, fourthToAct.getPrestigeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fourthReturnWithoutFoodNoEffect() {
|
void fourthReturnWithoutFoodLosesPrestige() {
|
||||||
Player p1 = new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2 = new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3 = new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
@@ -157,7 +157,7 @@ class Order4Test {
|
|||||||
order.push(fourthToAct);
|
order.push(fourthToAct);
|
||||||
|
|
||||||
assertEquals(initialFood, fourthToAct.getFoodValue());
|
assertEquals(initialFood, fourthToAct.getFoodValue());
|
||||||
assertEquals(initialPrestige, fourthToAct.getPrestigeValue());
|
assertEquals(initialPrestige - 2, fourthToAct.getPrestigeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class Order5Test {
|
class Order5Test {
|
||||||
@@ -149,7 +151,7 @@ class Order5Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fifthReturnPaysFoodAndLosesPrestige() {
|
void fifthReturnPaysFoodWithoutLosingPrestige() {
|
||||||
Player p1 = new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2 = new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3 = new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
@@ -178,11 +180,11 @@ class Order5Test {
|
|||||||
order.push(fifthToAct);
|
order.push(fifthToAct);
|
||||||
|
|
||||||
assertEquals(0, fifthToAct.getFoodValue());
|
assertEquals(0, fifthToAct.getFoodValue());
|
||||||
assertEquals(-2, fifthToAct.getPrestigeValue());
|
assertEquals(0, fifthToAct.getPrestigeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fifthReturnWithoutFoodNoEffect() {
|
void fifthReturnWithoutFoodLosesPrestige() {
|
||||||
Player p1 = new Player("p1");
|
Player p1 = new Player("p1");
|
||||||
Player p2 = new Player("p2");
|
Player p2 = new Player("p2");
|
||||||
Player p3 = new Player("p3");
|
Player p3 = new Player("p3");
|
||||||
@@ -212,7 +214,7 @@ class Order5Test {
|
|||||||
order.push(fifthToAct);
|
order.push(fifthToAct);
|
||||||
|
|
||||||
assertEquals(initialFood, fifthToAct.getFoodValue());
|
assertEquals(initialFood, fifthToAct.getFoodValue());
|
||||||
assertEquals(initialPrestige, fifthToAct.getPrestigeValue());
|
assertEquals(initialPrestige - 2, fifthToAct.getPrestigeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user