Beispiel #1
0
 public void AddNeighbor(Region neighbor)
 {
     if (!Neighbors.Contains(neighbor))
     {
         Neighbors.Add(neighbor);
         neighbor.AddNeighbor(this);
     }
 }
Beispiel #2
0
        /**
         * @return : a new Map object exactly the same as this one
         */
        public Map GetMapCopy()
        {
            Map newMap = new Map();

            foreach (SuperRegion sr in SuperRegions) //copy superRegions
            {
                SuperRegion newSuperRegion = new SuperRegion(sr.Id, sr.ArmiesReward);
                newMap.Add(newSuperRegion);
            }
            foreach (Region r in Regions) //copy regions
            {
                Region newRegion = new Region(r.Id, newMap.GetSuperRegion(r.SuperRegion.Id), r.PlayerName, r.Armies);
                newMap.Add(newRegion);
            }
            foreach (Region r in Regions) //Add neighbors to copied regions
            {
                Region newRegion = newMap.GetRegion(r.Id);
                foreach (Region neighbor in r.Neighbors)
                {
                    newRegion.AddNeighbor(newMap.GetRegion(neighbor.Id));
                }
            }
            return(newMap);
        }
Beispiel #3
0
 /**
  * @return : a new Map object exactly the same as this one
  */
 public Map GetMapCopy()
 {
     Map newMap = new Map();
     foreach (SuperRegion sr in superRegions) //copy superRegions
     {
         SuperRegion newSuperRegion = new SuperRegion(sr.Id, sr.ArmiesReward);
         newMap.Add(newSuperRegion);
     }
     foreach (Region r in regions) //copy regions
     {
         try
         {
             Region newRegion = new Region(r.Id, newMap.GetSuperRegion(r.SuperRegion.Id), r.PlayerName, r.Armies);
             newMap.Add(newRegion);
         }
         catch (Exception exc) {
             Console.Error.WriteLine(exc.Message);
             Console.Error.WriteLine("couldn't copy region");
             Console.Error.WriteLine("id: " + r.Id);
             Console.Error.WriteLine("parent: " + r.SuperRegion.Id);
             Console.Error.WriteLine("playername: " + r.PlayerName);
             Console.Error.WriteLine("armies: " + r.Armies);
         }
     }
     foreach (Region r in regions) //Add neighbors to copied regions
     {
         Region newRegion = newMap.GetRegion(r.Id);
         foreach (Region neighbor in r.Neighbors)
             newRegion.AddNeighbor(newMap.GetRegion(neighbor.Id));
     }
     return newMap;
 }
 public void AddNeighbor(Region neighbor)
 {
     if (!neighbors.Contains(neighbor))
     {
         neighbors.Add(neighbor);
         neighbor.AddNeighbor(this);
     }
 }