Exemplo n.º 1
0
    public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(-1);
        }

        OneScoreFromTopTen other = obj as OneScoreFromTopTen;

        if (this.GradeMeAsFloat() > other.GradeMeAsFloat())
        {
            //this grade is higher, automatically makes this precede other in the top ten list
            return(-1);
        }
        else if (this.GradeMeAsFloat() == other.GradeMeAsFloat())
        {
            //grades are the same for this and other
            //if other time is shorter, then other is higher on the top 10 list, this follows other in the top ten list
            if (other.TimeValue < this.TimeValue)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }

        //same by default?
        return(0);
    }
Exemplo n.º 2
0
 //LoadFromOneString takes a string array and sets local private vars
 public void LoadFromOneStringArray(OneScoreFromTopTen oneScoreOnly)
 {
     NameStr     = oneScoreOnly.PlayerName;
     TimeStr     = oneScoreOnly.TimeValueAsString();
     GradeStr    = oneScoreOnly.GradeMe();
     AccuracyStr = oneScoreOnly.AccuracyValueAsString();
     KillsStr    = oneScoreOnly.KillsValueAsString();
 }
Exemplo n.º 3
0
        //s stands for player shots
        public OneScoreFromTopTen GetAsOneScore(int s, int difficulty)
        {
            OneScoreFromTopTen newScore = new OneScoreFromTopTen();

            newScore.AccuracyValue = (float)hits / s;
            newScore.KillsValue    = (float)kills / total;
            newScore.TimeValue     = timer;
            newScore.Difficulty    = difficulty;
            return(newScore);
        }
Exemplo n.º 4
0
    public void SaveNewTopTenRecord(string newPlayerName)
    {
        //get the current score
        OneScoreFromTopTen newScore = score.GetAsOneScore(player.Shots, pers.settingsOfTheGame.difficultyMode);

        //set the new player name
        newScore.PlayerName = newPlayerName;
        //insert new record into the top ten list
        pers.settingsOfTheGame.InsertNewTopTenScore(newScore);
    }
Exemplo n.º 5
0
 //CheckIfInTopTen returns true if newScore is higher than the current 10th place
 public bool CheckIfInTopTen(OneScoreFromTopTen newScore)
 {
     //if new score is higher than 10th score
     //CompareTo() returns <0 if this precedes other in the sort order
     if (newScore.CompareTo(topTenScores [topTenScores.Count - 1]) < 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 6
0
    void GameWon()
    {
        //Player wins!
        gameover = gamewon = true;
        gameWonPanel.gameObject.SetActive(true);

        //check if the score made it to the top ten
        OneScoreFromTopTen newScore = score.GetAsOneScore(player.Shots, pers.settingsOfTheGame.difficultyMode);

        if (pers.settingsOfTheGame.CheckIfInTopTen(newScore))
        {
            //show user name input
            nameEntryDialog.SetActive(true);
        }
    }
Exemplo n.º 7
0
 public void GenerateFakeTopTenScores()
 {
     //generate fake top 10 scores
     topTenScores = new List <OneScoreFromTopTen>();
     for (int i = 0; i < 10; i++)
     {
         OneScoreFromTopTen newScore = new OneScoreFromTopTen();
         newScore.MakeRandomScore();
         //append top 10 rank to the name for debugging
         newScore.PlayerName = fakeNamesList[i];
         topTenScores.Add(newScore);
         Debug.Log("Made this in Persister: " + topTenScores[i].ToString());
     }
     topTenScores.Sort();
 }
Exemplo n.º 8
0
    //InsertNewTopTenScore adds the new score to the top ten list and sorts the new list, makes sure to keep only the top 10
    public void InsertNewTopTenScore(OneScoreFromTopTen newScore)
    {
        //make a temp list to hold 11 scores
        List <OneScoreFromTopTen> tempTopElevenScores = new List <OneScoreFromTopTen>(topTenScores.ToArray());

        //add to the score list (count will be 11)
        tempTopElevenScores.Add(newScore);

        //sort
        tempTopElevenScores.Sort();

        //only keep the top 10 (count will be 10)
        tempTopElevenScores.RemoveAt(tempTopElevenScores.Count - 1);

        //real top scores = new top 10 scores
        topTenScores = tempTopElevenScores;
    }
Exemplo n.º 9
0
 //set one of the top 10 scores
 //idx is the score index, scoreArray is a string[5] with [name,time,grade,accuracy,kills]
 void SetScoreForOneRow(int idx, OneScoreFromTopTen scoreArray)
 {
     Debug.Log("Top " + idx.ToString() + " score is " + scoreArray.ToString());
     topPlaces[idx].LoadFromOneStringArray(scoreArray);
 }