コード例 #1
0
    protected void UpdateStateSwitch()
    {
        switch (thisPlayerState)
        {
        case State.eActivated:
        {
            /* this state contains one time things before the turn really starts*/

            // check if all cards are flipped
            CheckClickableCards();

            // allow player to click
            thisCanClickCards = true;

            // prevent player from having one more turn
            thisOneMoreRoundAllowed = false;

            thisPlayerState = State.eZeroSelected;
        }
        break;

        // eZero and eOne are supposed to be empty because they just wait
        case State.eZeroSelected:
        {
        }
        break;

        case State.eOneSelected:
        {
        }
        break;

        case State.eTwoSelected:
        {
            // when timer goes off, cards will be flipped back
            thisStateTimer -= Time.deltaTime;

            if (thisStateTimer < 0)
            {
                // check pairs
                CheckSelectedPairs();

                // empty selection
                ClearSelection();

                // reset time for display
                InitializeStateTimer();

                if (thisOneMoreRoundAllowed)
                {
                    // player turn start again
                    StartPlayerTurn();
                    //print("player now has one more round\n");
                    return;
                }
                else
                {
                    if (thisIsNowLerpingToShuffle)
                    {
                        thisUiManager.UpdateShuffling();
                        thisPlayerState = State.eWaitDuringLerping;
                        return;
                    }
                    else
                    {
                        // switch to idle state because the npc's turn is about to start
                        thisPlayerState = State.eIdle;
                        thisNpcBehavior.StartNpcTurn();
                    }
                }
            }
        }
        break;

        case State.eWaitDuringLerping:
        {
            // wait for the lerping to end, and switch state
            if (!thisIsNowLerpingToShuffle)
            {
                thisPlayerState = State.eIdle;
                thisNpcBehavior.StartNpcTurn();
            }
        }
        break;

        case State.eIdle:
        {
            // doing nothing
        }
        break;
        }
    }
コード例 #2
0
    protected void UpdateStateSwitch()
    {
        switch (thisNpcState)
        {
        case State.eIdle:
        {
        }
        break;

        case State.eActivated:
        {
            /* this state is an interrim wake state
             * that completes some one-time things before selection*/

            //thisUiManager.StopAnySlash(thisPlayerBehavior.gameObject);

            thisUiManager.ToggleAllCardsEmittable(false);

            // once activated, update clickable list first
            UpdateClickableList();

            // prevent player from having another turn
            thisOneMoreRoundAllowed = false;
            thisNpcState            = State.eZeroSelected;
        }
        break;

        case State.eZeroSelected:
        {
            if (!thisGameHasEnded)
            {
                thisStateTimer -= Time.deltaTime;

                if (thisStateTimer < 0)
                {
                    RandomlyFlipOneCard();
                    InitializeStateTimer();
                    thisNpcState = State.eOneSelected;

                    return;
                }

                if (thisStateTimer < thisActionLag / 2)
                {
                    // during half of the action lag, update the turn prompt
                    thisUiManager.UpdateNpcTurn();

                    // makes all cards emittable when cursor hovered on cards
                    //thisUiManager.MakeAllCardsEmittable();

                    return;
                }
            }
        }
        break;

        case State.eOneSelected:
        {
            thisStateTimer -= Time.deltaTime;

            if (thisStateTimer < 0)
            {
                // check if cards in memory are flippable
                // note: current this assumes that there must be two cards in memory, not considering time countdown
                // this also assumes that the two in memory should be the same in flippability
                // note: the public method returns if the card has been flipped; true means it is not flippable
                bool oneFlipped     = thisMemoryList[0].GetComponent <CardScript>().GetIfCardHasBeenFlipped();
                bool anotherFlipped = thisMemoryList[1].GetComponent <CardScript>().GetIfCardHasBeenFlipped();

                // if they are both flippable, they must be different from each other
                if (!oneFlipped && !anotherFlipped)
                {
                    if (CheckIfTwoTilesAreTheSame(thisMemoryList[0], thisSelectionList[0]))
                    {
                        // if the first one in memory matches the already selected one
                        // add the one in the memory as the second selected one so that they can match
                        FlipTheParticularCard(thisMemoryList[0]);
                        //print("Npc flipped the matched one" + thisMemoryList[0].name +" \n");

                        // reset timer
                        InitializeStateTimerToDisplayDuration();

                        UpdateMemoryFromSelfSelection();
                        // switch to next state
                        thisNpcState = State.eTwoSelected;
                    }
                    else if (CheckIfTwoTilesAreTheSame(thisMemoryList[1], thisSelectionList[0]))
                    {
                        FlipTheParticularCard(thisMemoryList[1]);
                        //print("Npc flipped the matched one" + thisMemoryList[1].name + " \n");
                        InitializeStateTimerToDisplayDuration();
                        UpdateMemoryFromSelfSelection();
                        thisNpcState = State.eTwoSelected;
                    }
                    else
                    {
                        RandomlyFlipOneCard();
                        //print("Npc flipped another random one\n");
                        InitializeStateTimerToDisplayDuration();
                        UpdateMemoryFromSelfSelection();
                        thisNpcState = State.eTwoSelected;
                    }
                }
                else
                {
                    RandomlyFlipOneCard();
                    //print("Npc flipped another random one\n");
                    InitializeStateTimerToDisplayDuration();
                    UpdateMemoryFromSelfSelection();
                    thisNpcState = State.eTwoSelected;
                }
            }
        }
        break;

        case State.eTwoSelected:
        {
            // when timer goes off, cards will be flipped back
            thisStateTimer -= Time.deltaTime;

            if (thisStateTimer < 0)
            {
                // check pairs
                CheckSelectedPairs();

                ClearSelection();

                if (thisOneMoreRoundAllowed)
                {
                    StartNpcTurn();
                    InitializeStateTimer();
                    return;
                }
                else
                {
                    if (thisIsNowLerpingToShuffle)
                    {
                        thisNpcState = State.eWaitDuringLerping;
                        // make prompt to indicate shuffling
                        thisUiManager.UpdateShuffling();
                        return;
                    }
                    else
                    {
                        // makes all cards emittable when cursor hovered on cards
                        thisUiManager.ToggleAllCardsEmittable(true);

                        thisNpcState = State.eIdle;
                        thisPlayerBehavior.StartPlayerTurn();
                        InitializeStateTimer();
                    }
                }
            }
        }
        break;

        case State.eWaitDuringLerping:
        {
            if (!thisIsNowLerpingToShuffle)
            {
                // makes all cards emittable when cursor hovered on cards
                thisUiManager.ToggleAllCardsEmittable(true);

                thisNpcState = State.eIdle;
                thisPlayerBehavior.StartPlayerTurn();
                InitializeStateTimer();
            }
        }
        break;
        }
    }