Tweaks and fixes, including renaming Game's "board" property/ivar to "table", which is less confusing.
Released as part of Your Move 1.0a2.
     5 //  Created by Jens Alfke on 3/7/08.
 
     6 //  Copyright __MyCompanyName__ 2008. All rights reserved.
 
     9 #import "iPhoneAppDelegate.h"
 
    10 #import "BoardUIView.h"
 
    13 #import "QuartzUtils.h"
 
    18 // Temporary HACK to fix logging problem in beta 6 iPhone OS
 
    19 extern void _NSSetLogCStringFunction(void (*)(const char *string, unsigned length, BOOL withSyslogBanner));
 
    20 static void PrintNSLogMessage(const char *string, unsigned length, BOOL withSyslogBanner)
 
    24 static void HackNSLog(void) __attribute__((constructor));
 
    25 static void HackNSLog(void)
 
    27 	_NSSetLogCStringFunction(PrintNSLogMessage);
 
    32 @implementation GGB_iPhoneAppDelegate
 
    35 @synthesize window=_window;
 
    36 @synthesize contentView=_contentView;
 
    37 @synthesize headline=_headline;
 
    40 - (void)applicationDidFinishLaunching:(UIApplication *)application 
 
    43     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 
    44     _window.layer.backgroundColor = GetCGPatternNamed(@"Background.png");
 
    46     // Set up content view
 
    47     CGRect rHeadline,rContent;
 
    48     CGRectDivide([[UIScreen mainScreen] applicationFrame],
 
    49                  &rHeadline, &rContent, 35, CGRectMinYEdge);
 
    51     self.contentView = [[[BoardUIView alloc] initWithFrame: rContent] autorelease];
 
    52     [_window addSubview: _contentView];
 
    54     self.headline = [[[UILabel alloc] initWithFrame: rHeadline] autorelease];
 
    55     _headline.backgroundColor = nil;
 
    56     _headline.opaque = NO;
 
    57     _headline.textAlignment = UITextAlignmentCenter;
 
    58     _headline.font = [UIFont boldSystemFontOfSize: 20];
 
    59     _headline.minimumFontSize = 14;
 
    60     _headline.adjustsFontSizeToFitWidth = YES;
 
    61     [_window addSubview: _headline];
 
    64     [self startGameNamed: @"CheckersGame"];
 
    67     [_window makeKeyAndVisible];
 
    73     [_contentView release];
 
    80 - (void) startGameNamed: (NSString*)gameClassName
 
    82     Game *game = _contentView.game;
 
    83     [game removeObserver: self  forKeyPath: @"currentPlayer"];
 
    84     [game removeObserver: self forKeyPath: @"winner"];
 
    86     if( gameClassName == nil )
 
    87         gameClassName = [[game class] description];
 
    89     [_contentView startGameNamed: gameClassName];
 
    91     game = _contentView.game;
 
    92     [game addObserver: self 
 
    93            forKeyPath: @"currentPlayer"
 
    94               options: NSKeyValueObservingOptionInitial
 
    96     [game addObserver: self
 
   103 - (void)observeValueForKeyPath:(NSString *)keyPath 
 
   105                         change:(NSDictionary *)change
 
   106                        context:(void *)context
 
   108     Game *game = _contentView.game;
 
   109     if( object == game ) {
 
   110         Player *p = game.winner;
 
   113             PlaySound(@"Sosumi");
 
   116             p = game.currentPlayer;
 
   117             msg = @"Your turn, %@";
 
   119         _headline.text = [NSString stringWithFormat: msg, p.name];
 
   123             alert = [[UIAlertView alloc] initWithTitle: msg
 
   124                                                message: @"Congratulations!"
 
   126                                      cancelButtonTitle:nil 
 
   127                                      otherButtonTitles:nil];
 
   135 - (void)alertView:(UIAlertView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex;
 
   138     [self startGameNamed: nil];