iPhone Game Development - Chris Craft [32]
Note
You can include information about yourself or your company and advertise other games and products you may have on the info screen.
FIGURE 3.7
Click the small “i” info icon to bring up the info screen.
You can use the info screen to do the following:
Show some information and a description for the game.
Show the player's current high score (in our case, the highest level that has been completed).
Provide a button that, when clicked, allows players to brag to their friends about their high score.
Tell people about this book and show them how to get it.
Tell people about other games in this book.
FIGURE 3.8
After the info icon is clicked, the info screen is displayed.
Hopefully you have already downloaded the code from http://appsamuckcom and are ready to follow through. If you have been using Xcode and developing for the iPhone, you already know how to create new projects. However, if you have not, we'll take a moment at the beginning of the application to walk you through the steps of creating a project and a new class for some of the shorter, less involved items. As we progress to larger items, we'll assume you are following along and just cover the relevant material and methods.
Here are the steps you need to follow to create a utility app the same way we started AmuckSlider. Launch Xcode and choose File⇒New Project. From the New Project dialog box, click Application under iPhone OS on the left and then click Utility Application (see Figure 3.9).
FIGURE 3.9
Creating a new utility application
You will be prompted to name your project. We named ours AmuckSlider, but choose whatever name you like. When the project is created, several files are created for you. To get started, let's go ahead and complete our Info View.
Putting info in the Info View
You will find the source you will want to modify for the Info View in the files FlipsideViewController.h and FlipsideViewController.m. Most of the information in this screen is static, but two elements are not. First, we need the high score to change to reflect the player's current best score. Second, we need a button that sends a message to the controller whenever it is clicked so we can send an e-mail to a friend bragging about our score. Start by opening up FlipsideViewController.h. You will need an IBOutlet to reference the highScoreLabel, and you will need an IBAction to respond to your button click. When you open FlipsideViewController.h, you see the following code:
#import @interface FlipsideView : UIView { } @end Add a label and action to the code so that it looks like this (additions are in bold): #import @interface FlipsideView : UIView { IBOutlet UILabel *highScoreLabel; } @property (nonatomic, retain) UILabel *highScoreLabel; IBAction onEmailButtonClick; @end Now we need to make some completer changes to FlipsideViewController.m. When you open this file it will look like this: #import “FlipsideViewController.h” @implementation FlipsideViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { [super dealloc]; } @end Again, add code for a label and action so that it looks like Listing 3.1. Cross-Reference To download all of the code listings in this chapter, go to www.wileydevreference.com and click the Downloads link. Listing 3.1 The Complete Implementation for the FlipsideViewController Class #import “FlipsideViewController.h” @synthesize highScoreLabel; @implementation FlipsideViewController - (void)viewDidLoad { [super viewDidLoad]; NSString* highScore = [Helper getUserValueForKey: @”highscore” withDefault:@”0”]; highScoreLabel.text