guess-the-card/Form1.cs

65 lines
1.5 KiB
C#
Raw Normal View History

2026-04-11 10:59:54 +07:00
namespace GuessTheCard
{
public partial class Form1 : Form
{
2026-04-11 11:47:26 +07:00
private int score = 0;
2026-04-11 12:01:34 +07:00
private int previousDice;
private Random random = new Random();
2026-04-11 11:47:26 +07:00
2026-04-11 10:59:54 +07:00
public Form1()
{
InitializeComponent();
2026-04-11 11:40:45 +07:00
int randomDice = random.Next(1, 7);
2026-04-11 12:01:34 +07:00
previousDice = randomDice;
2026-04-11 11:40:45 +07:00
labelCard.Text = "Result : " + randomDice;
2026-04-11 11:47:26 +07:00
labelScore.Text = "Score: " + score;
buttonHigh.Click += buttonHigh_Click;
buttonLow.Click += buttonLow_Click;
}
private void buttonHigh_Click(object sender, EventArgs e)
{
PlayRound(1);
}
private void buttonLow_Click(object sender, EventArgs e)
{
PlayRound(0);
2026-04-11 10:59:54 +07:00
}
2026-04-11 12:06:29 +07:00
private void PlayRound(int guess)
{
int newDice = random.Next(1, 7);
bool isCorrect = false;
if (newDice > previousDice)
{
isCorrect = (guess == 1);
}
else if (newDice < previousDice)
{
isCorrect = (guess == 0);
}
else
{
isCorrect = true;
}
if (isCorrect)
{
score += 5000;
}
else
{
score = 0;
}
previousDice = newDice;
labelCard.Text = "Result : " + newDice;
labelScore.Text = "Score: " + score;
}
2026-04-11 10:59:54 +07:00
}
}