예제 #1
0
        public static NameScore[] SortNewScores(NameScore[] unsortedScores, int newScore, string newName = "")
        {
            NameScore[] tempSortNameScores = new NameScore[10];

            bool insertedNew = false;

            foreach (NameScore score in unsortedScores)
            {
                //Debug.Log(score.Rank);
                if (newScore > score.Score && !insertedNew)
                {
                    tempSortNameScores[score.Rank - 1] = new NameScore(score.Rank, newName, newScore);
                    insertedNew = true;
                }

                if (insertedNew)
                {
                    score.Rank++;
                }
                if (score.Rank != 11)
                {
                    tempSortNameScores[score.Rank - 1] = new NameScore(score.Rank, score.Name, score.Score);
                }
            }

            return(tempSortNameScores);
        }
예제 #2
0
        public static NameScore[] ReadHighScores(string path)
        {
            NameScore[] NameScoreLines  = new NameScore[10]; // high scores seperated
            string[]    HighScoresLines = new string[10];    // all line from file as string
            int         lineCounter     = 0;

            if (File.Exists(path))
            {
                StreamReader reader = new StreamReader(path);
                while (reader.Peek() >= 0)
                {
                    HighScoresLines[lineCounter] = reader.ReadLine();
                    string[] lineTemp  = HighScoresLines[lineCounter].Split(',');
                    int      tempRank  = Convert.ToInt32(lineTemp[0]);
                    string   tempname  = lineTemp[1];
                    int      tempScore = Convert.ToInt32(lineTemp[2]);


                    NameScoreLines[lineCounter] = (new NameScore(tempRank, tempname, tempScore));
                    //Debug.Log(NameScoreLine[lineCounter].Rank + NameScoreLine[lineCounter].Name+ NameScoreLine[lineCounter].Score);
                    lineCounter++;
                }
                reader.Close();
                //Debug.Log(SortNewScores(NameScoreLine, 5));
            }
            else
            {
                for (int i = 0; i < NameScoreLines.Length; i++)
                {
                    NameScoreLines[i] = new NameScore(i + 1, "", 0);
                }
            }

            return(NameScoreLines);
        }
예제 #3
0
 public void Initialize()
 {
     _nameScore = new NameScore();
 }