Exemplo n.º 1
0
 void initialise()//this will only run the first time the game is started on a new computer
 {
     if (!initialised)
     {
         print("initialising highscore");
         HighScoreStruct init = new HighScoreStruct("Default", 0);
         easyHighScore = new HighScoreStruct[10];
         for (int i = 0; i < 10; i++)
         {
             easyHighScore.SetValue(init, i);
         }
         normalHighScore = new HighScoreStruct[10];
         for (int i = 0; i < 10; i++)
         {
             normalHighScore.SetValue(init, i);
         }
         hardHighScore = new HighScoreStruct[10];
         for (int i = 0; i < 10; i++)
         {
             hardHighScore.SetValue(init, i);
         }
         insaneHighScore = new HighScoreStruct[10];
         for (int i = 0; i < 10; i++)
         {
             insaneHighScore.SetValue(init, i);
         }
         HS = new HighScoreStruct[10];
         for (int i = 0; i < 10; i++)
         {
             HS.SetValue(init, i);
         }
         initialised = true;
     }
 }
Exemplo n.º 2
0
    void calculateHighScore()
    {
        int score = sword.getScore();

        print("score set");
        for (int i = 0; i < 10; i++)
        {
            print("current lap " + i);
            print(HS.GetValue(i));

            if (score > ((HighScoreStruct)HS.GetValue(i)).getScore()) //check if current score is higher than the old score
            {
                scoreChanged      = true;
                activateTextField = true;
                //while (!submittedText) { }
                HighScoreStruct temp = new HighScoreStruct(stringToEdit, score);
                print("created new highscorestruct");
                HighScoreStruct temp2 = (HighScoreStruct)HS.GetValue(i);
                HS.SetValue(temp, i);

                for (int y = i + 1; y < 10; y++)
                {
                    temp = (HighScoreStruct)HS.GetValue(y);
                    HS.SetValue(temp2, y);
                    temp2 = temp;
                }
                i = 10;
            }
        }
    }
    private void LoadJsonDataCallBack(string res)
    {
        if (res != null)
        {
            highScoreStruct = JsonUtility.FromJson <HighScoreStruct>(res);

            playerName.text    = highScoreStruct.playerName;
            highScoreText.text = highScoreStruct.highScore.ToString();

            successState.color = Color.green;
            successState.text  = "Success!";
        }
        else
        {
            successState.color = Color.red;
            successState.text  = "Fail!";
        }
    }
Exemplo n.º 4
0
    public void AddScore(int score, string scoreName)
    {
        var newScore = new HighScoreStruct {
            score = score, name = scoreName
        };

        highScore.Add(newScore);

        var newArray = highScore.ToArray();

        if (newArray.Length > 1)
        {
            for (var i = 0; i < newArray.Length; i++)
            {
                for (var j = 0; j < newArray.Length; j++)
                {
                    if (!(newArray[j].score < newArray[i].score))
                    {
                        continue;
                    }
                    var temp = newArray[i];
                    newArray[i] = newArray[j];
                    newArray[j] = temp;
                }
            }
        }

        highScore = new List <HighScoreStruct>();
        if (newArray.Length >= amountOfScoresToShow)
        {
            for (int k = 0; k < amountOfScoresToShow; k++)
            {
                highScore.Add((newArray[k]));
            }
        }
        else
        {
            highScore = new List <HighScoreStruct>();
            foreach (var item in newArray)
            {
                highScore.Add(item);
            }
        }
    }