Compare commits

...

4 Commits

View File

@ -3,15 +3,62 @@ namespace GuessTheCard
public partial class Form1 : Form public partial class Form1 : Form
{ {
private int score = 0; private int score = 0;
private int previousDice;
private Random random = new Random();
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
Random random = new Random();
int randomDice = random.Next(1, 7); int randomDice = random.Next(1, 7);
previousDice = randomDice;
labelCard.Text = "Result : " + randomDice; labelCard.Text = "Result : " + randomDice;
labelScore.Text = "Score: " + score; 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);
}
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;
} }
} }
} }