i am beginner programmer who is creating a hangman game so i am going to show you codes that's i used and which one is not working.
string target;
public int attempt = 0;
public void firststage()
{
pictureBox1.Image = Image.FromFile(@"C:\Users\OmarS_000\Documents\Visual Studio 2015\Projects\HangMan\HangMan\stage1.png");
attempt++;
}
private void buttonZ_Click(object sender, EventArgs e)
{
matching('z');
}
now the code which is not working.
public void matching(char _thechar)
{
if (target.Contains(_thechar))
{
MessageBox.Show("Corret");
}
else
{
switch (attempt)
{
case (0):
firststage();
break;
case (1):
secondstage();
break;
case (2):
thirdstage();
break;
case (3):
fourthstage();
break;
case (4):
fifthstage();
break;
case (5):
death();
break;
}
}
}
the code works if the letters exist it shows the MessageBox Correct. but if the letter z didn't exist in string target it does nothing. i even tried replacing displaying the picture with messagebox but it didn't work too. PS: target is a string which gets a random word from an array.
so to make it clear. how can i make the code works.
Aucun commentaire:
Enregistrer un commentaire