// Use this for initialization
    void Start()
    {
        myParse     = GameObject.Find("Preload").GetComponent <MyParse>();
        testNetwork = GameObject.Find("Preload").GetComponent <TestNetwork>();
        testNetwork.ReTestConnection();
        isQuery = false;

        localPosition  = 275.98f;
        top100Position = 275.98f;
        loadState      = LoadState.Local;
    }
    // Update is called once per frame
    void Update()
    {
        switch (loadState)
        {
        case LoadState.Local:
            /*if (!isQuery) {
             *      isQuery = true;
             *      myParse.QueryScore(ParseUser.CurrentUser.Username);
             * } else {
             *      if (myParse.isGetScores) {
             *              myParse.isGetScores = false;
             *              int sum = 0;
             *              foreach (var score in myParse.results) {
             *                      sum++;
             *                      GameObject clone = NGUITools.AddChild (localGameObject, localScoreItem);
             *                      clone.transform.localPosition = new Vector3(0, localPosition, 0);
             *                      clone.GetComponent<SetScoreData>().SetData(sum, score.Get<string>("nickname"), score.Get<int>("score"));
             *                      localPosition -= 60.0f;
             *              }
             *              if (sum > 0) {
             *                      localLoading.gameObject.SetActive(false);
             *              } else {
             *                      localLoading.key = "NoData";
             *              }
             *              isQuery = false;
             *              loadState = LoadState.World;
             *      }
             * }*/
            int[]    scores = PlayerPrefsX.GetIntArray("scores");
            string[] names  = PlayerPrefsX.GetStringArray("names");
            sum = 0;
            for (int i = 0; i < 10; i++)
            {
                if (scores[i] >= 0)
                {
                    sum++;
                    GameObject clone = NGUITools.AddChild(localGameObject, localScoreItem);
                    clone.transform.localPosition = new Vector3(0, localPosition, 0);
                    clone.GetComponent <SetScoreData>().SetData(sum, names[i], scores[i]);
                    localPosition -= 60.0f;
                }
            }
            if (sum > 0)
            {
                localLoading.gameObject.SetActive(false);
            }
            else
            {
                localLoading.key = "NoData";
            }
            loadState = LoadState.World;
            break;

        case LoadState.World:
            loadState = LoadState.Top100;
            break;

        case LoadState.Top100:
            if (testNetwork.isConnect)
            {
                if (!testNetwork.isReConnect)
                {
                    if (!isQuery)
                    {
                        isQuery = true;
                        myParse.QueryTop100Score();
                    }
                    else
                    {
                        if (myParse.isGetTop100Scores)
                        {
                            myParse.isGetTop100Scores = false;
                            sum = 0;

                            foreach (var score in myParse.results)
                            {
                                sum++;
                                GameObject clone = NGUITools.AddChild(top100GameObject, top100ScoreItem);
                                clone.transform.localPosition = new Vector3(0, top100Position, 0);
                                clone.GetComponent <SetScoreData>().SetData(sum, score.Get <string>("nickname"), score.Get <int>("score"));
                                top100Position -= 60.0f;
                            }
                            if (sum > 0)
                            {
                                top100Loading.gameObject.SetActive(false);
                            }
                            else
                            {
                                top100Loading.key = "NoData";
                            }
                        }
                    }
                }
            }
            else
            {
                top100Loading.key = "PleaseConnectNetwork";
                testNetwork.ReTestConnection();
            }
            break;
        }
    }
示例#3
0
    void Update()
    {
        switch (gameState)
        {
        case GameState.Starting:          //ok
            if (countDownTimeLeft <= 0)
            {
                CountDownSound.audioClip = CountDownSource;
                CountDownSound.Play();
                gameState = GameState.Playing;
                playState = PlayState.NewRandom;
            }
            else if (Mathf.FloorToInt(countDownTimeLeft) < countDownTimeLeftTmp)
            {
                CountDownLabelPlayTween.resetOnPlay = true;
                if (countDownTimeLeftTmp < 3)
                {
                    CountDownSound.Play();
                }
                CountDownLabel.text = countDownTimeLeftTmp.ToString();
                CountDownLabelPlayTween.Play(true);
                countDownTimeLeftTmp--;
            }
            countDownTimeLeft -= Time.deltaTime;
            break;

        case GameState.Playing:          //ok

            PlayComboCountLabel.text = combo.ToString();

            switch (playState)
            {
            case PlayState.NewRandom:              //ok

                randomQuestion = Random.Range(0, dataCount);
                computerPlay   = NewComputerPlay(randomQuestion);
                playerPlay     = -1;

                QuestionLabel.key = data[randomQuestion][0];
                timeLeft          = SetTimeLeft(combo);

                PlayUI.SetActive(true);
                playState = PlayState.Going;
                break;

            case PlayState.Going:              //ok

                TimeLeftCountDownLabel.text = timeLeft.ToString("0.0");
                timeLeft -= Time.deltaTime;


                if (playerPlay != -1)
                {
                    isPlayed = true;
                    PlayUI.SetActive(false);
                    playState      = PlayState.PlayingAnimation;
                    animationState = AnimationState.MoveForward;
                }
                if (timeLeft <= 0.0f)
                {
                    PlayUI.SetActive(false);
                    TimeLeftCountDownLabel.text = "0.0";
                    DefeatSprite.spriteName     = "TimesUp";
                    gameState = GameState.EndAnimation;
                }
                break;

            case PlayState.PlayingAnimation:
                switch (animationState)
                {
                case AnimationState.MoveForward:
                    if (isPlayed)
                    {
                        isPlayed = false;
                        if (AwinB(playerPlay, computerPlay))
                        {
                            ResultLocalize.key = "Win";
                        }
                        else if (AwinB(computerPlay, playerPlay))
                        {
                            ResultLocalize.key = "Lose";
                        }
                        else
                        {
                            ResultLocalize.key = "Draw";
                        }
                        ResultLabel.gameObject.SetActive(true);
                        player[playerPlay].Play(true);
                        computer[computerPlay].Play(true);
                    }
                    if (!player[playerPlay].GetComponent <TweenPosition>().enabled)
                    {
                        stopTime       = 1.0f;
                        animationState = AnimationState.Stop;
                    }
                    break;

                case AnimationState.Stop:
                    stopTime -= Time.deltaTime;
                    if (stopTime <= 0.0f)
                    {
                        isPlayed       = true;
                        animationState = AnimationState.MoveBack;
                    }
                    break;

                case AnimationState.MoveBack:
                    if (isPlayed)
                    {
                        isPlayed = false;
                        player[playerPlay].Play(false);
                        computer[computerPlay].Play(false);
                    }
                    if (!player[playerPlay].GetComponent <TweenPosition>().enabled)
                    {
                        ResultLabel.gameObject.SetActive(false);
                        playState = PlayState.Judgment;
                    }
                    break;
                }
                break;

            case PlayState.Judgment:                 //ok
                if (AwinB(playerPlay, computerPlay)) //player win
                {
                    combo++;
                    playState = PlayState.NewRandom;
                }
                else if (AwinB(computerPlay, playerPlay))                      //computer win
                {
                    DefeatSprite.spriteName = "Defeat";
                    gameState = GameState.EndAnimation;
                }
                else
                {
                    playState = PlayState.NewRandom;
                }
                break;
            }


            break;

        case GameState.EndAnimation:


            switch (endAnimationState)
            {
            case EndAnimationState.MoveDown:
                DefeatSpriteTweenPosition.from = new Vector3(0, 511, 0);
                DefeatSpriteTweenPosition.to   = new Vector3(0, 0, 0);
                DefeatSpritePlayTween.Play(true);
                if (!DefeatSpriteTweenPosition.enabled)
                {
                    stopTime          = 1.0f;
                    endAnimationState = EndAnimationState.Stop;
                }
                break;

            case EndAnimationState.Stop:
                if (stopTime > 0)
                {
                    stopTime -= Time.deltaTime;
                }
                else
                {
                    DefeatSpriteTweenPosition.gameObject.SetActive(false);
                    testNetwork.ReTestConnection();
                    gameState = GameState.Ending;
                }
                break;
            }


            break;

        case GameState.Ending:
            PlayUI.SetActive(false);
            EndUI.SetActive(true);
            EndComboCountLabel.text = combo.ToString();
            if (testNetwork.isConnect)
            {
                if (!testNetwork.isReConnect)
                {
                    Warning.SetActive(false);
                }
            }
            else
            {
                Warning.SetActive(true);
                testNetwork.ReTestConnection();
            }
            break;
        }
    }