public static int Distance(StarSystem a, int x, int y) { return((int)Math.Floor(Math.Sqrt(Math.Pow(a.X - x, 2) + Math.Pow(a.Y - y, 2)))); }
/* * 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 int Distance(StarSystem a, StarSystem b) { return((int)Math.Floor(Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)))); }
private int Compare(int a, int b, string sortWhat, string sortBy) { int compareVal = 0; if (sortWhat == "M") // Mercenaries { CrewMember A = game.Mercenaries[a]; CrewMember B = game.Mercenaries[b]; bool strCompare = false; object valA = null; object valB = null; switch (sortBy) { case "I": // Id valA = (int)A.Id; valB = (int)B.Id; break; case "N": // Name valA = A.Name; valB = B.Name; strCompare = true; break; case "P": // Pilot valA = A.Pilot; valB = B.Pilot; break; case "F": // Fighter valA = A.Fighter; valB = B.Fighter; break; case "T": // Trader valA = A.Trader; valB = B.Trader; break; case "E": // Engineer valA = A.Engineer; valB = B.Engineer; break; case "S": // System valA = CurrentSystemDisplay(A); valB = CurrentSystemDisplay(B); strCompare = true; break; } if (strCompare) { compareVal = ((string)valA).CompareTo((string)valB); } else { compareVal = ((int)valA).CompareTo(valB); } // Secondary sort by Name if (compareVal == 0 && sortBy != "N") { compareVal = A.Name.CompareTo(B.Name); } } else { StarSystem A = game.Universe[a]; StarSystem B = game.Universe[b]; if (sortBy == "D") // Description { string nameA = ""; string nameB = ""; switch (sortWhat) { case "Q": // Quests nameA = A.SpecialEvent.Title; nameB = B.SpecialEvent.Title; break; case "S": // Shipyards nameA = A.Shipyard.Name; nameB = B.Shipyard.Name; break; } compareVal = nameA.CompareTo(nameB); } if (compareVal == 0) // Default sort - System Name { compareVal = A.Name.CompareTo(B.Name); } } return(compareVal); }