I am a beginner in xcode and objective-c , And I just follow all the steps in the lesson I have watched in youtube to create hangman game. but there is an error in switch case
when I enter wrong letter the images should be updated but what happen is when I enter the second wrong letter it just go to the default case and start again.
( but in the correct situation, the length of string (WrongLetter) should be incremented by 1 and then enter the case 2 and so on).
The word is: colorado ( For those who will run the program )
if (match==NO)
{
self.WrongLetter = [self.WrongLetter stringByReplacingOccurrencesOfString:LetterToCheck withString: @""];
self.WrongLetter = [self.WrongLetter stringByAppendingString:LetterToCheck];
switch (self.WrongLetter.length) {
case 1:
{self.HangMan.image = [UIImage imageNamed:@"head"];
break;}
case 2:{
self.HangMan.image = [UIImage imageNamed:@"HB"];
break;}
case 3:{
self.HangMan.image = [UIImage imageNamed:@"HBA"];
break;}
case 4:{
self.HangMan.image = [UIImage imageNamed:@"HBAs"];
break;}
case 5:{
self.HangMan.image = [UIImage imageNamed:@"HBAL"];
break;}
case 6:{
self.HangMan.image = [UIImage imageNamed:@"CompleteMan"];
break;}
default:{
[self SetHangManWord:self.CorrectWord];
break; }
} }
This is my project:
http://www.2shared.com/file/BLHIQ6kQ/HM_online.html
And this is the lesson in the youtube:
http://www.youtube.com/watch?v=I63BSGsFnEw
I would appreciate any help 🙂
Change this:
To this:
The WrongLetter property gets released too soon. And on second iteration it’s just null.
It’s a bad practice to name your variables with first letter capitalized. Usually class names get first letter capital.