/// <summary> /// Make an exact copy of this map. /// </summary> /// <returns>A new Map object exactly the same as this one.</returns> public Map GetMapCopy() { var newMap = new Map(); foreach (var sr in SuperRegions) //copy superRegions { var newSuperRegion = new SuperRegion(sr.Id, sr.ArmiesReward); newMap.Add(newSuperRegion); } foreach (var r in Regions) //copy regions { var newRegion = new Region(r.Id, newMap.GetSuperRegion(r.SuperRegion.Id), r.PlayerName, r.Armies); newMap.Add(newRegion); } foreach (var r in Regions) //add neighbors to copied regions { var newRegion = newMap.GetRegion(r.Id); foreach (var neighbor in r.Neighbors) { newRegion.AddNeighbor(newMap.GetRegion(neighbor.Id)); } } return(newMap); }
/// <summary> /// Create an inhabited region. /// </summary> /// <param name="id">Unique ID of this Region.</param> /// <param name="superRegion">SuperRegion this Region belongs to.</param> /// <param name="playerName">Owner of this Region.</param> /// <param name="armies">Number of armies in this region.</param> public Region(int id, SuperRegion superRegion, string playerName, int armies) { Id = id; SuperRegion = superRegion; Neighbors = new List <Region>(); PlayerName = playerName; Armies = armies; superRegion.AddSubRegion(this); }
/// <summary> /// Create an empty region. /// </summary> /// <param name="id">Unique ID of this Region.</param> /// <param name="superRegion">SuperRegion this Region belongs to.</param> public Region(int id, SuperRegion superRegion) { Id = id; SuperRegion = superRegion; Neighbors = new List <Region>(); PlayerName = "unknown"; Armies = 0; superRegion.AddSubRegion(this); }
/// <summary> /// Add a SuperRegion to the map /// </summary> /// <param name="superRegion">SuperRegion to be added.</param> public void Add(SuperRegion superRegion) { foreach (var s in SuperRegions) { if (s.Id == superRegion.Id) { Console.Error.WriteLine("SuperRegion cannot be added: id already exists."); return; } } SuperRegions.Add(superRegion); }