Game Development Reference
In-Depth Information
-(void)checkMatches;
-(void)updateCoinViews;
-(void)spinCoinAt:(Coord)coord;
-(void)stopCoinAt:(Coord)coord;
-(void)doEndGame;
@end
This header file for the class CoinsController describes the class as well as the delegate protocol
CoinsControllerDelegate , discussed in Chapter 3. The field CoinsGame is used to store the state of
the game. This object can be archived to save the game state or it can be passed to an instance
of CoinsController to resume a game. The UIView coinsView is the white play area. The BOOL
isFirstCoinSelected is used to keep track of whether the user has already selected a coin. The two
Coord structs record which coins are selected. We will take a look at the Coord struct shortly. The
BOOL acceptingInput is used to block user input when animations are happening.
The two UIImageView fields, coinViewA and coinViewB , along with the NSMutableArray
variables matchingRows and matchingCols are used during animations to keep track of what is
being animated. The last field is the delegate for this class and must implement the protocol
CoinsControllerDelegate .
Initialization and Setup
The life of a CoinController object starts when the task viewDidLoad is called. This is called
automatically because we have an instance of CoinController in our XIB files. Listing 4-8 shows
this task.
Listing 4-8. CoinController.m (viewDidLoad)
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor clearColor]];
CGRect viewFrame = [self.view frame];
//border is 3.125%
float border = viewFrame.size.width*.03125;
float coinsViewWidth = viewFrame.size.width-border*2;
CGRect coinsFrame = CGRectMake(border, border, coinsViewWidth, coinsViewWidth);
coinsView = [[UIView alloc] initWithFrame: coinsFrame];
[coinsView setBackgroundColor:[UIColor whiteColor]];
[coinsView setClipsToBounds:YES];
[self.view addSubview:coinsView];
 
Search WWH ::




Custom Search