Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Have mercy

Name: Anonymous 2009-11-19 6:56

Gentlemen, I'm playing around with C# trying to make a simple little game with a highscore board but sorting the highhscores is troubling me.

Highscores are read from a highscore file and put in an ArrayList with 3 fields, int score, string playerName, int moves. The board will only have a 'top ten' so including the last game played there is a potential of 11 highscores. The ArrayLists need to be sorted by the first element, score, and then trimmed to 10 entries before being written back to the highscore file and displayed.

Now, sorting a single ArrayList is fine, but I have 11 that need to be checked against each other and then sorted. I even tried an ArrayList of ArrayLists, what the shit.

Name: Anonymous 2009-11-19 9:07

>>6
Now with Best Practices!
        struct SchoreEntry : IComparable<SchoreEntry>
        {
            public readonly string Name;
            public readonly int Schore;
            public readonly int Movesh;
            public SchoreEntry(string name, int schore, int movesh)
            {
                this.Name = name;
                this.Schore = schore;
                this.Movesh = movesh;
            }
            public int CompareTo(SchoreEntry other)
            {
                return this.Schore.CompareTo(other.Schore);
            }
        }

        static void Main()
        {
            var sc1 = new SchoreEntry("MDickie", 9001, 0);
            var sc2 = new SchoreEntry("Anon", 1, 100);
            Console.WriteLine(sc1.CompareTo(sc2));
        }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List