private static void addPlayerToHistoric(PlayerDatas p) { byte[] byteArray = Encoding.ASCII.GetBytes("PlayersHistoric.xml"); MemoryStream stream = new MemoryStream(byteArray); XElement x = new XElement("player"); x.Add(new XAttribute("name", p.getName())); x.Add(new XAttribute("points", p.getPoints().ToString())); XElement xml = XElement.Load("PlayersHistoric.xml"); xml.Add(x); xml.Save(stream); }
private static void editPalyerHistoric(PlayerDatas player) { byte[] byteArray = Encoding.ASCII.GetBytes("PlayersHistoric.xml"); MemoryStream stream = new MemoryStream(byteArray); XElement xml = XElement.Load("PlayersHistoric.xml"); if (xml.HasElements) { XElement x = xml.Elements().Where(p => p.Attribute("name").Value.Equals(player.getName())).First(); if (x != null) { if ((int.Parse(x.Attribute("points").Value)) < player.getPoints()) { x.Attribute("points").SetValue(player.getPoints().ToString()); } } xml.Save(stream); } }
private static bool existThePlayer(PlayerDatas player) { byte[] byteArray = Encoding.UTF8.GetBytes("PlayersHistoric.xml"); MemoryStream stream = new MemoryStream(byteArray); XElement xml = XElement.Load("PlayersHistoric.xml"); if (xml.HasElements) { XElement x = xml.Elements().Where(p => p.Attribute("name").Value.Equals(player.getName())).First(); if (x != null) { return(true); } else { return(false); } } else { return(false); } }