Ejemplo n.º 1
0
    public void ReadInScoresData()
    {
        StreamReader scoresReader = new StreamReader(scoresPath);

        for (int i = 0; i < 5; i++)
        {
            NameVal temp = new NameVal();
            temp.name = scoresReader.ReadLine();
            temp.val  = int.Parse(scoresReader.ReadLine());
            fileScores.Add(temp);
        }

        scoresReader.Close();

        StreamReader timesReader = new StreamReader(timesPath);

        for (int i = 0; i < 5; i++)
        {
            NameVal temp = new NameVal();
            temp.name = timesReader.ReadLine();
            temp.val  = int.Parse(timesReader.ReadLine());
            fileTimes.Add(temp);
        }

        timesReader.Close();
    }
Ejemplo n.º 2
0
    public void CmdWriteOutScoresData()
    {
        if (!isServer)
        {
            return;
        }

        gameScores.Clear();
        gameTimes.Clear();

        foreach (CarMovement car in DeathRaceManager.GetCars())
        {
            NameVal temp = new NameVal();
            temp.name = car.PlayerName;
            temp.val  = car.score;
            gameScores.Add(temp);
        }

        foreach (CarMovement car in DeathRaceManager.GetCars())
        {
            NameVal temp = new NameVal();
            temp.name = car.PlayerName;
            temp.val  = (int)car.raceFinishTime;
            gameTimes.Add(temp);
        }

        foreach (NameVal pair in gameScores)
        {
            fileScores.Add(pair);
        }

        foreach (NameVal pair in gameTimes)
        {
            fileTimes.Add(pair);
        }

        fileScores = (fileScores.OrderBy(s => s.val)).ToList <NameVal>();
        fileScores.Reverse();

        fileTimes = (fileTimes.OrderBy(t => t.val)).ToList <NameVal>();

        List <NameVal> tempFileScores = new List <NameVal>(5);
        List <NameVal> tempFileTimes  = new List <NameVal>(5);

        for (int i = 0; i < 5; i++)
        {
            tempFileScores.Add(fileScores[i]);
            tempFileTimes.Add(fileTimes[i]);
        }

        fileScores = tempFileScores;
        fileTimes  = tempFileTimes;

        StreamWriter scoresWriter = new StreamWriter(scoresPath, false);

        foreach (NameVal pair in fileScores)
        {
            scoresWriter.WriteLine(pair.name);
            scoresWriter.WriteLine(pair.val);
        }

        scoresWriter.Close();

        StreamWriter timesWriter = new StreamWriter(timesPath, false);

        foreach (NameVal pair in fileTimes)
        {
            timesWriter.WriteLine(pair.name);
            timesWriter.WriteLine(pair.val);
        }

        timesWriter.Close();
    }