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;
string[] simplewords = new string[] { "apple", "orange","pie","tank","banana","cat","keyboard" };
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.
EDIT: i will add the rest of the code to make it easier to define the problem.
public void generateeasyword()
{
Random r = new Random();
int ra = r.Next(0, simplewords.Length);
target = simplewords[ra];
}
public void begin() // the word is a label in my form
{
theword.Text = target;
theword.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
generateeasyword();
begin();
}
this is the rest of my code