示例#1
0
    WinPanel winpanel;    //winpanel controller
    /// <summary>
    /// when game wins.
    /// </summary>
    public void gameWin()
    {
        //fire win event
        //		gameWinEvent ();
        GameManager.getInstance().playSfx("win");
        if (GameData.getInstance().cLevel % 5 == 0 && GameData.getInstance().cLevel > 0)
        {
//			musicScript.showCB();
        }

        GameData.getInstance().isWin = true;
        int threeStar = (int)(levelData [1].Count / 2 / 1.2f) + 2; //one line per second
        int twoStar   = threeStar + 5;                             //
        int oneStar   = threeStar + 20;                            //

        int starGet = 0;

        if ((120 - timeCount) <= threeStar)
        {
            starGet = 3;
        }
        else if ((120 - timeCount) > threeStar && (120 - timeCount) <= twoStar)
        {
            starGet = 2;
        }
        else if ((120 - timeCount) > twoStar && (120 - timeCount) <= oneStar)
        {
            starGet = 1;
        }
        else
        {
            starGet = 0;
        }

        GameObject panelWin = GameObject.Find("PanelWin");

        winpanel = panelWin.GetComponent <WinPanel> ();
        winpanel.showHidePanel(starGet);
        GameObject.Find("btnTip").GetComponent <Button> ().interactable = false;

        //save
        int saveLevel = 0;

        if (GameData.getInstance().cLevel < GameData.totalLevel - 1)
        {
            saveLevel = GameData.getInstance().cLevel + 1;
        }

        if (GameData.getInstance().levelPassed < saveLevel)
        {
            PlayerPrefs.SetInt("levelPassed", saveLevel);
            GameData.getInstance().levelPassed = saveLevel;
        }
        //save score
        int cLvScore = PlayerPrefs.GetInt("levelScore_" + GameData.getInstance().cLevel, 0);

//		print (cLvScore + "_" + timeCount);
        if (cLvScore < timeCount)
        {
            PlayerPrefs.SetInt("levelScore_" + GameData.getInstance().cLevel, timeCount);
            PlayerPrefs.SetInt("levelStar_" + GameData.getInstance().cLevel, starGet);
            //save to GameData instantlly
            if (GameData.getInstance().lvStar.Count > GameData.getInstance().cLevel)
            {
                GameData.getInstance().lvStar[GameData.getInstance().cLevel] = starGet;
            }
//			print ("save new score"+cLvScore+"_"+timeCount);


            //submitscore
            int tallScore = 0;
            for (int i = 0; i < GameData.totalLevel; i++)
            {
                int tScore = PlayerPrefs.GetInt("levelScore_" + i.ToString(), 0);
                tallScore += tScore;
            }
            GameData.getInstance().bestScore = tallScore;
            GameManager.getInstance().submitGameCenter();
        }
    }