public PlaceArmiesMove(string player, Region region, int armies) : base(player) { Region = region; Armies = armies; if (Logger.IsDebug ()) { Logger.Debug (string.Format ("PlaceArmiesMove:\tInitialized by {0} who puts {1} armies into region {2}.", player, armies, region.Id)); } else { Logger.Info ("PlaceArmiesMove:\tInitialized."); } }
public AttackTransferMove(string player, Region sourceRegion, Region targetRegion, int armies) : base(player) { SourceRegion = sourceRegion; TargetRegion = targetRegion; Armies = armies; if (Logger.IsDebug ()) { Logger.Debug (string.Format ("AttackTransferMove:\tInitialized by {0} who moves {1} armies " + "from region {2} to region {3}.", player, armies, sourceRegion.Id, targetRegion.Id)); } else { Logger.Info ("AttackTransferMove:\tInitialized."); } }
/// <summary> /// This method sets up the regions, and is only used when the game /// gets initialized. /// </summary> /// <param name="commandParts">Command parts.</param> public void Regions(string[] commandParts) { int id, continentId; Region region; Continent continent; for (int i = 2; i < commandParts.Length; i += 2) { id = int.Parse (commandParts [i]); continentId = int.Parse (commandParts [i + 1]); continent = State.CompleteMap.ContinentForId (continentId); if (continent == null) { Logger.Info (string.Format("Parser:\tFailed to add region {0} with the unkown continent {1}.", id, continentId)); continue; } else { region = new Region (id, continent); } State.CompleteMap.AddRegion (region); } if (Logger.IsDebug ()) { Logger.Debug ("Parser:\tSet up regions."); } }
/// <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)); } }
/// <summary> /// Adds a neighbor to this region's list of neighbors. /// </summary> /// <param name="region">Region.</param> public void AddNeighbor(Region region) { if (!region.Equals (this) && !Neighbors.Contains (region)) { Neighbors.Add (region); region.AddNeighbor (this); if (IsBorderRegion ()) { Continent.BorderRegions.Add (this); } if (Logger.IsDebug ()) { Logger.Debug (string.Format("Region {0}:\tAdded neighbor {1}.", Id, region.Id)); } } }
/// <summary> /// Adds the region to the map. /// </summary> /// <param name="region">Region.</param> public void AddRegion(Region region) { if (!Regions.ContainsKey (region.Id)) { Regions.Add (region.Id, region); AddContinent (region.Continent); if (Logger.IsDebug ()) { Logger.Debug (string.Format("Map:\tRegion {0} added.", region.Id)); } } }
/// <summary> /// Adds a region to the continent, and check if it is a border region. /// </summary> /// <param name="region">Region.</param> public void AddRegion(Region region) { if (!Regions.Contains (region)) { Regions.Add (region); if (region.IsBorderRegion ()) { BorderRegions.Add (region); } if (Logger.IsDebug ()) { Logger.Debug (string.Format ("Continent:\tRegion {0} added to continent {1}", region.Id, Id)); } } }
/// <summary> /// Adds a region to the list of border region. /// </summary> /// <param name="region">Region.</param> public void AddBorderRegion(Region region) { if (!BorderRegions.Contains (region) && region.IsBorderRegion ()) { BorderRegions.Add (region); } }