示例#1
0
    public void SetScoreBoard()
    {
        //System.Threading.Thread.Sleep(5000);
        //string path = @"D:\Unity3D_M\test.txt";
        string path = Application.persistentDataPath + "/Ranking.dat";
        string s;

        ScoreBoardText[] sbText = new ScoreBoardText[20];
        int index = 0;

        char[] name_tmp = { (char)UnityEngine.Random.Range('A', 'Z'), (char)UnityEngine.Random.Range('A', 'Z'), (char)UnityEngine.Random.Range('A', 'Z') };
        string name     = new string(name_tmp);

        SCB.text          = "ScoreBoard";
        GameOverText.text = "";

        using (StreamWriter sw = File.AppendText(path))
        {
            sw.WriteLine(name + " " + score);
            MyScore.text = "MyScore: " + score;
        }

        using (StreamReader sr = File.OpenText(path))
        {
            while ((s = sr.ReadLine()) != null)
            {
                string[] sTmp = s.Split(' ');
                sbText[index].str = sTmp[0];
                if (sTmp[1] != null)
                {
                    sbText[index++].score = int.Parse(sTmp[1]);
                }
            }
        }
        sbSorting(sbText, index);
        for (int i = 0; i < index && i < 10; i++)
        {
            GameOverText.text += (i + 1) + ". \t" + sbText[i].str + " \t" + sbText[i].score + "\n";
        }
        using (StreamWriter sw = File.CreateText(path))
        {
            for (int i = 0; i < 10; i++)
            {
                sw.WriteLine(sbText[i].str + " " + sbText[i].score);
            }
        }
    }
示例#2
0
    public ScoreBoardText[] sbSorting(ScoreBoardText[] sbText, int size)
    {
        ScoreBoardText index = sbText[0];
        int            j     = 0;

        for (int i = 0; i < size; i++)
        {
            index = sbText[i];
            j     = i;

            while ((j > 0) && (sbText[j - 1].score < index.score))
            {
                sbText[j] = sbText[j - 1];
                j         = j - 1;
            }
            sbText[j] = index;
        }

        return(sbText);
    }
示例#3
0
    void OnEnable()
    {
        GameObject[] charGO = GameObject.FindGameObjectsWithTag ("character");
        foreach (GameObject GO in charGO) {
            CHARACTERS.Add(GO.GetComponent<Character>());
        }

        controllerToChar = GameObject.Find ("DontDestroy");
        if(controllerToChar != null)
            setCharactersAndControllers (controllerToChar.GetComponent<DontDestroy> ().controllerToCharacter);

        GameObject nightImg = GameObject.Find ("BlackScreen");

        if (nightImg) {
            float alpha = nightImg.GetComponent<Renderer>().material.color.a;
            Color newColor = new Color(1, 1, 1, 0.0f);
            nightImg.GetComponent<SpriteRenderer>().material.color = newColor;
            Debug.Log ("Hiding black map");
        }

        Color hiddenColor = new Color(1, 1, 1, 0.0f);
        Color showColor = new Color(1, 1, 1, 1.0f);

        foxText = foxCanvas.GetComponent<ScoreBoardText>();
        skunkText = skunkCanvas.GetComponent<ScoreBoardText>();
        bearText = bearCanvas.GetComponent<ScoreBoardText>();
        rabbitText = rabbitCanvas.GetComponent<ScoreBoardText>();

        foxScoreboard.GetComponent<SpriteRenderer>().material.color = hiddenColor;
        skunkScoreboard.GetComponent<SpriteRenderer>().material.color = hiddenColor;
        bearScoreboard.GetComponent<SpriteRenderer>().material.color = hiddenColor;
        rabbitScoreboard.GetComponent<SpriteRenderer>().material.color = hiddenColor;

        Debug.Log ("Hiding black map");

        foreach (Character player in CHARACTERS){
            if(player.name.Contains("Fox")){
                foxText.isHidden = false;
                foxScoreboard.GetComponent<SpriteRenderer>().material.color = showColor;
            }
            if(player.name.Contains("Skunk")){
                skunkText.isHidden = false;
                skunkScoreboard.GetComponent<SpriteRenderer>().material.color = showColor;
            }
            if(player.name.Contains("Bear")){
                bearText.isHidden = false;
                bearScoreboard.GetComponent<SpriteRenderer>().material.color = showColor;
            }
            if(player.name.Contains("Rabbit")){
                rabbitText.isHidden = false;
                rabbitScoreboard.GetComponent<SpriteRenderer>().material.color = showColor;
            }
        }
    }