Removed: PickOptionalTribeCard and PickOptionalBuildingCard in Game and GameController
This commit is contained in:
@@ -142,54 +142,14 @@ public class GameController {
|
||||
* @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.
|
||||
*/
|
||||
public boolean SkipNoDrawable(String playerUsername) {
|
||||
public boolean SkipTurn(String playerUsername) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
if(player==null)
|
||||
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.
|
||||
|
||||
@@ -411,11 +411,12 @@ public class Game implements Serializable {
|
||||
* @param player the player performing the draw.
|
||||
* @param cardIndex the index of the upper tribe card to draw.
|
||||
* @return {@code true} if the draw succeeds, {@code false} otherwise.
|
||||
* TODO
|
||||
*/
|
||||
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -423,7 +424,7 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(currentState.getNUpper() <1)
|
||||
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
return false;
|
||||
TribeCard tribeCard = board.upperListTribe.get(cardIndex);
|
||||
if(tribeCard.IsEventCard())
|
||||
@@ -432,9 +433,17 @@ public class Game implements Serializable {
|
||||
Character tempCard = (Character) tribeCard;
|
||||
tempCard.insert(player);
|
||||
board.removeUpperTribeCard(tempCard);
|
||||
currentState.UpperDrawn();
|
||||
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
|
||||
if(currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
{
|
||||
currentState.UpperDrawn();
|
||||
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
|
||||
nextPlayerSetup();
|
||||
}
|
||||
else
|
||||
{
|
||||
nextPlayerSetup();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -447,8 +456,8 @@ public class Game implements Serializable {
|
||||
* @param player the player skipping the turn .
|
||||
* @return {@code true} if the skip succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean SkipNoDrawable(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
public boolean SkipTurn(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -456,15 +465,21 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(hasDrawableDown() && currentState.getNLower()>0 )
|
||||
return false;
|
||||
if(hasDrawableUp() && currentState.getNUpper()>0)
|
||||
return false;
|
||||
while(currentState.getNLower()>0)
|
||||
currentState.LowerDrawn();
|
||||
while(currentState.getNUpper()>0)
|
||||
currentState.UpperDrawn();
|
||||
nextPlayerSetup();
|
||||
if(currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
{
|
||||
if(hasDrawableDown() && currentState.getNLower()>0 )
|
||||
return false;
|
||||
if(hasDrawableUp() && currentState.getNUpper()>0)
|
||||
return false;
|
||||
while(currentState.getNLower()>0)
|
||||
currentState.LowerDrawn();
|
||||
while(currentState.getNUpper()>0)
|
||||
currentState.UpperDrawn();
|
||||
nextPlayerSetup();
|
||||
}
|
||||
else {
|
||||
nextPlayerSetup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -525,7 +540,7 @@ public class Game implements Serializable {
|
||||
public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -534,18 +549,23 @@ public class Game implements Serializable {
|
||||
return false;
|
||||
}
|
||||
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
|
||||
if(currentState.getNUpper() <1)
|
||||
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
|
||||
return false;
|
||||
if(buildingCard.buy(player))
|
||||
if(!buildingCard.buy(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
board.removeUpperBuildingCard(buildingCard);
|
||||
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS))
|
||||
{
|
||||
currentState.UpperDrawn();
|
||||
board.removeUpperBuildingCard(buildingCard);
|
||||
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
|
||||
nextPlayerSetup();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
|
||||
{
|
||||
nextPlayerSetup();
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -594,98 +614,6 @@ public class Game implements Serializable {
|
||||
|
||||
//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
|
||||
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
|
||||
@@ -28,7 +27,7 @@ public class NoOptionalCard extends NetworkEvent implements Serializable{
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.noOptionalCard(username);
|
||||
return gameController.SkipTurn(username);
|
||||
}
|
||||
//TODO
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ 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;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class PickOptionalBuildingCard extends NetworkEvent implements Serializa
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.pickOptionalBuildingCard(username, pos);
|
||||
return gameController.drawUpperBuildingCard(username, pos);
|
||||
}
|
||||
//TODO
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class PickOptionalTribeCard extends NetworkEvent implements Serializable
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.pickOptionalTribeCard(username, pos);
|
||||
return gameController.drawUpperTribeCard(username, pos);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SkipNoDrawable extends NetworkEvent implements Serializable{
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.SkipNoDrawable(username);
|
||||
return gameController.SkipTurn(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
Reference in New Issue
Block a user