private void button2_Click(object sender, EventArgs e) { if (OldGold.Text == "" || P1.Text == "" || P2.Text == "" || NewGold.Text == "") { MessageBox.Show("Enter the missing"); OldGold.Focus(); } else { float OldGold1 = float.Parse(OldGold.Text); float Price1 = float.Parse(P1.Text); float Price2 = float.Parse(P2.Text); int i = 0; float NewGold1 = float.Parse(NewGold.Text); while (true) { if (OldGold1 < NewGold1) { OldGold1 *= Price1 * Price2; } else { break; } i++; } redobox.Text = i.ToString(); } }
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"); }