Esempio n. 1
0
    //Function to move the token step by step based on the number appeared on the dice.
    IEnumerator IMoveToken()
    {
        yield return(new WaitForSeconds(.25f));

        mNumberGot = GameManagerScript.mGameManager.mNumberGot;
        if (mNumberGot == 6 && mIsReadyToMove == false)
        {
            //This is condition to move the token from Initial position to the first position.
            //mMoveToFirstPosition = true;
            transform.DOMove(mPath[1].transform.position, 1f).SetEase(Ease.InOutQuad).OnComplete(ShakeToken);
            GameManagerScript.mGameManager.mGreenPlayerOut++;
            GameManagerScript.mGameManager.mTokenClicked = false;
            mStartingPosition = true;
            mNumberGot        = 2;
            mPositionMoved    = 2;
            mFlag             = 1;
            mIsReadyToMove    = true;
            mAnotherChance    = true;
            mTokenMoved       = false;
            mTokenOut         = true;
        }
        else if (mIsReadyToMove && mNumberGot <= 6 && GameManagerScript.mGameManager.mRolledDice.CompareTag("Green"))
        {
            //Checking whether number appeared on the dice is less than the number of steps remaining.
            //If not shift the turn to the next player.
            mChildObject.SetActive(false);
            mMoveToFirstPosition = false;
            if (mNumberGot <= mNumberOfStepsRemaining)
            {
                GameManagerScript.mGameManager.mCanClick = false;
                for (int i = mNumberOfStepsMoved; i < (mNumberGot + mNumberOfStepsMoved); i++)
                {
                    transform.DOMove(mPath[i].transform.position, .1f).SetEase(Ease.InOutQuad);
                    SoundManagerScript.PlaySound("Move");
                    GameManagerScript.mGameManager.mTokenMoving = true;
                    mGreenTokenMoving = true;
                    yield return(new WaitForSeconds(.25f));

                    mLastPosition  += 1;
                    mPositionMoved += 1;
                    mTokenPosition  = i;
                }
                mGreenTokenMoving = false;
                GameManagerScript.mGameManager.mTokenMoving = false;
                if (mTokenPosition != 57 && mNumberGot == 6)
                {
                    //This is a condition to check whether a player got 6.
                    //If so he will get another chance to roll the dice.
                    mAnotherChance = true;
                    GameManagerScript.mGameManager.mCanClick = true;
                    mGreenCanMove = true;
                    mTokenMoved   = false;
                }
                else if (mTokenPosition == 57)
                {
                    gameObject.transform.localScale = new Vector2(0.1f, 0.1f);
                    gameObject.transform.position   = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - mFinalPosition[mGreenToken.mFinalPositionIndex]);
                    mGreenToken.OrderInLayer(1);
                    SoundManagerScript.PlaySound("Home");
                    GameManagerScript.mGameManager.mGreenPlayerFinished++;
                    GameManagerScript.mGameManager.mGreenPlayerOut--;
                    mAnotherChance  = true;
                    mGreenCanMove   = false;
                    mPlayerFinished = true;
                    mGreenToken.mFinalPositionIndex++;
                }
                else
                {
                    mAnotherChance = false;
                    mGreenCanMove  = false;
                    mTokenMoved    = true;
                }
                mNumberOfStepsMoved += mNumberGot;
            }
        }
        mNumberOfStepsRemaining = mPath.Length - mPositionMoved;
        StartCoroutine(IShiftPlayer());
        AllPlayerFinished();
        mGreenToken.OrderInLayer(2);
        if (mMoveToken != null)
        {
            StopCoroutine(mMoveToken);
        }
    }