So im making a hangman gam3 it worked now im trying to make it w 2 players it aint working He4e is the code for everybutton (letter) When he clicks it
if (label13.Text == "Player 1 Guess")
{
if (Fullword.Contains(button2.Text))
{
char[] temp = Underscore_Word.ToCharArray();
char[] found = Fullword.ToCharArray();
for (int i = 0; i < found.Length; i++)
{
if (found[i] == button2.Text.ElementAt(0))
{
temp[i] = button2.Text.ElementAt(0);
}
}
Underscore_Word = new string(temp);
PrintLabel();
}
else
{
faux++;
}
if (faux < 7)
{
pictureBox1.Image = images[faux];
}
else
{
label1.Text = "you lose !!! ";
User.score--;
label7.Text = "Score of " + Methods.displayName + ": " + User.score.ToString();
label2.Visible = true;
label2.Text = "The word was :" + "\"" + Fullword + "\" ";
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "lose.wav";
player.Play();
}
if (Underscore_Word.Equals(Fullword))
{
label1.Text = "You Win!!";
User.score++;
label7.Text = "Score of " + Methods.displayName + ": " + User.score.ToString();
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "appllaud.wav";
player.Play();
}
label13.Text = "Player 2 Guess";
else
{
if (Fullword.Contains(button2.Text))
{
char[] temp = Underscore_Word.ToCharArray();
char[] found = Fullword.ToCharArray();
for (int i = 0; i < found.Length; i++)
{
if (found[i] == button2.Text.ElementAt(0))
{
temp[i] = button2.Text.ElementAt(0);
}
}
Underscore_Word = new string(temp);
PrintLabel();
}
else
{
faux_player2++;
}
if (faux_player2 < 7)
{
pictureBox2.Image = images[faux_player2];
}
else
{
label1.Text = "you lose !!! ";
User.score--;
label14.Text = "Score of " + Methods.displayName_playertwo + ": " + User.score_Player2.ToString();
label2.Visible = true;
label2.Text = "The word was :" + "\"" + Fullword + "\" ";
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "lose.wav";
player.Play();
}
if (Underscore_Word.Equals(Fullword))
{
label1.Text = "You Win!!";
User.score_Player2++;
label14.Text = "Score of " + Methods.displayName_playertwo + ": " + User.score_Player2.ToString(); ;
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "appllaud.wav";
player.Play();
}
label13.Text = "Player 1 Guess";
}
im having problems with the label its staying player 1 guess its alternating when the player gets a wrong guess please help
You are messing a }
after the label13.Text = "Player 2 Guess";
before the else
if (label13.Text == "Player 1 Guess")
{
// code ....
}
else
{
// code ....
}
I would also Advice you to try to write cleaner code and try to not repeat yourself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.