/// <summary> /// Reads in the game map data from a specified xml file. Returns a game created from this. /// </summary> /// <returns></returns> public Game Read() { if (map == null) map = "classic.xml"; using (XmlReader reader = XmlReader.Create(Path.Combine(Package.Current.InstalledLocation.Path, "Assets/" + map))) { while (reader.Read()) { // Only detect start elements. if (reader.IsStartElement()) { // Get element name and switch on it. switch (reader.Name) { case "Map": string imageName = reader["image"]; image = imageName; break; case "Zone": Continent tempContinent = new Continent(); tempContinent.Name = reader["name"]; tempContinent.Worth = Int32.Parse(reader["bonus"]); continents.Add(tempContinent); break; case "Country": string attribute = reader["name"]; if (attribute != null) { Country tempCountry = new Country(); tempCountry.Name = attribute; countries.Add(tempCountry); continents.Last().CountryNames.Add(attribute); } break; case "AdjCountry": if (reader.Read()) { countries.Last().AdjacentCountryNames.Add(reader.Value.Trim()); } break; case "X": if (reader.Read()) { if (reader.Value.Trim().Equals("x")) countries.Last().X = 0; else countries.Last().X = Int32.Parse(reader.Value.Trim()); } break; case "Y": if (reader.Read()) { if (reader.Value.Trim().Equals("y")) countries.Last().Y = 0; else countries.Last().Y = Int32.Parse(reader.Value.Trim()); } break; } } } foreach (Country temp in countries) { game.Countries.Add(temp.Name, temp); } foreach (Continent temp in continents) { game.Continents.Add(temp.Name, temp); } return game; } }
/// <summary> /// Adds a country to this game. /// </summary> /// <param name="country"></param> public void AddCountry(Country country) { Countries[country.Name] = country; }
public Game MakeExampleGame() { var game = Game.DisposeAndAcreateNewGame(); game.AddPlayer(new Player() { //PlayerNumber = PlayerNumber.P1, Name = "Player One", Color = 0xFFFF0000, }); game.AddPlayer(new Player() { //PlayerNumber = PlayerNumber.P2, Name = "Player Two", Color = 0xFF0000FF, }); Country country; country = new Country() { Name = "Testistan", Units = 2, X = 0, Y = 0, OwnedBy = PlayerNumber.P1 }; country.AdjacentCountryNames.Add("Testlyvania"); country.AdjacentCountryNames.Add("Testanbul"); game.AddCountry(country); country = new Country() { Name = "Testlyvania", Units = 3, X = 10, Y = 0, OwnedBy = PlayerNumber.P1 }; country.AdjacentCountryNames.Add("Testistan"); country.AdjacentCountryNames.Add("Testanbul"); game.AddCountry(country); country = new Country() { Name = "Testanbul", Units = 2, X = 0, Y = 10, OwnedBy = PlayerNumber.P2 }; country.AdjacentCountryNames.Add("Testistan"); country.AdjacentCountryNames.Add("Testlyvania"); country.AdjacentCountryNames.Add("Test States of America"); game.AddCountry(country); country = new Country() { Name = "Test States of America", Units = 1, X = 0, Y = 20, OwnedBy = PlayerNumber.P1 }; country.AdjacentCountryNames.Add("Testanbul"); game.AddCountry(country); Continent continent; continent = new Continent() { Name = "Testartica", Worth = 3, }; continent.CountryNames.Add("Testistan"); continent.CountryNames.Add("Testlyvania"); game.AddContinent(continent); continent = new Continent() { Name = "Testarica", Worth = 3, }; continent.CountryNames.Add("Testanbul"); continent.CountryNames.Add("Test States of America"); game.AddContinent(continent); return game; }