/// <summary> /// Determines the type of action to perform and calls the correct method to perform it /// </summary> /// <param name="lastState">The state previous to the current state.</param> /// <param name="currentState">The current state.</param> /// <param name="nextState">A reference for the next state</param> /// <param name="playerPerformingAction">The Guid of the player who is performing the action.</param> /// <param name="typeOfActionToPerform">The type of action the player is performing.</param> /// <param name="justSayNoAble">The StatePhase the state should be if the action is performed and is able to be Just Say No'd</param> /// <param name="notJustSayNoAble">The StatePhase the state should be if the action is performed and is not able to be Just Say No'd</param> /// <param name="rearrangeProperties">The StatePhase the state should be if the action is performed is to move properties between sets</param> /// <param name="drawCardsAtTurnStart">The StatePhase the state should be if the action is performed is to draw cards at the start of a turn</param> /// <param name="JustSayNoUsedByOpposition">The StatePhase the state should be if the action is performed and is a player using a Just Say No card against an Action Card affecting them played by the player who is on their turn</param> /// <param name="moveInformation">The MoveInfo containing the information required to perform the action.</param> /// <param name="discard">The StatePhase the state should be if the action is performed is to end a turn and the player has to discard cards</param> /// <returns></returns> private BoolResponseBox doAppropriateAction(PlayFieldModel lastState, PlayFieldModel currentState, PlayFieldModel nextState, PlayerModel playerPerformingAction, TurnActionTypes typeOfActionToPerform, Statephase justSayNoAble, Statephase notJustSayNoAble, Statephase rearrangeProperties, Statephase drawCardsAtTurnStart, Statephase JustSayNoUsedByOpposition, MoveInfo moveInformation, Statephase discard) { if (typeOfActionToPerform.CompareTo(TurnActionTypes.drawTwoCardsAtStartOfTurn) == 0) { return draw2CardsAtStartOfTurn(currentState, nextState, playerPerformingAction, drawCardsAtTurnStart); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.drawFiveCardsAtStartOfTurn) == 0) { return draw5CardsAtStartOfTurn(currentState, nextState, playerPerformingAction, drawCardsAtTurnStart); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.EndTurn) == 0) { return endTurn(currentState, nextState, playerPerformingAction); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.MovePropertyCard) == 0) { return movePropertyCard(currentState, nextState, playerPerformingAction, moveInformation, rearrangeProperties); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.PlayPropertyCardFromHand) == 0) { return playPropertyCardFromHand(currentState, nextState, playerPerformingAction, moveInformation, notJustSayNoAble); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { return playPropertyCardFromHandToNewSet(currentState, nextState, playerPerformingAction, moveInformation, notJustSayNoAble); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.BankActionCard) == 0) { return playCardFromHandToBank(currentState, nextState, playerPerformingAction, moveInformation, notJustSayNoAble); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.BankMoneyCard) == 0) { return playCardFromHandToBank(currentState, nextState, playerPerformingAction, moveInformation, notJustSayNoAble); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { return discard1Card(currentState, nextState, playerPerformingAction, moveInformation, discard); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.PayDebt) == 0) { return payDebt(currentState, nextState, playerPerformingAction, moveInformation, justSayNoAble, notJustSayNoAble); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.Dont_Play_Just_Say_No) == 0) { return doNotPlayJustSayNo(currentState, nextState, playerPerformingAction, moveInformation, justSayNoAble, notJustSayNoAble); } //ActionCards else if (typeOfActionToPerform.CompareTo(TurnActionTypes.PlayActionCard) == 0 || typeOfActionToPerform.CompareTo(TurnActionTypes.PlayCard) == 0) { if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.PassGo) == 0) { Statephase nextStatePhase = notJustSayNoAble; return playActionCardPassGo(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.DebtCollector) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardDebtCollector(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.ItsMyBirthday) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardItsMyBirthday(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.JustSayNo) == 0) { Statephase nextStatePhase = notJustSayNoAble;//TODO switch to justsaynoable return playActionCardJustSayNo(currentState, nextState, playerPerformingAction, nextStatePhase, justSayNoAble, JustSayNoUsedByOpposition, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.RentMultiColor) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardRentMultiColor(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.RentStandard) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardRentStandard(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.SlyDeal) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardSlyDeal(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.ForcedDeal) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardForcedDeal(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.DealBreaker) == 0) { Statephase nextStatePhase = justSayNoAble; return playActionCardDealBreaker(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.House) == 0) { Statephase nextStatePhase = notJustSayNoAble; return playActionCardHouse(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } else if (moveInformation.actionCardActionType.CompareTo(ActionCardAction.Hotel) == 0) { Statephase nextStatePhase = notJustSayNoAble; return playActionCardHotel(currentState, nextState, playerPerformingAction, nextStatePhase, moveInformation); } throw new NotImplementedException(); } else if (typeOfActionToPerform.CompareTo(TurnActionTypes.PlayJustSayNo) == 0) { Statephase nextStatePhase = notJustSayNoAble;//should be just say noable return playActionCardJustSayNo(currentState, nextState, playerPerformingAction, nextStatePhase, justSayNoAble, JustSayNoUsedByOpposition, moveInformation); } else { return new BoolResponseBox(false, "Unsupported action:" + typeOfActionToPerform.ToString()); } }
private void updateState(TurnActionTypes actionToAttemptToPerform, ActionCardAction actionCardType, PlayFieldModel currentState, Guid playerWhoPerformedAction) { PlayerModel player = getPlayerByGuid(playerWhoPerformedAction, currentState); PlayFieldModel newState = copyPlayFieldModel(currentState); //List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); //List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); #region draw2state //draw 2 on turn start state if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Draw_2_Cards) == 0) { if (actionToAttemptToPerform.CompareTo(TurnActionTypes.drawTwoCardsAtStartOfTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_0_Cards_Played; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } } #endregion draw2state #region draw5state //draw 5 on turn start state else if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Draw_5_Cards) == 0) { if (actionToAttemptToPerform.CompareTo(TurnActionTypes.drawFiveCardsAtStartOfTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_0_Cards_Played; //player has drawn their five cards as they started the turn with zero cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } } #endregion draw5state #region Turn_Started_Cards_Drawn_0_Cards_Played //draw 2 on turn start state else if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Cards_Drawn_0_Cards_Played) == 0) { #region bankActionCard if (actionToAttemptToPerform.CompareTo(TurnActionTypes.BankActionCard) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_1_Cards_Played; //player has drawn their two cards, Now can play up to three cards on their turn on List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion bankActionCard #region endTurn else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.EndTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase switch (player.hand.cardsInHand.Count) { case 8: { newState.currentPhase = Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 9: { newState.currentPhase = Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 10: { newState.currentPhase = Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 11: { newState.currentPhase = Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 12: { newState.currentPhase = Statephase.Turn_Ended_12_Cards_In_Hand_Discard_5_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } default: { newState.currentPhase = Statephase.Turn_Ended_7_Or_Less_Cards_In_Hand_Setup_NextPlayer; setNextPlayerOnTurn(newState); if (getPlayerByGuid(newState.guidOfPlayerWhosTurnItIs, newState).hand.cardsInHand.Count == 0) { //Player has 0 cards draws 5 on turn start instead of 2 newState.currentPhase = Statephase.Turn_Started_Draw_5_Cards; onTurn.Add(TurnActionTypes.drawFiveCardsAtStartOfTurn); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } else { newState.currentPhase = Statephase.Turn_Started_Draw_2_Cards; onTurn.Add(TurnActionTypes.drawTwoCardsAtStartOfTurn); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } break; } } updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion endTurn #region playPropertyToNewSet else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); //updateStateForPropertyPlayedToSet(actionToAttemptToPerform, currentState, playerWhoPerformedAction, player, newState); //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_1_Cards_Played; updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion playPropertyToNewSet //Play Action #region Actions unable to be just say no carded #region pass Go else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayActionCard) == 0 && actionCardType.CompareTo(ActionCardAction.PassGo) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_1_Cards_Played; updateStateActionCardPassGo(actionToAttemptToPerform, currentState, playerWhoPerformedAction, player, newState); } } #endregion pass Go #endregion Actions unable to be just say no carded } #endregion Turn_Started_Cards_Drawn_0_Cards_Played #region Turn_Started_Cards_Drawn_1_Cards_Played else if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Cards_Drawn_1_Cards_Played) == 0) { #region bankActionCard if (actionToAttemptToPerform.CompareTo(TurnActionTypes.BankActionCard) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_2_Cards_Played; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion bankActionCard #region endTurn else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.EndTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase switch (player.hand.cardsInHand.Count) { case 8: { newState.currentPhase = Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 9: { newState.currentPhase = Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 10: { newState.currentPhase = Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 11: { newState.currentPhase = Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 12: { newState.currentPhase = Statephase.Turn_Ended_12_Cards_In_Hand_Discard_5_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } default: { newState.currentPhase = Statephase.Turn_Ended_7_Or_Less_Cards_In_Hand_Setup_NextPlayer; setNextPlayerOnTurn(newState); if (getPlayerByGuid(newState.guidOfPlayerWhosTurnItIs, newState).hand.cardsInHand.Count == 0) { //Player has 0 cards draws 5 on turn start instead of 2 newState.currentPhase = Statephase.Turn_Started_Draw_5_Cards; onTurn.Add(TurnActionTypes.drawFiveCardsAtStartOfTurn); } else { newState.currentPhase = Statephase.Turn_Started_Draw_2_Cards; onTurn.Add(TurnActionTypes.drawTwoCardsAtStartOfTurn); } break; } } updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion endTurn #region playPropertyToNewSet else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); //updateStateForPropertyPlayedToSet(actionToAttemptToPerform, currentState, playerWhoPerformedAction, player, newState); //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_2_Cards_Played; updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion playPropertyToNewSet //Play Action #region Actions unable to be just say no carded #region pass Go else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayActionCard) == 0 && actionCardType.CompareTo(ActionCardAction.PassGo) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_2_Cards_Played; updateStateActionCardPassGo(actionToAttemptToPerform, currentState, playerWhoPerformedAction, player, newState); } } #endregion pass Go #endregion Actions unable to be just say no carded } #endregion Turn_Started_Cards_Drawn_1_Cards_Played #region Turn_Started_Cards_Drawn_2_Cards_Played else if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Cards_Drawn_2_Cards_Played) == 0) { //Actions that can be taken on this phase #region bankActionCard if (actionToAttemptToPerform.CompareTo(TurnActionTypes.BankActionCard) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn.Add(TurnActionTypes.SwitchAroundPlayedProperties); onTurn.Add(TurnActionTypes.EndTurn); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion bankActionCard #region endTurn else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.EndTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase switch (player.hand.cardsInHand.Count) { case 8: { newState.currentPhase = Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 9: { newState.currentPhase = Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 10: { newState.currentPhase = Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 11: { newState.currentPhase = Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 12: { newState.currentPhase = Statephase.Turn_Ended_12_Cards_In_Hand_Discard_5_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } default: { newState.currentPhase = Statephase.Turn_Ended_7_Or_Less_Cards_In_Hand_Setup_NextPlayer; setNextPlayerOnTurn(newState); if (getPlayerByGuid(newState.guidOfPlayerWhosTurnItIs, newState).hand.cardsInHand.Count == 0) { //Player has 0 cards draws 5 on turn start instead of 2 newState.currentPhase = Statephase.Turn_Started_Draw_5_Cards; onTurn.Add(TurnActionTypes.drawFiveCardsAtStartOfTurn); } else { newState.currentPhase = Statephase.Turn_Started_Draw_2_Cards; onTurn.Add(TurnActionTypes.drawTwoCardsAtStartOfTurn); } break; } } updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion endTurn #region playPropertyToNewSet else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn.Add(TurnActionTypes.SwitchAroundPlayedProperties); onTurn.Add(TurnActionTypes.EndTurn); //onTurn = setAllowableActionsOnTurn(onTurn, newState); //updateStateForPropertyPlayedToSet(actionToAttemptToPerform, currentState, playerWhoPerformedAction, player, newState); //Change phase newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only; updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion playPropertyToNewSet //Play Action #region Actions unable to be just say no carded #region pass Go else if (actionToAttemptToPerform.CompareTo(TurnActionTypes.PlayActionCard) == 0 && actionCardType.CompareTo(ActionCardAction.PassGo) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn.Add(TurnActionTypes.SwitchAroundPlayedProperties); onTurn.Add(TurnActionTypes.EndTurn); newState.currentPhase = Statephase.Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only; updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion pass Go #endregion Actions unable to be just say no carded } #endregion Turn_Started_Cards_Drawn_2_Cards_Played #region Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only //draw 2 on turn start state else if (currentState.currentPhase.CompareTo(Statephase.Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only) == 0) { #region endTurn if (actionToAttemptToPerform.CompareTo(TurnActionTypes.EndTurn) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase switch (player.hand.cardsInHand.Count) { case 8: { newState.currentPhase = Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card; onTurn.Add(TurnActionTypes.Discard_1_Card); break; } case 9: { newState.currentPhase = Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card); //Replace with Discard_2_Cards when discarding 2 cards at a time is supported break; } case 10: { newState.currentPhase = Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card);//Replace with Discard_3_Cards when discarding 2 cards at a time is supported break; } case 11: { newState.currentPhase = Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card);//Replace with Discard_4_Cards when discarding 2 cards at a time is supported break; } case 12: { newState.currentPhase = Statephase.Turn_Ended_12_Cards_In_Hand_Discard_5_Cards; onTurn.Add(TurnActionTypes.Discard_1_Card);//Replace with Discard_5_Cards when discarding 2 cards at a time is supported break; } default: { newState.currentPhase = Statephase.Turn_Ended_7_Or_Less_Cards_In_Hand_Setup_NextPlayer; setNextPlayerOnTurn(newState); if (getPlayerByGuid(newState.guidOfPlayerWhosTurnItIs, newState).hand.cardsInHand.Count == 0) { //Player has 0 cards draws 5 on turn start instead of 2 newState.currentPhase = Statephase.Turn_Started_Draw_5_Cards; onTurn.Add(TurnActionTypes.drawFiveCardsAtStartOfTurn); } else { newState.currentPhase = Statephase.Turn_Started_Draw_2_Cards; onTurn.Add(TurnActionTypes.drawTwoCardsAtStartOfTurn); } break; } } updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion endTurn //Play Action } #endregion Turn_Started_Cards_Drawn_3_Cards_Played_Swap_Properties_Or_End_Turn_Only #region Turn_Ended_12_Cards_In_Hand_Discard_5_Cards else if (currentState.currentPhase.CompareTo(Statephase.Turn_Ended_12_Cards_In_Hand_Discard_5_Cards) == 0) { #region discard1Card if (actionToAttemptToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion discard1Card } #endregion Turn_Ended_12_Cards_In_Hand_Discard_5_Cards #region Turn_Ended_11_Cards_In_Hand_Discard_4_Cards else if (currentState.currentPhase.CompareTo(Statephase.Turn_Ended_11_Cards_In_Hand_Discard_4_Cards) == 0) { #region discard1Card if (actionToAttemptToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion discard1Card } #endregion Turn_Ended_11_Cards_In_Hand_Discard_4_Cards #region Turn_Ended_10_Cards_In_Hand_Discard_3_Cards else if (currentState.currentPhase.CompareTo(Statephase.Turn_Ended_10_Cards_In_Hand_Discard_3_Cards) == 0) { #region discard1Card if (actionToAttemptToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion discard1Card } #endregion Turn_Ended_10_Cards_In_Hand_Discard_3_Cards #region Turn_Ended_9_Cards_In_Hand_Discard_2_Cards else if (currentState.currentPhase.CompareTo(Statephase.Turn_Ended_9_Cards_In_Hand_Discard_2_Cards) == 0) { #region discard1Card if (actionToAttemptToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { //Move was a valid move at current state //Check if move is valid for player if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card; //player has drawn their two cards, Now can play up to three cards on their turn List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion discard1Card } #endregion Turn_Ended_9_Cards_In_Hand_Discard_2_Cards #region Turn_Ended_8_Cards_In_Hand_Discard_1_Card else if (currentState.currentPhase.CompareTo(Statephase.Turn_Ended_8_Cards_In_Hand_Discard_1_Card) == 0) { #region discard1Card if (actionToAttemptToPerform.CompareTo(TurnActionTypes.Discard_1_Card) == 0) { //Move was a valid move at current state //Check if move is valid for player List<TurnActionTypes> notOnTurn = new List<TurnActionTypes>(); List<TurnActionTypes> onTurn = new List<TurnActionTypes>(); if (isActionAllowedForPlayer(actionToAttemptToPerform, playerWhoPerformedAction, currentState)) { //action is valid for player at this time //Could perform the action here instead, for now just change the phase of the state //Not an action so cant be just say no'd //Change phase newState.currentPhase = Statephase.Turn_Ended_7_Or_Less_Cards_In_Hand_Setup_NextPlayer; setNextPlayerOnTurn(newState); if (getPlayerByGuid(newState.guidOfPlayerWhosTurnItIs, newState).hand.cardsInHand.Count == 0) { //Player has 0 cards draws 5 on turn start instead of 2 newState.currentPhase = Statephase.Turn_Started_Draw_5_Cards; onTurn.Add(TurnActionTypes.drawFiveCardsAtStartOfTurn); } else { newState.currentPhase = Statephase.Turn_Started_Draw_2_Cards; onTurn.Add(TurnActionTypes.drawTwoCardsAtStartOfTurn); } //player has drawn their two cards, Now can play up to three cards on their turn //onTurn = setAllowableActionsOnTurn(onTurn, newState); updateAllowableStates(newState, notOnTurn, onTurn, newState.guidOfPlayerWhosTurnItIs); } } #endregion discard1Card } #endregion Turn_Ended_8_Cards_In_Hand_Discard_1_Card }
public bool doAction(Guid gameGuid, Guid playerGuid, Guid gameStateActionShouldBeAppliedOnGuid, TurnActionTypes actionType) { ///Returns false if action not carried out /// //Get CurrentPlayFieldModelState currentPlayFieldModel = getCurrentPlayFieldModel(); if (checkIfActionIsForThisState(actionType, gameStateActionShouldBeAppliedOnGuid, playerGuid, gameGuid)) { if (actionType.CompareTo(TurnActionTypes.drawTwoCardsAtStartOfTurn) == 0) { drawTwoCardsAtTurnStart(getPlayerByGuid(playerGuid, currentPlayFieldModel)); } if (actionType.CompareTo(TurnActionTypes.drawFiveCardsAtStartOfTurn) == 0) { drawFiveCards(getPlayerByGuid(playerGuid, currentPlayFieldModel)); } if (actionType.CompareTo(TurnActionTypes.EndTurn) == 0) { endTurn(getPlayerByGuid(playerGuid, currentPlayFieldModel), gameStateActionShouldBeAppliedOnGuid); } if (actionType.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { //playPropertyCardToNewSet(getPlayerByGuid(playerGuid, currentPlayFieldModel)); } //turn action is for this playfieldmodel } return true; throw new NotImplementedException(); }
public bool playPropertyCardToNewSet(Guid gameGuid, bool isOrientedUp, Guid playerGuid, Guid gameStateActionShouldBeAppliedOnGuid, TurnActionTypes actionType, int propertyCardID) { //Get CurrentPlayFieldModelState currentPlayFieldModel = getCurrentPlayFieldModel(); PlayerModel player = getPlayerByGuid(playerGuid, currentPlayFieldModel); if (checkIfActionIsForThisState(actionType, gameStateActionShouldBeAppliedOnGuid, playerGuid, gameGuid)) { if (actionType.CompareTo(TurnActionTypes.PlayPropertyCard_New_Set) == 0) { foreach (Card c in player.hand.cardsInHand) { if (c.cardID == propertyCardID && c is PropertyCard) { Card card = removeCardFromHand(c, player); if (card != null) { PropertyCard cP = c as PropertyCard; PropertyCardSet ps = new PropertyCardSet(cP); cP.setPropertyColor(isOrientedUp); player.propertySets.addSet(ps); updateState(TurnActionTypes.PlayPropertyCard_New_Set, ActionCardAction.NotAnActionCard, currentPlayFieldModel, player.guid); return true; } } } } } return false; }