/* * 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; }
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; }
private void ClearHighScores() { HighScoreRecord[] highScores = new HighScoreRecord[3]; Functions.SaveFile(Consts.HighScoreFile, STSerializableObject.ArrayToArrayList(highScores), this); }
private void GameEnd() { SetInGameControlsEnabled(false); AlertType alertType = AlertType.Alert; switch (game.EndStatus) { case GameEndType.Killed: alertType = AlertType.GameEndKilled; break; case GameEndType.Retired: alertType = AlertType.GameEndRetired; break; case GameEndType.BoughtMoon: alertType = AlertType.GameEndBoughtMoon; break; } FormAlert.Alert(alertType, this); FormAlert.Alert(AlertType.GameEndScore, this, Functions.FormatNumber(game.Score / 10), Functions.FormatNumber(game.Score % 10)); HighScoreRecord candidate = new HighScoreRecord(game.Commander.Name, game.Score, game.EndStatus, game.Commander.Days, game.Commander.Worth, game.Difficulty); if (candidate > Functions.GetHighScores(this)[0]) { if (game.CheatEnabled) FormAlert.Alert(AlertType.GameEndHighScoreCheat, this); else { AddHighScore(candidate); FormAlert.Alert(AlertType.GameEndHighScoreAchieved, this); } } else FormAlert.Alert(AlertType.GameEndHighScoreMissed, this); Game.CurrentGame = null; game = null; }
private void AddHighScore(HighScoreRecord highScore) { HighScoreRecord[] highScores = Functions.GetHighScores(this); highScores[0] = highScore; Array.Sort(highScores); Functions.SaveFile(Consts.HighScoreFile, STSerializableObject.ArrayToArrayList(highScores), this); }