/// <summary> /// Adds the continent to the map. /// </summary> /// <param name="continent">Continent.</param> public void AddContinent(Continent continent) { if (!Continents.Contains (continent)) { Continents.Add (continent); foreach (Region r in continent.Regions) { AddRegion (r); } } if (Logger.IsDebug ()) { Logger.Debug (string.Format("Map:\tContinent {0} added.", continent.Id)); } }
public Region(int id, Continent continent) { this.Id = id; Neighbors = new List<Region> (); this.Continent = continent; continent.AddRegion (this); Armies = 2; Owner = "unknown"; if (Logger.IsDebug ()) { Logger.Debug (string.Format("Region {0}:\tInitialized with continent {1}", id, continent.Id)); } else { Logger.Info (string.Format("Region {0}:\tInitialized.", id)); } }
/// <summary> /// This method sets up the continents, and is only used when the /// game gets initialized. /// </summary> /// <param name="commandParts">Command parts.</param> public void SuperRegions(string[] commandParts) { int id, reward; Continent continent; for (int i = 2; i < commandParts.Length; i += 2) { id = int.Parse(commandParts [i]); reward = int.Parse(commandParts [i + 1]); continent = new Continent (id, reward); State.CompleteMap.AddContinent (continent); } if (Logger.IsDebug ()) { Logger.Debug ("Parser:\tSet up continents."); } }
/// <summary> /// Checks if you own a given continent. /// </summary> /// <returns><c>true</c>, if continent was owned, <c>false</c> otherwise.</returns> /// <param name="continent">Continent.</param> public bool OwnsContinent(Continent continent) { if (OwnedContinents.Contains (continent)) { return true; } else { return false; } }
/// <summary> /// Called whenever you conquer a continent, updates your armies. /// </summary> /// <param name="continent">Continent.</param> public void LoseContinent(Continent continent) { if (OwnedContinents.Contains (continent)) { OwnedContinents.Remove (continent); ArmiesPerTurn -= continent.Reward; } }
/// <summary> /// Called whenever you conquer a continent, updates your armies. /// </summary> /// <param name="continent">Continent.</param> public void GainContinent(Continent continent) { if (!OwnedContinents.Contains (continent)) { OwnedContinents.Add (continent); ArmiesPerTurn += continent.Reward; } }
/// <summary> /// Updates the map. /// </summary> /// <param name="player">Player.</param> /// <param name="regionId">Region identifier.</param> /// <param name="armies">Armies.</param> public void UpdateMap(int regionId, string player, int armies) { if (VisibleMap.Regions.ContainsKey (regionId)) { Region originalRegion = VisibleMap.Regions [regionId]; originalRegion = VisibleMap.Regions [regionId]; originalRegion.Owner = player; originalRegion.Armies = armies; } else { Region originalRegion = CompleteMap.Regions [regionId]; Region newRegion; Continent continent; if (!VisibleMap.Continents.Contains (originalRegion.Continent)) { Continent originalContinent = originalRegion.Continent; Continent newContinent = new Continent (originalContinent.Id, originalContinent.Reward); VisibleMap.Continents.Add (newContinent); } continent = VisibleMap.ContinentForId (originalRegion.Continent.Id); newRegion = new Region (originalRegion.Id, continent); foreach (Region n in originalRegion.Neighbors) { if (VisibleMap.Regions.ContainsKey (n.Id)) { newRegion.AddNeighbor (VisibleMap.Regions[n.Id]); } } newRegion.Owner = player; newRegion.Armies = armies; VisibleMap.AddRegion (newRegion); } if (Logger.IsDebug ()) { Logger.Debug (string.Format("State:\tUpdated region {0} with owner {1} and {2} armies.", regionId, player, armies)); } }