Advertisement
washinson

Untitled

Feb 23rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1.         public void SaveToXML(string path)
  2.         {
  3.             XmlDocument xDoc = new XmlDocument();
  4.  
  5.             var root = xDoc.CreateElement("GameCore");
  6.  
  7.             var activePlayer = xDoc.CreateElement("ActivePlayer");
  8.             activePlayer.AppendChild(xDoc.CreateTextNode(ActivePlayer.ToString()));
  9.  
  10.             var player1Team = xDoc.CreateElement("FirstTeam");
  11.             FillTeam(xDoc, player1Team, Player1Units);
  12.  
  13.             var player2Team = xDoc.CreateElement("SecondTeam");
  14.             FillTeam(xDoc, player2Team, Player2Units);
  15.  
  16.             root.AppendChild(activePlayer);
  17.             root.AppendChild(player1Team);
  18.             root.AppendChild(player2Team);
  19.  
  20.             xDoc.AppendChild(root);
  21.  
  22.             xDoc.Save(path);
  23.         }
  24.  
  25.         private void FillTeam(XmlDocument xDoc, XmlElement player1Team, List<Unit> player1Units)
  26.         {
  27.             for (int i = 0; i < player1Units.Count; ++i)
  28.             {
  29.                 var t = xDoc.CreateElement("Unit");
  30.                 Unit t1 = player1Units[i];
  31.                 t.SetAttribute("Unit_name", t1.Unit_name);
  32.                 t.SetAttribute("AI_Value", t1.AI_Value.ToString());
  33.                 t.SetAttribute("Attack", t1.Attack.ToString());
  34.                 t.SetAttribute("Defence", t1.Defence.ToString());
  35.                 t.SetAttribute("Gold", t1.Gold.ToString());
  36.                 t.SetAttribute("Growth", t1.Growth.ToString());
  37.                 t.SetAttribute("Health", t1.Health.ToString());
  38.                 t.SetAttribute("MaximumDamage", t1.MaximumDamage.ToString());
  39.                 t.SetAttribute("MinimumDamage", t1.MinimumDamage.ToString());
  40.                 t.SetAttribute("Speed", t1.Speed.ToString());
  41.  
  42.                 player1Team.AppendChild(t);
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement