mirror of
https://github.com/Alvin-Zilverstand/ict-algemeen-opdrachten.git
synced 2026-03-06 13:23:58 +01:00
Add restart button functionality to Gokspel game
This commit is contained in:
@@ -10,6 +10,7 @@ class Program : Form
|
|||||||
private TextBox inputBox;
|
private TextBox inputBox;
|
||||||
private Label resultLabel;
|
private Label resultLabel;
|
||||||
private Button guessButton;
|
private Button guessButton;
|
||||||
|
private Button restartButton;
|
||||||
private System.Windows.Forms.Timer confettiTimer;
|
private System.Windows.Forms.Timer confettiTimer;
|
||||||
private List<Confetti> confettiList = new List<Confetti>();
|
private List<Confetti> confettiList = new List<Confetti>();
|
||||||
|
|
||||||
@@ -41,6 +42,13 @@ class Program : Form
|
|||||||
resultLabel.AutoSize = true;
|
resultLabel.AutoSize = true;
|
||||||
this.Controls.Add(resultLabel);
|
this.Controls.Add(resultLabel);
|
||||||
|
|
||||||
|
restartButton = new Button();
|
||||||
|
restartButton.Text = "Opnieuw";
|
||||||
|
restartButton.Location = new System.Drawing.Point(10, 140);
|
||||||
|
restartButton.Click += new EventHandler(RestartButton_Click);
|
||||||
|
restartButton.Visible = false;
|
||||||
|
this.Controls.Add(restartButton);
|
||||||
|
|
||||||
confettiTimer = new System.Windows.Forms.Timer();
|
confettiTimer = new System.Windows.Forms.Timer();
|
||||||
confettiTimer.Interval = 30;
|
confettiTimer.Interval = 30;
|
||||||
confettiTimer.Tick += new EventHandler(ConfettiTimer_Tick);
|
confettiTimer.Tick += new EventHandler(ConfettiTimer_Tick);
|
||||||
@@ -63,6 +71,7 @@ class Program : Form
|
|||||||
{
|
{
|
||||||
resultLabel.Text = "Gefeliciteerd! Je hebt het juiste getal geraden.";
|
resultLabel.Text = "Gefeliciteerd! Je hebt het juiste getal geraden.";
|
||||||
StartConfetti();
|
StartConfetti();
|
||||||
|
restartButton.Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -71,6 +80,17 @@ class Program : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RestartButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
numberToGuess = random.Next(1, 101);
|
||||||
|
resultLabel.Text = "";
|
||||||
|
inputBox.Text = "";
|
||||||
|
confettiList.Clear();
|
||||||
|
confettiTimer.Stop();
|
||||||
|
restartButton.Visible = false;
|
||||||
|
this.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
private void StartConfetti()
|
private void StartConfetti()
|
||||||
{
|
{
|
||||||
confettiList.Clear();
|
confettiList.Clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user