示例#1
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);
                newSuperRegion.StrategicValue = sr.StrategicValue;
                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);
        }
        public Region(int id, SuperRegion superRegion, String playerName, int armies)
        {
            this.Id          = id;
            this.SuperRegion = superRegion;
            this.Neighbors   = new List <Region>();
            this.PlayerName  = playerName;
            this.Armies      = armies;

            superRegion.AddSubRegion(this);
        }
        public Region(int id, SuperRegion superRegion)
        {
            this.Id          = id;
            this.SuperRegion = superRegion;
            this.Neighbors   = new List <Region>();
            this.PlayerName  = Constants.UnknownPlayerName;
            this.Armies      = 0;

            superRegion.AddSubRegion(this);
        }
示例#4
0
 /**
  * Add a SuperRegion to the map
  * @param superRegion : SuperRegion to be Added
  */
 public void Add(SuperRegion superRegion)
 {
     foreach (SuperRegion sr in superRegions)
     {
         if (sr.Id == superRegion.Id)
         {
             Console.Error.WriteLine("SuperRegion cannot be Added: id already exists.");
             return;
         }
     }
     superRegions.Add(superRegion);
 }