Merge pull request #105 from rubenpirreram/Pick-optional-refactor

Pick optional refactor
This commit is contained in:
rubenpirreram
2026-05-17 16:48:10 +02:00
committed by GitHub
19 changed files with 112 additions and 572 deletions
@@ -38,7 +38,6 @@ public class ClientLauncherTUI {
*/ */
public void main() throws InterruptedException { public void main() throws InterruptedException {
view = new TUI(null); view = new TUI(null);
admissibleChar.add("0");
admissibleChar.add("1"); admissibleChar.add("1");
admissibleChar.add("2"); admissibleChar.add("2");
admissibleChar.add("3"); admissibleChar.add("3");
@@ -46,8 +45,6 @@ public class ClientLauncherTUI {
admissibleChar.add("5"); admissibleChar.add("5");
admissibleChar.add("6"); admissibleChar.add("6");
admissibleChar.add("7"); admissibleChar.add("7");
admissibleChar.add("8");
admissibleChar.add("9");
admissibleChar.add("A"); admissibleChar.add("A");
admissibleChar.add("B"); admissibleChar.add("B");
admissibleChar.add("C"); admissibleChar.add("C");
@@ -138,7 +135,7 @@ public class ClientLauncherTUI {
if(admissibleChar.contains(action)) if(admissibleChar.contains(action))
{ {
if (!action.equals("7") && !action.equals("8")&& !action.equals("A") && !action.equals("B") && !action.equals("C")&&!action.equals("a") && !action.equals("b") && !action.equals("c")) { if (!action.equals("6") && !action.equals("A") && !action.equals("B") && !action.equals("C")&&!action.equals("a") && !action.equals("b") && !action.equals("c")) {
try { try {
System.out.println("Insert the required position:"); System.out.println("Insert the required position:");
pos = scanner.nextInt(); pos = scanner.nextInt();
@@ -148,16 +145,13 @@ public class ClientLauncherTUI {
} }
} }
switch (action) { switch (action) {
case "0" -> controller.slotChoice(username, pos); case "1" -> controller.slotChoice(username, pos);
case "1" -> controller.drawUpperTribeCard(username, pos); case "2" -> controller.drawUpperTribeCard(username, pos);
case "2" -> controller.drawUpperBuildingCard(username, pos); case "3" -> controller.drawUpperBuildingCard(username, pos);
case "3" -> controller.drawLowerTribeCard(username, pos); case "4" -> controller.drawLowerTribeCard(username, pos);
case "4" -> controller.drawLowerBuildingCard(username, pos); case "5" -> controller.drawLowerBuildingCard(username, pos);
case "5" -> controller.pickOptionalTribeCard(username, pos); case "6" -> controller.skipTurn(username);
case "6" -> controller.pickOptionalBuildingCard(username, pos); case "7" -> controller.totemChoice(username,pos);
case "7" -> controller.noOptionalCard(username);
case "8" -> controller.skipTurn(username);
case "9" -> controller.totemChoice(username,pos);
case "A", "a" -> view.fullRender(); case "A", "a" -> view.fullRender();
case "B", "b" -> view.renderBoard(); case "B", "b" -> view.renderBoard();
case "C", "c" -> view.renderPlayer(); case "C", "c" -> view.renderPlayer();
@@ -157,52 +157,6 @@ public class ClientController {
} }
/**
* Used to draw a tribe card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername,miniModel.currentState.getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
client.pickOptionalTribeCard(playerUsername,pos);
}
}
/**
* Used to draw a building card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
client.pickOptionalBuildingCard(playerUsername,pos);
}
}
/**
* Used to skip the action of drawing a card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
if(!Objects.equals(playerUsername, miniModel.currentState.getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else {
client.noOptionalCard(playerUsername);
}
}
/** /**
* Used to perform the slot choice action for the specified player at the specified position. * Used to perform the slot choice action for the specified player at the specified position.
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
@@ -142,54 +142,14 @@ public class GameController {
* @return {@code true} if the skip action is valid and successfully performed; * @return {@code true} if the skip action is valid and successfully performed;
* {@code false} if the player does not exist or the action is not valid. * {@code false} if the player does not exist or the action is not valid.
*/ */
public boolean SkipNoDrawable(String playerUsername) { public boolean SkipTurn(String playerUsername) {
Player player= model.getPlayerByUsername(playerUsername); Player player= model.getPlayerByUsername(playerUsername);
if(player==null) if(player==null)
return false; return false;
return model.SkipNoDrawable(model.getPlayerByUsername(playerUsername)); return model.SkipTurn(model.getPlayerByUsername(playerUsername));
} }
/**
* 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 boolean pickOptionalTribeCard(String playerUsername,int pos) {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.PickOptionalTribeCardByIndex(model.getPlayerByUsername(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 boolean pickOptionalBuildingCard(String playerUsername,int pos) {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.PickOptionalBuildingCard(model.getPlayerByUsername(playerUsername), pos);
}
/**
* Refuse to pick an optional building card for the specified player.
* @param playerUsername the username of the player performing the action.
* @return {@code true} if the action succeeds, {@code false} if the player does not exist
* or if the pick operation fails.
*/
public boolean noOptionalCard(String playerUsername) {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.NoOptionalCard(model.getPlayerByUsername(playerUsername));
}
/** /**
* Attempts to perform the slot choice action for the specified player at the specified position. * Attempts to perform the slot choice action for the specified player at the specified position.
@@ -411,11 +411,12 @@ public class Game implements Serializable {
* @param player the player performing the draw. * @param player the player performing the draw.
* @param cardIndex the index of the upper tribe card to draw. * @param cardIndex the index of the upper tribe card to draw.
* @return {@code true} if the draw succeeds, {@code false} otherwise. * @return {@code true} if the draw succeeds, {@code false} otherwise.
* TODO
*/ */
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) { public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size()) if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS) if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{ {
return false; return false;
} }
@@ -423,7 +424,7 @@ public class Game implements Serializable {
{ {
return false; return false;
} }
if(currentState.getNUpper() <1) if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false; return false;
TribeCard tribeCard = board.upperListTribe.get(cardIndex); TribeCard tribeCard = board.upperListTribe.get(cardIndex);
if(tribeCard.IsEventCard()) if(tribeCard.IsEventCard())
@@ -432,9 +433,17 @@ public class Game implements Serializable {
Character tempCard = (Character) tribeCard; Character tempCard = (Character) tribeCard;
tempCard.insert(player); tempCard.insert(player);
board.removeUpperTribeCard(tempCard); board.removeUpperTribeCard(tempCard);
if(currentState.getGameStage()==GameStages.RES_ACTIONS)
{
currentState.UpperDrawn(); currentState.UpperDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty()))) if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
nextPlayerSetup(); nextPlayerSetup();
}
else
{
nextPlayerSetup();
}
return true; return true;
} }
@@ -447,8 +456,8 @@ public class Game implements Serializable {
* @param player the player skipping the turn . * @param player the player skipping the turn .
* @return {@code true} if the skip succeeds, {@code false} otherwise. * @return {@code true} if the skip succeeds, {@code false} otherwise.
*/ */
public boolean SkipNoDrawable(Player player) { public boolean SkipTurn(Player player) {
if(currentState.getGameStage()!= GameStages.RES_ACTIONS) if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E))
{ {
return false; return false;
} }
@@ -456,6 +465,8 @@ public class Game implements Serializable {
{ {
return false; return false;
} }
if(currentState.getGameStage()==GameStages.RES_ACTIONS)
{
if(hasDrawableDown() && currentState.getNLower()>0 ) if(hasDrawableDown() && currentState.getNLower()>0 )
return false; return false;
if(hasDrawableUp() && currentState.getNUpper()>0) if(hasDrawableUp() && currentState.getNUpper()>0)
@@ -465,6 +476,10 @@ public class Game implements Serializable {
while(currentState.getNUpper()>0) while(currentState.getNUpper()>0)
currentState.UpperDrawn(); currentState.UpperDrawn();
nextPlayerSetup(); nextPlayerSetup();
}
else {
nextPlayerSetup();
}
return true; return true;
} }
@@ -525,7 +540,7 @@ public class Game implements Serializable {
public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) { public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size()) if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS) if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{ {
return false; return false;
} }
@@ -534,18 +549,23 @@ public class Game implements Serializable {
return false; return false;
} }
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex); BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
if(currentState.getNUpper() <1) if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false; return false;
if(buildingCard.buy(player)) if(!buildingCard.buy(player))
{
return false;
}
board.removeUpperBuildingCard(buildingCard);
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS))
{ {
currentState.UpperDrawn(); currentState.UpperDrawn();
board.removeUpperBuildingCard(buildingCard);
}
else
return false;
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty()))) if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
nextPlayerSetup(); nextPlayerSetup();
}
else
{
nextPlayerSetup();
}
return true; return true;
} }
@@ -594,98 +614,6 @@ public class Game implements Serializable {
//region Optional Card Methods //region Optional Card Methods
/**
* Attempts to pick the upper optional tribe card at the specified index for the specified player.
* The operation succeeds only if the current game stage is {@code OPTIONAL_CARD_EFFECT},
* the specified player is the current player, the index is valid,
* and the selected tribe card is not an event card.
* If successful, the card is inserted into the player's collection,
* removed from the board, the player is removed from the optional card queue,
* and the next player setup is triggered.
*
* @param player the player performing the optional tribe card pick.
* @param cardIndex the index of the upper optional tribe card to pick.
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean PickOptionalTribeCardByIndex(Player player,int cardIndex) {
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
return false;
}
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
return false;
TribeCard tribeCard = board.upperListTribe.get(cardIndex);
if(tribeCard.IsEventCard())
return false;
Character tempCard = (Character) tribeCard;
tempCard.insert(player);
board.removeUpperTribeCard(tempCard);
OptionalCardQueue.removeIf(x->x.equals(player));
nextPlayerSetup();
return true;
}
/**
* Attempts to pick the upper optional building card at the specified index for the specified player.
* The operation succeeds only if the current game stage is {@code OPTIONAL_CARD_EFFECT},
* the specified player is the current player, the index is valid,
* and the selected building card can be bought by the player.
* If successful, the card is removed from the board, the next player setup is triggered,
* and the player is removed from the optional card queue.
*
* @param player the player performing the optional building card pick.
* @param cardIndex the index of the upper optional building card to pick.
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean PickOptionalBuildingCard(Player player, int cardIndex) {
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
return false;
}
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
return false;
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
if(buildingCard.buy(player)) {
board.removeUpperBuildingCard(buildingCard);
}
else {
return false;
}
OptionalCardQueue.removeIf(x->x.equals(player));
nextPlayerSetup();
return true;
}
/**
* Skips the optional card choice for the specified player.
* The operation succeeds only if the current game stage is {@code OPTIONAL_CARD_EFFECT}
* and the specified player is the current player.
* If successful, the player is removed from the optional card queue
* and the next player setup is triggered.
*
* @param player the player skipping the optional card choice.
* @return {@code true} if the operation succeeds, {@code false} otherwise.
*/
public boolean NoOptionalCard(Player player) {
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
return false;
}
if(!player.equals(currentState.getCurrentPlayer())){
return false;
}
OptionalCardQueue.removeIf(x->x.equals(player));
nextPlayerSetup();
return true;
}
//endregion //endregion
//endregion //endregion
@@ -763,7 +691,7 @@ public class Game implements Serializable {
for (Map.Entry<Slot,Player> entry : slotMap.entrySet()) { for (Map.Entry<Slot,Player> entry : slotMap.entrySet()) {
if (entry.getValue() != null) { if (entry.getValue() != null) {
if(disconnetedPlayers.containsKey(entry.getValue())&&disconnetedPlayers.get(currentState.getCurrentPlayer())) if(disconnetedPlayers.containsKey(entry.getValue())&&disconnetedPlayers.get(entry.getValue()))
{ {
orderLogicCard.push(entry.getValue()); orderLogicCard.push(entry.getValue());
entry.setValue(null); entry.setValue(null);
@@ -1,15 +0,0 @@
package it.polimi.ingsw.gc14.Network;
//TODO
public class ClientPlayer {
private String username;
public String getUsername() {
return username;
}
public boolean connected;
public ClientPlayer(String username,boolean connected) {
this.username = username;
this.connected = connected;
}
}
@@ -12,12 +12,9 @@ public enum EventType {
DRAW_LOWER_TRIBE, DRAW_LOWER_TRIBE,
DRAW_UPPER_BUILD, DRAW_UPPER_BUILD,
DRAW_LOWER_BUILD, DRAW_LOWER_BUILD,
PICK_OPTIONAL_TRIBE, SKIP_TURN,
PICK_OPTIONAL_BUILD,
SKIP_NO_DRAWABLE,
DISCONNECTED_PLAYER, DISCONNECTED_PLAYER,
RECONNECT_PLAYER, RECONNECT_PLAYER,
NEXT_ROUND, NEXT_ROUND,
ENDED_GAME, ENDED_GAME
NO_OPTIONAL_CARD
} }
@@ -20,14 +20,6 @@ public interface IClient {
public void skipTurn(String playerUsername); public void skipTurn(String playerUsername);
public void pickOptionalTribeCard(String playerUsername,int pos) ;
public void pickOptionalBuildingCard(String playerUsername,int pos) ;
public void noOptionalCard(String playerUsername) ;
public void slotChoice(String playerUsername,int pos) ; public void slotChoice(String playerUsername,int pos) ;
public void totemChoice(String playerUsername,String totem) ; public void totemChoice(String playerUsername,String totem) ;
} }
@@ -1,45 +0,0 @@
package it.polimi.ingsw.gc14.Network.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
/**
* NetworkEvent to avoid drawing a card from the upper list (see the effect of Building 12)
*/
public class NoOptionalCard extends NetworkEvent implements Serializable{
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
*/
public NoOptionalCard(String username){
super(username, EventType.NO_OPTIONAL_CARD, false);
}
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.noOptionalCard(username);
}
//TODO
@Override
public boolean apply(MiniModel miniModel){
if(isError)
return false;
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
return true;
}
}
@@ -1,52 +0,0 @@
package it.polimi.ingsw.gc14.Network.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
/**
* NetworkEvent to draw a building card from the upper list (see the effect of Building 12)
*/
public class PickOptionalBuildingCard extends NetworkEvent implements Serializable{
/** Index of the card to draw */
private int pos;
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public PickOptionalBuildingCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_BUILD, false);
this.pos = pos;
}
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.pickOptionalBuildingCard(username, pos);
}
//TODO
@Override
public boolean apply(MiniModel miniModel){
if(isError)
return false;
miniModel.board.removeUpperBuildingCard(miniModel.board.upperListBuilding.get(pos));
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
return true;
}
}
@@ -1,54 +0,0 @@
package it.polimi.ingsw.gc14.Network.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
/**
* NetworkEvent to draw a tribe card from the upper list (see the effect of Building 12)
*/
public class PickOptionalTribeCard extends NetworkEvent implements Serializable{
/** Index of the card to draw */
private int pos;
/**
* Class constructor.
* Initialized all the attributes.
* @param username the name of the player requesting the event
* @param pos the index of the card to draw
*/
public PickOptionalTribeCard(String username, int pos){
super(username, EventType.PICK_OPTIONAL_TRIBE, false);
this.pos = pos;
}
/**
* @param gameController the Game Controller on which to apply the event
* @return true if the player could draw the card, false otherwise
*/
@Override
public boolean apply(GameController gameController){
return gameController.pickOptionalTribeCard(username, pos);
}
//TODO
@Override
public boolean apply(MiniModel miniModel){
if(isError)
return false;
miniModel.board.removeUpperTribeCard(miniModel.board.upperListTribe.get(pos));
miniModel.setPlayer(player);
miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState);
miniModel.setSlotPlayerMap(slotPlayerMap);
return true;
}
}
@@ -10,15 +10,15 @@ import java.io.Serializable;
/** /**
* NetworkEvent to avoid drawing a card from the lower card list * NetworkEvent to avoid drawing a card from the lower card list
*/ */
public class SkipNoDrawable extends NetworkEvent implements Serializable{ public class SkipTurn extends NetworkEvent implements Serializable{
/** /**
* Class constructor. * Class constructor.
* Initializes all the attributes. * Initializes all the attributes.
* @param username the name of the player requesting the event * @param username the name of the player requesting the event
*/ */
public SkipNoDrawable(String username){ public SkipTurn(String username){
super(username, EventType.SKIP_NO_DRAWABLE, false); super(username, EventType.SKIP_TURN, false);
} }
/** /**
@@ -27,7 +27,7 @@ public class SkipNoDrawable extends NetworkEvent implements Serializable{
*/ */
@Override @Override
public boolean apply(GameController gameController){ public boolean apply(GameController gameController){
return gameController.SkipNoDrawable(username); return gameController.SkipTurn(username);
} }
//TODO //TODO
@@ -209,52 +209,6 @@ public class RMIClient implements IClient {
/**
* Used to draw a tribe card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
try{
stub.pickOptionalTribeCard(playerUsername,pos);
}
catch (RemoteException e){
System.out.println("Error during remote pick optional tribe card");
}
}
/**
* Used to draw a building card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
try{
stub.pickOptionalBuildingCard(playerUsername,pos);
}
catch (RemoteException e){
System.out.println("Error during remote pick optional building card");
}
}
/**
* Used to skip the action of drawing a card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
try{
stub.noOptionalCard(playerUsername);
}
catch (RemoteException e){
System.out.println("Error during remote no pick optional card");
}
}
/** /**
* Used to perform the slot choice action for the specified player at the specified position. * Used to perform the slot choice action for the specified player at the specified position.
@@ -18,9 +18,6 @@ public interface IGameServer extends Remote {
void drawUpperBuildingCard(String playerUsername, int pos) throws RemoteException; void drawUpperBuildingCard(String playerUsername, int pos) throws RemoteException;
void drawLowerBuildingCard(String playerUsername, int pos) throws RemoteException; void drawLowerBuildingCard(String playerUsername, int pos) throws RemoteException;
void skipTurn(String playerUsername) throws RemoteException; void skipTurn(String playerUsername) throws RemoteException;
void pickOptionalTribeCard(String playerUsername, int pos) throws RemoteException;
void pickOptionalBuildingCard(String playerUsername, int pos) throws RemoteException;
void noOptionalCard(String playerUsername) throws RemoteException;
void slotChoice(String playerUsername, int pos) throws RemoteException; void slotChoice(String playerUsername, int pos) throws RemoteException;
void totemChoice(String playerUsername, String totems) throws RemoteException; void totemChoice(String playerUsername, String totems) throws RemoteException;
/** /**
@@ -3,7 +3,6 @@ package it.polimi.ingsw.gc14.Network.RMI.Server;
import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.LimitedMap; import it.polimi.ingsw.gc14.LimitedMap;
import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import it.polimi.ingsw.gc14.Model.MiniModel; import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
@@ -250,43 +249,11 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
*/ */
public void skipTurn(String playerUsername) { public void skipTurn(String playerUsername) {
actionQueue.offer(new SkipNoDrawable(playerUsername)); actionQueue.offer(new SkipTurn(playerUsername));
} }
/**
* Used to draw a tribe card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
actionQueue.offer(new PickOptionalTribeCard(playerUsername,pos));
}
/**
* Used to draw a building card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
actionQueue.offer(new PickOptionalBuildingCard(playerUsername,pos));
}
/**
* Used to skip the action of drawing a card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
actionQueue.offer(new NoOptionalCard(playerUsername));
}
/** /**
* Used to perform the slot choice action for the specified player at the specified position. * Used to perform the slot choice action for the specified player at the specified position.
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
@@ -235,39 +235,7 @@ public class TCPClient implements IClient {
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
*/ */
public void skipTurn(String playerUsername) { public void skipTurn(String playerUsername) {
doEvent(new SkipNoDrawable(playerUsername)); doEvent(new SkipTurn(playerUsername));
}
/**
* Used to draw a tribe card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalTribeCard(String playerUsername,int pos) {
doEvent(new PickOptionalTribeCard(playerUsername,pos));
}
/**
* Used to draw a building card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
* @param pos the index of the card to draw
*/
public void pickOptionalBuildingCard(String playerUsername,int pos) {
doEvent(new PickOptionalBuildingCard(playerUsername,pos));
}
/**
* Used to skip the action of drawing a card from the upper list.
* Available only if the player owns the building 12.
* @param playerUsername the name of the player performing the action
*/
public void noOptionalCard(String playerUsername) {
doEvent(new NoOptionalCard(playerUsername));
} }
@@ -4,8 +4,6 @@ import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.LimitedMap; import it.polimi.ingsw.gc14.LimitedMap;
import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.MiniModel; import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Network.ClientPlayer;
import it.polimi.ingsw.gc14.Network.EventType; import it.polimi.ingsw.gc14.Network.EventType;
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;
@@ -194,7 +194,7 @@ public class TUI implements IView {
lines.add(i+"."+model.availableTotems.get(i)); lines.add(i+"."+model.availableTotems.get(i));
} }
table.addRow(lines); table.addRow(lines);
System.out.println(model.currentState+"\nTOTEMS AVAILABLE:\n"+table.build()+"\nPress 9 and then write the position"); System.out.println(model.currentState+"\nTOTEMS AVAILABLE:\n"+table.build()+"\nPress 7 and then write the position");
} }
/** /**
@@ -248,15 +248,12 @@ public class TUI implements IView {
private String printMenuOptions() { private String printMenuOptions() {
var table = new AsciiTable(BorderStyle.ROUNDED, 2); var table = new AsciiTable(BorderStyle.ROUNDED, 2);
table.addHeader("Menu Options", "Render Options"); table.addHeader("Menu Options", "Render Options");
table.addRow(List.of("0-SlotChoice(pos)", "A-Full Render")); table.addRow(List.of("1-SlotChoice(pos)", "A-Full Render"));
table.addRow(List.of("1-DrawUpperTribe(pos)", "B-Board Render")); table.addRow(List.of("2-DrawUpperTribe(pos)", "B-Board Render"));
table.addRow(List.of("2-DrawUpperBuilding(pos)", "C-Players Render")); table.addRow(List.of("3-DrawUpperBuilding(pos)", "C-Players Render"));
table.addRow(List.of("3-DrawLowerTribe(pos)", "")); table.addRow(List.of("4-DrawLowerTribe(pos)", ""));
table.addRow(List.of("4-DrawLowerBuilding(pos)", "")); table.addRow(List.of("5-DrawLowerBuilding(pos)", ""));
table.addRow(List.of("5-PickOptionalTribe(pos)", "")); table.addRow(List.of("6-SkipTurn", ""));
table.addRow(List.of("6-PickOptionalBuilding(pos)", ""));
table.addRow(List.of("7-NoOptional", ""));
table.addRow(List.of("8-SkipTurn", ""));
return table.build(); return table.build();
} }
@@ -149,7 +149,7 @@ class GameControllerTest {
if (game.getCurrentState().getNUpper() == 0 if (game.getCurrentState().getNUpper() == 0
|| game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard)) { || game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard)) {
assertTrue(controller.SkipNoDrawable(username)); assertTrue(controller.SkipTurn(username));
return; return;
} }
} }
@@ -172,7 +172,7 @@ class GameControllerTest {
if (game.getCurrentState().getNLower() == 0 if (game.getCurrentState().getNLower() == 0
|| game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard)) { || game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard)) {
assertTrue(controller.SkipNoDrawable(username)); assertTrue(controller.SkipTurn(username));
return; return;
} }
} }
@@ -289,10 +289,10 @@ class GameControllerTest {
assertFalse(controller.drawLowerTribeCard("ghost", 0)); assertFalse(controller.drawLowerTribeCard("ghost", 0));
assertFalse(controller.drawUpperBuildingCard("ghost", 0)); assertFalse(controller.drawUpperBuildingCard("ghost", 0));
assertFalse(controller.drawLowerBuildingCard("ghost", 0)); assertFalse(controller.drawLowerBuildingCard("ghost", 0));
assertFalse(controller.SkipNoDrawable("ghost")); assertFalse(controller.SkipTurn("ghost"));
assertFalse(controller.pickOptionalTribeCard("ghost", 0)); assertFalse(controller.drawUpperTribeCard("ghost", 0));
assertFalse(controller.pickOptionalBuildingCard("ghost", 0)); assertFalse(controller.drawUpperBuildingCard("ghost", 0));
assertFalse(controller.noOptionalCard("ghost")); assertFalse(controller.SkipTurn("ghost"));
assertFalse(controller.TotemChoice("ghost", Totems.values()[0].name())); assertFalse(controller.TotemChoice("ghost", Totems.values()[0].name()));
assertFalse(controller.DisconnectedPlayer("ghost")); assertFalse(controller.DisconnectedPlayer("ghost"));
assertFalse(controller.ReconnectPlayer("ghost")); assertFalse(controller.ReconnectPlayer("ghost"));
@@ -505,8 +505,8 @@ class GameControllerTest {
String cur = game.getCurrentState().getCurrentPlayer().getUserName(); String cur = game.getCurrentState().getCurrentPlayer().getUserName();
assertFalse(controller.pickOptionalTribeCard(cur, 0)); assertFalse(controller.drawUpperTribeCard(cur, 0));
assertFalse(controller.pickOptionalBuildingCard(cur, 0)); assertFalse(controller.drawUpperBuildingCard(cur, 0));
} }
@Test @Test
@@ -530,7 +530,7 @@ class GameControllerTest {
int charactersBefore = optionalPlayer.getTotCharacters(); int charactersBefore = optionalPlayer.getTotCharacters();
assertTrue(controller.pickOptionalTribeCard(optionalPlayer.getUserName(), index)); assertTrue(controller.drawUpperTribeCard(optionalPlayer.getUserName(), index));
assertEquals(charactersBefore + 1, optionalPlayer.getTotCharacters()); assertEquals(charactersBefore + 1, optionalPlayer.getTotCharacters());
} }
@@ -558,7 +558,7 @@ class GameControllerTest {
int foodBefore = optionalPlayer.getFoodValue(); int foodBefore = optionalPlayer.getFoodValue();
int buildingsBefore = optionalPlayer.buildingCards.size(); int buildingsBefore = optionalPlayer.buildingCards.size();
assertTrue(controller.pickOptionalBuildingCard(optionalPlayer.getUserName(), 0)); assertTrue(controller.drawUpperBuildingCard(optionalPlayer.getUserName(), 0));
assertTrue(optionalPlayer.getFoodValue() <= foodBefore); assertTrue(optionalPlayer.getFoodValue() <= foodBefore);
assertEquals(buildingsBefore + 1, optionalPlayer.buildingCards.size()); assertEquals(buildingsBefore + 1, optionalPlayer.buildingCards.size());
@@ -625,7 +625,7 @@ class GameControllerTest {
assertTrue(optionalPlayer.buildingCards.stream() assertTrue(optionalPlayer.buildingCards.stream()
.anyMatch(building -> building.getEffectId() == 12)); .anyMatch(building -> building.getEffectId() == 12));
assertTrue(controller.noOptionalCard(optionalPlayer.getUserName())); assertTrue(controller.SkipTurn(optionalPlayer.getUserName()));
} }
@Test @Test
@@ -666,11 +666,11 @@ class GameControllerTest {
String username = optionalPlayer.getUserName(); String username = optionalPlayer.getUserName();
assertFalse(controller.pickOptionalTribeCard(username, -1)); assertFalse(controller.drawUpperTribeCard(username, -1));
assertFalse(controller.pickOptionalTribeCard(username, 999)); assertFalse(controller.drawUpperTribeCard(username, 999));
assertFalse(controller.pickOptionalBuildingCard(username, -1)); assertFalse(controller.drawUpperBuildingCard(username, -1));
assertFalse(controller.pickOptionalBuildingCard(username, 999)); assertFalse(controller.drawUpperBuildingCard(username, 999));
} }
@Test @Test
@@ -693,9 +693,9 @@ class GameControllerTest {
assertNotNull(wrongPlayer); assertNotNull(wrongPlayer);
assertFalse(controller.pickOptionalTribeCard(wrongPlayer.getUserName(), 0)); assertFalse(controller.drawUpperTribeCard(wrongPlayer.getUserName(), 0));
assertFalse(controller.pickOptionalBuildingCard(wrongPlayer.getUserName(), 0)); assertFalse(controller.drawUpperBuildingCard(wrongPlayer.getUserName(), 0));
assertFalse(controller.noOptionalCard(wrongPlayer.getUserName())); assertFalse(controller.SkipTurn(wrongPlayer.getUserName()));
} }
@Test @Test
@@ -714,7 +714,7 @@ class GameControllerTest {
assertFalse(game.getLowerListTribeCards().isEmpty()); assertFalse(game.getLowerListTribeCards().isEmpty());
assertTrue(firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1); assertTrue(firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1);
assertFalse(controller.SkipNoDrawable(current.getUserName())); assertFalse(controller.SkipTurn(current.getUserName()));
} }
@Test @Test
@@ -733,7 +733,7 @@ class GameControllerTest {
assertFalse(game.getUpperListTribeCards().isEmpty()); assertFalse(game.getUpperListTribeCards().isEmpty());
assertTrue(firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1); assertTrue(firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1);
assertFalse(controller.SkipNoDrawable(current.getUserName())); assertFalse(controller.SkipTurn(current.getUserName()));
} }
@@ -119,7 +119,7 @@ class GameTest {
if(game.getCurrentState().getNUpper() == 0 || game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard)) if(game.getCurrentState().getNUpper() == 0 || game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard))
{ {
assertTrue(game.SkipNoDrawable(current)); assertTrue(game.SkipTurn(current));
return; return;
} }
@@ -140,7 +140,7 @@ class GameTest {
if(game.getCurrentState().getNLower() == 0 || game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard)) if(game.getCurrentState().getNLower() == 0 || game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard))
{ {
assertTrue(game.SkipNoDrawable(current)); assertTrue(game.SkipTurn(current));
return; return;
} }
} }
@@ -177,7 +177,7 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current); assertNotNull(current);
assertTrue(game.NoOptionalCard(current)); assertTrue(game.SkipTurn(current));
} }
} }
@@ -578,7 +578,7 @@ class GameTest {
int charactersBefore = current.getTotCharacters(); int charactersBefore = current.getTotCharacters();
assertTrue(game.PickOptionalTribeCardByIndex(current, index)); assertTrue(game.DrawUpperTribeCardByIndex(current, index));
assertEquals(charactersBefore + 1, current.getTotCharacters()); assertEquals(charactersBefore + 1, current.getTotCharacters());
} }
@@ -616,7 +616,7 @@ class GameTest {
int upperBuildingsBefore = game.getUpperListBuilding().size(); int upperBuildingsBefore = game.getUpperListBuilding().size();
int foodBefore = current.getFoodValue(); int foodBefore = current.getFoodValue();
assertTrue(game.PickOptionalBuildingCard(current, 0)); assertTrue(game.DrawUpperBuildingCardByIndex(current, 0));
assertEquals(buildingsBefore + 1, current.buildingCards.size()); assertEquals(buildingsBefore + 1, current.buildingCards.size());
assertEquals(upperBuildingsBefore - 1, game.getUpperListBuilding().size()); assertEquals(upperBuildingsBefore - 1, game.getUpperListBuilding().size());
@@ -651,7 +651,7 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current); assertNotNull(current);
assertTrue(game.NoOptionalCard(current)); assertTrue(game.SkipTurn(current));
assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
assertNotEquals(current, game.getCurrentState().getCurrentPlayer()); assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
@@ -785,9 +785,9 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current); assertNotNull(current);
assertFalse(game.PickOptionalTribeCardByIndex(current, 0)); assertFalse(game.DrawUpperTribeCardByIndex(current, 0));
assertFalse(game.PickOptionalBuildingCard(current, 0)); assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
assertFalse(game.NoOptionalCard(current)); assertFalse(game.SkipTurn(current));
} }
@Test @Test
@@ -806,15 +806,15 @@ class GameTest {
Player wrongPlayer = current.equals(players.get(0)) ? players.get(1) : players.get(0); Player wrongPlayer = current.equals(players.get(0)) ? players.get(1) : players.get(0);
assertFalse(game.PickOptionalTribeCardByIndex(wrongPlayer, 0)); assertFalse(game.DrawUpperTribeCardByIndex(wrongPlayer, 0));
assertFalse(game.PickOptionalBuildingCard(wrongPlayer, 0)); assertFalse(game.DrawUpperBuildingCardByIndex(wrongPlayer, 0));
assertFalse(game.NoOptionalCard(wrongPlayer)); assertFalse(game.SkipTurn(wrongPlayer));
assertFalse(game.PickOptionalTribeCardByIndex(current, -1)); assertFalse(game.DrawUpperTribeCardByIndex(current, -1));
assertFalse(game.PickOptionalTribeCardByIndex(current, 999)); assertFalse(game.DrawUpperTribeCardByIndex(current, 999));
assertFalse(game.PickOptionalBuildingCard(current, -1)); assertFalse(game.DrawUpperBuildingCardByIndex(current, -1));
assertFalse(game.PickOptionalBuildingCard(current, 999)); assertFalse(game.DrawUpperBuildingCardByIndex(current, 999));
} }
@@ -949,7 +949,7 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertNotNull(current); assertNotNull(current);
assertTrue(game.NoOptionalCard(current)); assertTrue(game.SkipTurn(current));
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage()); assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
assertEquals(roundBefore + 1, game.getCurrentState().getRound()); assertEquals(roundBefore + 1, game.getCurrentState().getRound());
@@ -1009,7 +1009,7 @@ class GameTest {
"There must be at least one upper building card to test that the player cannot buy it." "There must be at least one upper building card to test that the player cannot buy it."
); );
assertFalse(game.PickOptionalBuildingCard(current, 0)); assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
} }
@Test @Test
@@ -1228,7 +1228,7 @@ class GameTest {
.findFirst() .findFirst()
.orElseThrow(); .orElseThrow();
assertFalse(game.SkipNoDrawable(wrongPlayer)); assertFalse(game.SkipTurn(wrongPlayer));
} }
@Test @Test
@@ -1255,7 +1255,7 @@ class GameTest {
"The test requires at least one drawable tribe card." "The test requires at least one drawable tribe card."
); );
assertFalse(game.SkipNoDrawable(current)); assertFalse(game.SkipTurn(current));
} }
@Test @Test
@@ -1282,7 +1282,7 @@ class GameTest {
int charactersBefore = current.getTotCharacters(); int charactersBefore = current.getTotCharacters();
int upperSizeBefore = game.getUpperListTribeCards().size(); int upperSizeBefore = game.getUpperListTribeCards().size();
assertFalse(game.PickOptionalTribeCardByIndex(current, eventIndex)); assertFalse(game.DrawUpperTribeCardByIndex(current, eventIndex));
assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
assertEquals(current, game.getCurrentState().getCurrentPlayer()); assertEquals(current, game.getCurrentState().getCurrentPlayer());
@@ -1352,7 +1352,7 @@ class GameTest {
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage()); assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
assertFalse(game.SkipNoDrawable(current)); assertFalse(game.SkipTurn(current));
} }
@Test @Test