I'm new to Objective-C and currently I'm writing a Guess the Number single view application for Iphone. The "New Game" button currently runs this code.
- (IBAction)newGame:(id)sender {
NSString *guessANumber = @"Guess a number between 1 and 25!";
[output setText:guessANumber];
}
and the random method currently looks like this
-(int)Random {
int num;
num=(arc4random() % ((unsigned)25 + 1));
while (num == 0) {
if (num == 0)
{
num=(arc4random() % ((unsigned)25 + 1));
}
}
return num;
}
Currently the method for when the player submits his/her guess is
- (IBAction)submitGuess:(id)sender {
int num = [self num];
for (int x = 1; x<=3;x++)
{
if([textField.text intValue] > num)
output.text=@"Too high.";
else if([textField.text intValue] < num)
output.text=@"Too low.";
else if ([textField.text intValue] == num)
output.text=@"You got it!";
else
output.text= @"You lose. The number was %i.", num;
}
The turn system isn't implemented currently.
I'm new to Objective-C and I'm not sure how to get the random number in to the action that happens when the submit button is pressed.
Sorry for the newbie question.
edit: Thanks for the help, it is working now.