Beispiel #1
0
    public bool updateList(scoreRow newRow)
    {
        int myTime = 60*newRow.getMinutes() +  newRow.getSeconds();
        bool inserted = false;
        int i = 0;
        for(; i < scoreList.Count; i++)
        {
            if (!inserted)
            {
                int curTime = 60* scoreList[i].getMinutes() + scoreList[i].getSeconds();
                if (myTime <= curTime)
                {
                    newRow.setPlace(scoreList[i].getPlace());
                    scoreList.Insert(i, newRow);
                    inserted = true;
                    i++;
                    break;
                }
            }
        }

        for (;i < scoreList.Count; i++)
        {
            int curTime = 60*scoreList[i].getMinutes() + scoreList[i].getSeconds();
            int lastTime = 60 * scoreList[i-1].getMinutes() + scoreList[i-1].getSeconds();

            if (curTime == lastTime)
            {
                scoreList[i].setPlace(scoreList[i - 1].getPlace());
            }
            else
            {
                scoreList[i].setPlace(i+1);
            }
        }

        if (scoreList.Count == 0)
        {
            newRow.setPlace(1);
            scoreList.Insert(i, newRow);
            inserted = true;
        }
        if (scoreList.Count < places.Count && !inserted)
        {
            int lastTime = 60 * scoreList[scoreList.Count -1].getMinutes() + scoreList[scoreList.Count - 1].getSeconds();
            if (myTime == lastTime)
            {
                newRow.setPlace(scoreList[scoreList.Count - 1].getPlace());
            }
            else
            {
                newRow.setPlace(scoreList.Count + 1);
            }
            scoreList.Add(newRow);
            inserted = true;
        }
        if (inserted)
        {
            if (scoreList.Count > places.Count)
            {
                scoreList.RemoveRange(places.Count, scoreList.Count - places.Count );
            }
            recordBeaten = true;
            writeFile();
            return true;
        }
        return false;
    }
Beispiel #2
0
 void readFile()
 {
     scoreList.Clear();
     StreamReader theReader = new StreamReader(Main.S.Map.GetComponent<Map>().name + filename, Encoding.Default);
     using (theReader)
     {
         string line;
         do
         {
             line = theReader.ReadLine();
             if (line != null && line != "")
             {
                 string[] entries = line.Split(' ');
                 scoreRow newRow = new scoreRow();
                 newRow.setPlace(Int32.Parse(entries[0]));
                 newRow.setName(entries[1]);
                 newRow.setTime(Int32.Parse(entries[2]), Int32.Parse(entries[3]));
                 scoreList.Add(newRow);
             }
         } while (line != null);
     }
 }