Game Development Reference
In-Depth Information
-(void)userSelected:(id)sender{
int result = random()%3;
UIButton* selectedButton = (UIButton*)sender;
NSString* selection = [[selectedButton titleLabel] text];
NSString* resultText;
if (result == 0){//lost
NSString* computerSelection = [self getLostTo:selection];
resultText = [@"Lost, iOS selected " stringByAppendingString: computerSelection];
} else if (result == 1) {//tie
resultText = [@"Tie, iOS selected " stringByAppendingString: selection];
} else {//win
NSString* computerSelection = [self getWonTo:selection];
resultText = [@"Won, iOS selected " stringByAppendingString: computerSelection];
}
[resultLabel setText:resultText];
[buttonView removeFromSuperview];
[
self.view
addSubview:resultView];
}
-(void)continueGame:(id)sender{
[resultView removeFromSuperview];
[
self.view
addSubview:buttonView];
}
The bold sections of Listing 2-4 indicate where we have made the required changes. We will use this
UIViewController
version of Rock, Paper, Scissors toward the end of this chapter, after we have set
up the rest of our UI.
Customizing Behavior Based on Device Type
As mentioned, the project we are using is an example of a universal application, configured to run on
both the iPhone and the iPad. Because it is likely that an application will want to do different things
when running on different devices, we will create subclasses of our
ViewController
specific to each
device type.
To create these subclasses, from the file menu, select New file. You will be presented with a dialog
like the one shown in Figure
2-9
.