Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void SaveToXML(string path)
- {
- XmlDocument xDoc = new XmlDocument();
- var root = xDoc.CreateElement("GameCore");
- var activePlayer = xDoc.CreateElement("ActivePlayer");
- activePlayer.AppendChild(xDoc.CreateTextNode(ActivePlayer.ToString()));
- var player1Team = xDoc.CreateElement("FirstTeam");
- FillTeam(xDoc, player1Team, Player1Units);
- var player2Team = xDoc.CreateElement("SecondTeam");
- FillTeam(xDoc, player2Team, Player2Units);
- root.AppendChild(activePlayer);
- root.AppendChild(player1Team);
- root.AppendChild(player2Team);
- xDoc.AppendChild(root);
- xDoc.Save(path);
- }
- private void FillTeam(XmlDocument xDoc, XmlElement player1Team, List<Unit> player1Units)
- {
- for (int i = 0; i < player1Units.Count; ++i)
- {
- var t = xDoc.CreateElement("Unit");
- Unit t1 = player1Units[i];
- t.SetAttribute("Unit_name", t1.Unit_name);
- t.SetAttribute("AI_Value", t1.AI_Value.ToString());
- t.SetAttribute("Attack", t1.Attack.ToString());
- t.SetAttribute("Defence", t1.Defence.ToString());
- t.SetAttribute("Gold", t1.Gold.ToString());
- t.SetAttribute("Growth", t1.Growth.ToString());
- t.SetAttribute("Health", t1.Health.ToString());
- t.SetAttribute("MaximumDamage", t1.MaximumDamage.ToString());
- t.SetAttribute("MinimumDamage", t1.MinimumDamage.ToString());
- t.SetAttribute("Speed", t1.Speed.ToString());
- player1Team.AppendChild(t);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement