public void Save() { if (File.Exists("stats.xml")) { File.Delete("stats.xml"); } if (Points > mHighScore1) { mHighScore3 = mHighScore2; mHighScore2 = mHighScore1; mHighScore1 = Points; } else if (Points > mHighScore2 && Points < mHighScore1) { mHighScore3 = mHighScore2; mHighScore2 = Points; } else if (Points < mHighScore2 && Points > mHighScore3) { mHighScore3 = Points; } var saveState = new XmlDocument(); var xmlRoot = saveState.CreateElement("GameObjects"); // storing gold xmlRoot.SetAttribute("gold", OldGold >= EconomyManager.Instance.GoldAmount ? OldGold.ToString(CultureInfo.InvariantCulture) : EconomyManager.Instance.GoldAmount.ToString()); // storing killed zombies xmlRoot.SetAttribute("zombieskilled", ZombiesKilled.ToString(CultureInfo.InvariantCulture)); // storing max alive animals xmlRoot.SetAttribute("maxLivingAnimals", OldAnimalsAlive >= AnimalsAlive ? OldAnimalsAlive.ToString(CultureInfo.InvariantCulture) : AnimalsAlive.ToString(CultureInfo.InvariantCulture)); AnimalsAlive = 0; // storing max points xmlRoot.SetAttribute("points", OldPoints >= Points ? OldPoints.ToString(CultureInfo.InvariantCulture) : Points.ToString(CultureInfo.InvariantCulture)); // bought animals xmlRoot.SetAttribute("animals", Animals.ToString(CultureInfo.InvariantCulture)); // in game time xmlRoot.SetAttribute("gametime", ((int)OldGameTime + (int)Game1.mTime).ToString(CultureInfo.InvariantCulture)); xmlRoot.SetAttribute("lost", (GameLost).ToString()); xmlRoot.SetAttribute("win", (GameWon).ToString()); xmlRoot.SetAttribute("highscore1", mHighScore1.ToString()); xmlRoot.SetAttribute("highscore2", mHighScore2.ToString()); xmlRoot.SetAttribute("highscore3", mHighScore3.ToString()); saveState.AppendChild(xmlRoot); saveState.Save("stats.xml"); }