public Game LoadFromXmlFile(string xmlPath)
        {
            XDocument xml = XDocument.Load(xmlPath);

            XElement map      = xml.Element("map");
            string   gameName = map.Attribute("name").Value;
            Game     game     = new Game(gameName);

            string backgroundImagePath = map.Attribute("background").Value;
            //game.backgroundImage = Image.FromFile(backgroundImagePath);

            int width  = int.Parse(map.Attribute("width").Value);
            int height = int.Parse(map.Attribute("height").Value);

            game.GameSize = new Size(width, height);

            var xmlContinents = map.Element("continents").Elements();

            foreach (XElement xmlContinent in xmlContinents)
            {
                Continent continent = new Continent(xmlContinent.Attribute("name").Value);

                foreach (XElement xmlTerritory in xmlContinent.Elements())
                {
                    string name            = xmlTerritory.Element("territory.name").Value;
                    string labelPointValue = xmlTerritory.Element("territory.labelpoint").Value;

                    string    borderPointsValue = xmlTerritory.Element("territory.border").Value;
                    Territory territory         = new Territory(name)
                    {
                        LabelCoordinates = toPoint(labelPointValue),
                        Border           = toPointList(borderPointsValue),
                        Game             = game
                    };

                    continent.AddTerritories(territory);
                }
                game.Continents.Add(continent);
            }

            XElement allNeighbours = map.Element("allneighbours");

            foreach (XElement xmlNeighbours in allNeighbours.Elements())
            {
                Territory[] territories = new Territory[2];
                uint        index       = 0;
                foreach (XElement xmlNeighbour in xmlNeighbours.Elements())
                {
                    string neighbourName = xmlNeighbour.Attribute("name").Value;
                    territories[index] = game.getTerritory(neighbourName);
                    index++;
                }
                territories[0].AddNeighbours(territories[1]);
                territories[1].AddNeighbours(territories[0]);
            }

            return(game);
        }
Exemple #2
0
 private void AddTerritoriesToContinents()
 {
     Europe.AddTerritories(EuropeTerritories);
     Asia.AddTerritories(AsiaTerritories);
 }