Dreamer
New member
- Joined
- Mar 26, 2017
- Messages
- 3
- Programming Experience
- Beginner
I need to make three different forms to load :
1- a form when the results are tie,
2-a form when the computer wins,
3-a form when the user wins,
I am trying now for one form which is; when the results are tie.
However, it does not work tho i used a while loop for -checkresult();- method and I break it when the scores reach 20 .
Can anyone please help me?!
source code:
private void btnPlay_Click(object sender, EventArgs e)
{
Random r = new Random(); //create a new random object r
compChoice = r.Next(3) + 1; //use r to pick a number from 1 to 3
if (compChoice == 1)
{
pbxComputer.Image = Image.FromFile("Scissors.jpg");
}
else if (compChoice == 2)
{
pbxComputer.Image = Image.FromFile("Paper.jpg");
}
else if (compChoice == 3)
{
pbxComputer.Image = Image.FromFile("Stone.jpg");
}
while (userScore != 20 || compScore != 20)
{
checkResult(); // call the checkResult(); method
if (compScore == 20 || userScore == 20)
{
break;
}
}
finish();
}
private void checkResult()
{
lblResult.BackColor = Color.White;
lblUserScore.BackColor = Color.White;
lblComputerScore.BackColor = Color.White;
if (compChoice == userChoice)
{
lblResult.Text = "It's a DRAW!";
compScore += 1;
userScore += 1;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 1 && userChoice == 2) //scissors / paper
{
lblResult.Text = "Computer WINS!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 1 && userChoice == 3) //scissors / stone
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
else if (compChoice == 2 && userChoice == 1) //paper / scissors
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
else if (compChoice == 2 && userChoice == 3) //paper / stone
{
lblResult.Text = "Computer WINS!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 3 && userChoice == 1) //stone /scissors
{
lblResult.Text = "Computer WINs!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 3 && userChoice == 2) //stone / paper
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
lblComputerScore.Text = "Computer Score \n" + compScore.ToString();
lblUserScore.Text = "User Score \n" + userScore.ToString();
}
private void finish()
{
if(compScore == userScore)
{
//load the Draw form
frmDraw draw = new frmDraw();
draw.ShowDialog();
}
}
1- a form when the results are tie,
2-a form when the computer wins,
3-a form when the user wins,
I am trying now for one form which is; when the results are tie.
However, it does not work tho i used a while loop for -checkresult();- method and I break it when the scores reach 20 .
Can anyone please help me?!
source code:
private void btnPlay_Click(object sender, EventArgs e)
{
Random r = new Random(); //create a new random object r
compChoice = r.Next(3) + 1; //use r to pick a number from 1 to 3
if (compChoice == 1)
{
pbxComputer.Image = Image.FromFile("Scissors.jpg");
}
else if (compChoice == 2)
{
pbxComputer.Image = Image.FromFile("Paper.jpg");
}
else if (compChoice == 3)
{
pbxComputer.Image = Image.FromFile("Stone.jpg");
}
while (userScore != 20 || compScore != 20)
{
checkResult(); // call the checkResult(); method
if (compScore == 20 || userScore == 20)
{
break;
}
}
finish();
}
private void checkResult()
{
lblResult.BackColor = Color.White;
lblUserScore.BackColor = Color.White;
lblComputerScore.BackColor = Color.White;
if (compChoice == userChoice)
{
lblResult.Text = "It's a DRAW!";
compScore += 1;
userScore += 1;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 1 && userChoice == 2) //scissors / paper
{
lblResult.Text = "Computer WINS!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 1 && userChoice == 3) //scissors / stone
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
else if (compChoice == 2 && userChoice == 1) //paper / scissors
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
else if (compChoice == 2 && userChoice == 3) //paper / stone
{
lblResult.Text = "Computer WINS!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 3 && userChoice == 1) //stone /scissors
{
lblResult.Text = "Computer WINs!";
compScore += 2;
lblResult.ForeColor = Color.Black;
}
else if (compChoice == 3 && userChoice == 2) //stone / paper
{
lblResult.Text = "You WIN!";
userScore += 2;
lblResult.BackColor = Color.Red;
lblResult.ForeColor = Color.Yellow;
}
lblComputerScore.Text = "Computer Score \n" + compScore.ToString();
lblUserScore.Text = "User Score \n" + userScore.ToString();
}
private void finish()
{
if(compScore == userScore)
{
//load the Draw form
frmDraw draw = new frmDraw();
draw.ShowDialog();
}
}