public static bool SaveToString(StarSector sector)
 {
     Debug.WriteLine("Saving Star Sector");
     try
     {
         var wfile = new StreamWriter("Star Sector.txt");
         wfile.WriteLine(sector.ToString());
         wfile.Close();
     }
     catch (Exception) { return false; }
     return true;
 }
 public static bool Save(StarSector sector)
 {
     Debug.WriteLine("Saving Star Sector");
     try
     {
         var writer = new System.Xml.Serialization.XmlSerializer(typeof(StarSector));
         var wfile = new StreamWriter("Star Sector.xml");
         writer.Serialize(wfile, sector);
         wfile.Close();
     }
     catch (Exception) { return false; }
     return true;
 }
        public StarSector Generate()
        {
            StarSector sector = new StarSector();
            Die = new Dice();

            for (int x = 0; x < WidthHeight.X; x++)
            {
                var row = new List<StarSystem>(WidthHeight.Y);
                for (int y = 0; y < WidthHeight.Y; y++)
                {
                    var starSystem = StarSystem.Generate(Die);
                    starSystem.Coordinate = new HexCoordinate(x, y);
                    row.Add(starSystem);
                }
                sector.Sector.Add(row);
            }
            return sector;
        }
        public void Run()
        {
            int width = 1;
            int height = 1;

            while (true)
            {
                Console.WriteLine("Sector Width");
                string wstring = Console.ReadLine();

                Console.WriteLine("Sector Height");
                string hstring = Console.ReadLine();

                if (int.TryParse(wstring, out width) &&
                    int.TryParse(hstring, out height) &&
                    width > 0 &&
                    height > 0)
                    break;
            }

            bool generate = true;
            StarSectorGenerator generator = new StarSectorGenerator(new HexCoordinate(width, height));
            StarSector sector = new StarSector();

            bool loop = true;
            while (loop)
            {
                if (generate)
                {
                    Console.Clear();

                    // Generate Sector
                    generator = new StarSectorGenerator(new HexCoordinate(width, height));
                    sector = generator.Generate();
                    Writer.WriteLine(sector.ToString());

                    Console.WriteLine("Type 'save xml' to save output to an XML file");
                    Console.WriteLine("Type 'save txt' to save output to a text file");
                    Console.WriteLine("Type 'save' to save output to both text and XML files");
                    Console.WriteLine("Type 'exit' to exit generation");
                    Console.WriteLine("Otherwise Press enter to regenerate");
                }

                string read = Console.ReadLine();
                switch (read.ToLower())
                {
                    case "save":
                        StarSector.Save(sector);
                        StarSector.SaveToString(sector);
                        generate = false;
                        break;
                    case "save xml":
                        StarSector.Save(sector);
                        generate = false;
                        break;
                    case "save txt":
                        StarSector.SaveToString(sector);
                        generate = false;
                        break;
                    case "exit":
                        loop = false;
                        generate = false;
                        break;
                    default:
                        generate = true;
                        break;
                }
            }
        }