/// <summary> /// Konstruktor, inicializálja a hexagont. /// </summary> /// <param name="produceNumber">Mely dobásra termel</param> /// <param name="material">A mezõ nyersanyaga</param> public Hexagon(int produceNumber, Material material, Hexid id) : this(null) { Material = material; ProduceNumber = produceNumber; Id = id; Neighbours = new List<Hexagon>(); }
/// <summary> /// Xml visszatöltése lementett állapotból /// </summary> /// <param name="filename">betöltendő fájlnév</param> public static void Load(String filename) { int size, score; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode scoreNode = doc.DocumentElement.SelectSingleNode("/Table/Winnerscore"); score = Int32.Parse(scoreNode.InnerText); XmlNode sizeNode = doc.DocumentElement.SelectSingleNode("/Table/Tablesize"); size = Int32.Parse(sizeNode.InnerText); XmlNodeList pnodes = doc.DocumentElement.SelectNodes("/Table/Players/Player"); (GameController.Instance.Players as List<Player>).Clear(); foreach (XmlNode node in pnodes) { var attr = node.Attributes; if (attr.Count != 0) { Player p = new Player(); PlayerColor c = (PlayerColor)Enum.Parse(typeof(PlayerColor), attr["color"].Value, true); p.Color = c; p.Name = attr["name"].Value; p.Gold = Int32.Parse(attr["gold"].Value); (GameController.Instance.Players as List<Player>).Add(p); } } var random = new Random(); var materials = new[] { Material.Wood, Material.Wool, Material.Clay, Material.Wheat, Material.Iron }; for (var j = 0; j < size; ++j) { for (var i = 0; i < size - Math.Abs(Math.Floor(size / 2.0) - j); ++i) { var h = new Hexagon(10, materials[random.Next(0, materials.Length)], new Hexid(j, i)); GameController.Instance.Hexagons.Add(h); } } foreach (Hexagon hex in GameController.Instance.Hexagons) { GameController.Instance.InitializeHexagonNeighbours(hex, (int)(Math.Floor(size / 2.0)), new Random()); } XmlNodeList hnodes = doc.DocumentElement.SelectNodes("/Table/Hexagons/Hexagon"); foreach (XmlNode node in hnodes) { Hexagon hex = null; Nullable<Hexid> id = null; var index = 0; if (node.Attributes.Count != 0) { id = new Hexid(Int32.Parse(node.Attributes["col"].Value), Int32.Parse(node.Attributes["row"].Value)); index = GameController.Instance.Hexagons.FindIndex(x => x.Id.Equals(id)); hex = GameController.Instance.Hexagons[index]; string mat = node.Attributes["material"].Value; int produceNumber = Int32.Parse(node.Attributes["number"].Value); Material material = (Material)Enum.Parse(typeof(Material), mat, true); hex.ProduceNumber = produceNumber; hex.Material = material; } XmlNode settlNode = node.ChildNodes[0]; if (settlNode.HasChildNodes) { for (int i = 0; i < settlNode.ChildNodes.Count; ++i) { Int32 num = Int32.Parse(settlNode.ChildNodes[i].Attributes["nodeNumber"].Value); string owner = settlNode.ChildNodes[i].Attributes["owner"].Value; Player p = GameController.Instance.Players.First(x => x.Color.ToString() == owner); hex.SetTown(new Settlement(p), num); } } XmlNode roadNode = node.ChildNodes[1]; if (roadNode.HasChildNodes) { for (int i = 0; i < roadNode.ChildNodes.Count; ++i) { Int32 side = Int32.Parse(roadNode.ChildNodes[i].Attributes["side"].Value); string owner = roadNode.ChildNodes[i].Attributes["owner"].Value; Player p = GameController.Instance.Players.First(x => x.Color.ToString() == owner); hex.SetRoad(p, side); } } GameController.Instance.Hexagons[index] = hex; } }