c# create barcode 6: Coding a Pong Game in Objective-C

Maker QR in Objective-C 6: Coding a Pong Game

CHAPTER 6: Coding a Pong Game
QR Creation In Objective-C
Using Barcode encoder for iPhone Control to generate, create QR Code ISO/IEC18004 image in iPhone applications.
www.OnBarcode.com
GTIN - 12 Creation In Objective-C
Using Barcode generator for iPhone Control to generate, create UPCA image in iPhone applications.
www.OnBarcode.com
Pong Game Architecture
Quick Response Code Generation In Objective-C
Using Barcode creation for iPhone Control to generate, create QR Code JIS X 0510 image in iPhone applications.
www.OnBarcode.com
Generate UPC - 13 In Objective-C
Using Barcode printer for iPhone Control to generate, create EAN13 image in iPhone applications.
www.OnBarcode.com
You ve probably guessed by now that the Pong game architecture is fairly simple, and that would be correct. Your Pong game can be divided into three main parts: the application delegate, the game s view controller, and the accessory controller. Take a look at Figure 6 3 to see the functional relationship.
Generate Barcode In Objective-C
Using Barcode generator for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
EAN 128 Generator In Objective-C
Using Barcode generator for iPhone Control to generate, create GS1 128 image in iPhone applications.
www.OnBarcode.com
Figure 6 3. Pong game high-level architecture
Printing Barcode In Objective-C
Using Barcode drawer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Encode UPC - E0 In Objective-C
Using Barcode drawer for iPhone Control to generate, create Universal Product Code version E image in iPhone applications.
www.OnBarcode.com
The application delegate handles all the details of the main application. For Pong, this means three things: (1) setting up any start conditions once the app has finished loading, (2) loading the initial view/viewController, and (3) handling system cleanup when the app terminates. So let s begin coding. Launch Xcode and go to File New Project. Under iPhone OS click Application and select View-based Application. You should see the window in Figure 6 4.
Quick Response Code Creation In Java
Using Barcode creation for BIRT Control to generate, create Denso QR Bar Code image in Eclipse BIRT applications.
www.OnBarcode.com
Generating QR Code ISO/IEC18004 In None
Using Barcode creator for Software Control to generate, create QR image in Software applications.
www.OnBarcode.com
CHAPTER 6: Coding a Pong Game
Encode Barcode In .NET Framework
Using Barcode creation for .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Drawing Code 128C In C#.NET
Using Barcode maker for .NET Control to generate, create Code 128C image in VS .NET applications.
www.OnBarcode.com
Figure 6 4. Project creation window
Encode Code 128B In .NET
Using Barcode creation for Reporting Service Control to generate, create Code128 image in Reporting Service applications.
www.OnBarcode.com
Read Barcode In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
www.OnBarcode.com
Name the project Pong and save it wherever you d like. Xcode will provide you with the project window and open the Classes, Other Sources, and Resources folders on the left. Your project window should look like that shown in Figure 6 5. While this all seems pretty straightforward, carefully check the list of files on the left side to make sure they match. Creating a different project type causes a different set of files to be produced.
Generate Quick Response Code In Java
Using Barcode drawer for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Making Barcode In None
Using Barcode printer for Software Control to generate, create Barcode image in Software applications.
www.OnBarcode.com
Figure 6 5. Initial Xcode project window for pong game
Making PDF 417 In Java
Using Barcode generation for Android Control to generate, create PDF417 image in Android applications.
www.OnBarcode.com
Drawing QR Code In C#
Using Barcode printer for .NET framework Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 6: Coding a Pong Game
QR Code JIS X 0510 Printer In Visual Basic .NET
Using Barcode creation for .NET Control to generate, create Quick Response Code image in VS .NET applications.
www.OnBarcode.com
ECC200 Creator In Java
Using Barcode maker for Java Control to generate, create Data Matrix image in Java applications.
www.OnBarcode.com
The Application Delegate
Xcode has created two of your three modules and all you did was create the project. You could add the third piece of the puzzle, your accessory controller, right now, but let s wait and get the basic game running first. Take a look at the following code for the application delegate:
#import <UIKit/UIKit.h> @class PongViewController; @interface PongAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; PongViewController *viewController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet PongViewController *viewController; @end #import "PongAppDelegate.h" #import "PongViewController.h" @implementation PongAppDelegate @synthesize window; @synthesize viewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end
The application delegate, immediately upon launch of the program, adds the view of our viewController object to the window and then makes that window visible. So far, so good; your view controller is now running the show.
The View Controller
Like all good iPhone developers, you start with the PongViewController s interface specification and then work on your nib file. Xcode gave the following interface file:
CHAPTER 6: Coding a Pong Game
#import <UIKit/UIKit.h> @interface PongViewController : UIViewController { } @end
Not much there in fact, other than defining your PongVIewController to be a subclass of UIViewController, there is nothing there. First thing to do is add the IBOutlets for your actual view. In case you don t already know about IBOutlet and IBAction, they are really just compiler directives to Xcode to provide hints as to what the properties or methods are being used for. You can see from the following Xcode definitions that IBOutlet actual equates to nothing and IBAction to void.
#ifndef IBOutlet #define IBOutlet #endif #ifndef IBAction #define IBAction void #endif
If you are ever curious about the origin of a keyword, just place your cursor over the variable and CMD-Click to be taken to where the file is defined. NOTE: Don t confuse this with Option-Click-ing on a keyword that provides a look-up feature in Xcode. You will need at least six elements on your screen: (1) the ball, (2) the player s paddle, (3) the computer s paddle, (4) the player s score, (5) the computer s score, and (6) a status label that you can use to inform the player whether he s won or lost. Therefore, add the following IBOutlets to your PongViewController.h file.
IBOutlet IBOutlet IBOutlet IBOutlet IBOutlet IBOutlet UIImageView *ball; UIImageView *playerPaddle; UIImageView *compPaddle; UILabel *playerScoreView; UILabel *compScoreView; UILabel *winOrLoseView;
Don t forget to add the property definitions as well.
@property @property @property @property @property @property (nonatomic,retain) (nonatomic,retain) (nonatomic,retain) (nonatomic,retain) (nonatomic,retain) (nonatomic,retain) IBOutlet IBOutlet IBOutlet IBOutlet IBOutlet IBOutlet UIImageView *ball; UIImageView *playerPaddle; UIImageView *compPaddle; UILabel *playerScoreView; UILabel *compScoreView; UILabel *winOrLoseView;
You use the @property keyword as a shortcut to defining properties in your application, as well as automatic synthesis of getter and setter methods, which you ll see later when you start writing the implementation code. In case you don t know, the keywords
Copyright © OnBarcode.com . All rights reserved.