private void startButton_Click(object sender, EventArgs e) { countdownTimer.Start(); gameTimer.Start(); if (difficulty == 3) { FriendlyFireTimer.Start(); } pictureBox1.Visible = true; button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; score = 0; scoreLabel.Text = "0"; if (difficulty == 3) { //pictureBox2.Location = new Point(rnd.Next(minX + offsetX2, minX + panel1.Size.Width - offsetX2), rnd.Next(minY + offsetY2, minY + panel1.Size.Height - offsetY2)); pictureBox2.Location = new Point(minX, rnd.Next(minY + offsetY2, minY + panel1.Size.Height - offsetY2)); pictureBox2.Show(); } }
private void timer1_Tick(object sender, EventArgs e) { timeLeft--; timeLabel.Text = timeLeft.ToString(); if (difficulty == 3) { gameTimer.Interval = rnd.Next(500, 1000); //FriendlyFireTimer.Interval = 5000; } else if (difficulty == 2) { gameTimer.Interval = 900; } else { gameTimer.Interval = 1000; } if (timeLeft == 0) { pictureBox1.Hide(); pictureBox2.Hide(); countdownTimer.Stop(); gameTimer.Stop(); FriendlyFireTimer.Stop(); timeLeft = 30; MessageBox.Show("Game Over\nYour score is: " + score.ToString()); timeLabel.Text = timeLeft.ToString(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; FileStream fs = new FileStream("players.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); StreamReader readText = new StreamReader(fs); StreamWriter writeText = new StreamWriter(fs); string newText = readText.ReadToEnd(); string[] textpin = newText.Split('\n'); string[] date = DateTime.Now.ToString().Split(' '); for (int i = 0; i < textpin.Length - 1; i++) { string[] subtext = textpin[i].Split(' '); if (subtext[0] == PlayerName) { subtext[2] = date[0]; subtext[3] = date[1]; subtext[4] = date[2]; if (score > highScore) { subtext[1] = score.ToString(); } textpin[i] = String.Join(" ", subtext); } } newText = String.Join("\n", textpin); //newText = newText.Replace(PlayerName + " " + highScore, PlayerName + " " + score.ToString()); fs.SetLength(0); writeText.Write(newText); writeText.Flush(); fs.Close(); highScore = score; highScoreLabel.Text = highScore.ToString(); } }