/// <summary> /// Returns a copy of this map and all of its contents, with new instances of each object (Map, SuperRegions, Regions). /// </summary> /// <returns></returns> public Map GetMapCopy() { Map newMap = new Map(); foreach (SuperRegion sr in SuperRegions) { SuperRegion newSuperRegion = new SuperRegion(sr.ID, sr.ArmiesReward); newMap.AddSuperRegion(newSuperRegion); } foreach (Region r in Regions) { Region newRegion = new Region(r.ID, newMap.GetSuperRegionByID(r.SuperRegion.ID), r.PlayerName, r.Armies); newMap.AddRegion(newRegion); } foreach (Region r in Regions) { Region newRegion = newMap.GetRegionByID(r.ID); foreach (Region neighbor in r.Neighbors) { newRegion.AddNeighbor(newMap.GetRegionByID(neighbor.ID)); } } return newMap; }
public Region(int id, SuperRegion superRegion, String playerName, int armies) { this._id = id; this.SuperRegion = superRegion; this.Neighbors = new List<Region>(); this.PlayerName = playerName; Armies = armies; superRegion.addSubRegion(this); }
/** * add a SuperRegion to the map * @param superRegion : SuperRegion to be added */ public void AddSuperRegion(SuperRegion superRegion) { var existing = GetSuperRegionByID(superRegion.ID); if (existing != null) { Console.Error.WriteLine("SuperRegion cannot be added: id already exists."); return; } SuperRegions.Add(superRegion); }