More tweaks, including a "reversed" property for Grids to show the second player's perspective without turning the pieces upside-down.
5 // Created by Jens Alfke on 3/7/08.
6 // Copyright __MyCompanyName__ 2008. All rights reserved.
9 #import "iPhoneAppDelegate.h"
10 #import "BoardUIView.h"
12 #import "QuartzUtils.h"
16 // Temporary HACK to fix logging problem in beta 6 iPhone OS
17 extern void _NSSetLogCStringFunction(void (*)(const char *string, unsigned length, BOOL withSyslogBanner));
18 static void PrintNSLogMessage(const char *string, unsigned length, BOOL withSyslogBanner)
22 static void HackNSLog(void) __attribute__((constructor));
23 static void HackNSLog(void)
25 _NSSetLogCStringFunction(PrintNSLogMessage);
29 @implementation GGB_iPhoneAppDelegate
32 @synthesize window=_window;
33 @synthesize contentView=_contentView;
34 @synthesize headline=_headline;
37 - (void)applicationDidFinishLaunching:(UIApplication *)application
40 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
41 _window.layer.backgroundColor = GetCGPatternNamed(@"Background.png");
43 // Set up content view
44 CGRect rHeadline,rContent;
45 CGRectDivide([[UIScreen mainScreen] applicationFrame],
46 &rHeadline, &rContent, 35, CGRectMinYEdge);
48 self.contentView = [[[BoardUIView alloc] initWithFrame: rContent] autorelease];
49 [_window addSubview: _contentView];
51 self.headline = [[[UILabel alloc] initWithFrame: rHeadline] autorelease];
52 _headline.backgroundColor = nil;
53 _headline.opaque = NO;
54 _headline.textAlignment = UITextAlignmentCenter;
55 _headline.font = [UIFont boldSystemFontOfSize: 20];
56 _headline.minimumFontSize = 14;
57 _headline.adjustsFontSizeToFitWidth = YES;
58 [_window addSubview: _headline];
61 [self startGameNamed: @"CheckersGame"];
64 [_window makeKeyAndVisible];
70 [_contentView release];
77 - (void) startGameNamed: (NSString*)gameClassName
79 Game *game = _contentView.game;
80 [game removeObserver: self forKeyPath: @"currentPlayer"];
81 [game removeObserver: self forKeyPath: @"winner"];
83 if( gameClassName == nil )
84 gameClassName = [[game class] description];
86 [_contentView startGameNamed: gameClassName];
88 game = _contentView.game;
89 [game addObserver: self
90 forKeyPath: @"currentPlayer"
91 options: NSKeyValueObservingOptionInitial
93 [game addObserver: self
100 - (void)observeValueForKeyPath:(NSString *)keyPath
102 change:(NSDictionary *)change
103 context:(void *)context
105 Game *game = _contentView.game;
106 if( object == game ) {
107 Player *p = game.winner;
110 PlaySound(@"Sosumi");
113 p = game.currentPlayer;
114 msg = @"Your turn, %@";
116 _headline.text = [NSString stringWithFormat: msg, p.name];
120 alert = [[UIAlertView alloc] initWithTitle: msg
121 message: @"Congratulations!"
123 cancelButtonTitle:nil
124 otherButtonTitles:nil];
132 - (void)alertView:(UIAlertView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex;
135 [self startGameNamed: nil];