Example #1
0
        public static HighScoreRecord[] GetHighScores(System.Windows.Forms.IWin32Window owner)
        {
            HighScoreRecord[] highScores = new HighScoreRecord[3];

            object obj = LoadFile(Consts.HighScoreFile, true, owner);

            if (obj != null)
            {
                highScores = (HighScoreRecord[])STSerializableObject.ArrayListToArray((ArrayList)obj, "HighScoreRecord");
            }

            return(highScores);
        }
        public int CompareTo(object value)
        {
            int             compared;
            HighScoreRecord highScore = (HighScoreRecord)value;

            if (value == null)
            {
                compared = 1;
            }
            else if (highScore.Score < Score)
            {
                compared = 1;
            }
            else if (highScore.Score > Score)
            {
                compared = -1;
            }
            else if (highScore.Worth < Worth)
            {
                compared = 1;
            }
            else if (highScore.Worth > Worth)
            {
                compared = -1;
            }
            else if (highScore.Days < Days)
            {
                compared = 1;
            }
            else if (highScore.Days > Days)
            {
                compared = -1;
            }
            else
            {
                compared = 0;
            }

            return(compared);
        }
        /*
         * Types currently supported:
         * CrewMember
         * Gadget
         * HighScoreRecord
         * Shield
         * StarSystem
         * Weapon
         *
         * If an array of a type not listed is converted using ArrayToArrayList, the type
         * needs to be added here.
         */
        public static STSerializableObject[] ArrayListToArray(ArrayList list, string type)
        {
            STSerializableObject[] array = null;

            if (list != null)
            {
                switch (type)
                {
                case "CrewMember":
                    array = new CrewMember[list.Count];
                    break;

                case "Gadget":
                    array = new Gadget[list.Count];
                    break;

                case "HighScoreRecord":
                    array = new HighScoreRecord[list.Count];
                    break;

                case "Shield":
                    array = new Shield[list.Count];
                    break;

                case "StarSystem":
                    array = new StarSystem[list.Count];
                    break;

                case "Weapon":
                    array = new Weapon[list.Count];
                    break;
                }

                for (int index = 0; index < list.Count; index++)
                {
                    Hashtable            hash = (Hashtable)list[index];
                    STSerializableObject obj  = null;

                    if (hash != null)
                    {
                        switch (type)
                        {
                        case "CrewMember":
                            obj = new CrewMember(hash);
                            break;

                        case "Gadget":
                            obj = new Gadget(hash);
                            break;

                        case "HighScoreRecord":
                            obj = new HighScoreRecord(hash);
                            break;

                        case "Shield":
                            obj = new Shield(hash);
                            break;

                        case "StarSystem":
                            obj = new StarSystem(hash);
                            break;

                        case "Weapon":
                            obj = new Weapon(hash);
                            break;
                        }
                    }

                    array[index] = obj;
                }
            }

            return(array);
        }