Game class now tracks board state and moves, as strings, and can step through its history.
Fixed another bug in Go (you could drag your captured stones back to the board!)
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 @implementation GGB_iPhoneAppDelegate
19 @synthesize window=_window;
20 @synthesize contentView=_contentView;
21 @synthesize headline=_headline;
24 - (void)applicationDidFinishLaunching:(UIApplication *)application
26 for( NSString *family in [UIFont familyNames] )
27 NSLog(@"%@: (%@)", family, [[UIFont fontNamesForFamilyName: family] componentsJoinedByString: @", "]);
30 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
31 _window.layer.backgroundColor = GetCGPatternNamed(@"Background.png");
33 // Set up content view
34 CGRect rHeadline,rContent;
35 CGRectDivide([[UIScreen mainScreen] applicationFrame],
36 &rHeadline, &rContent, 35, CGRectMinYEdge);
38 self.contentView = [[[BoardUIView alloc] initWithFrame: rContent] autorelease];
39 [_window addSubview: _contentView];
41 self.headline = [[[UILabel alloc] initWithFrame: rHeadline] autorelease];
42 _headline.backgroundColor = nil;
43 _headline.opaque = NO;
44 _headline.textAlignment = UITextAlignmentCenter;
45 _headline.font = [UIFont boldSystemFontOfSize: 20];
46 _headline.minimumFontSize = 14;
47 _headline.adjustsFontSizeToFit = YES;
48 [_window addSubview: _headline];
51 [self startGameNamed: @"KlondikeGame"];
54 [_window makeKeyAndVisible];
60 [_contentView release];
67 - (void) startGameNamed: (NSString*)gameClassName
69 Game *game = _contentView.game;
70 [game removeObserver: self forKeyPath: @"currentPlayer"];
71 [game removeObserver: self forKeyPath: @"winner"];
73 if( gameClassName == nil )
74 gameClassName = [[game class] className];
76 [_contentView startGameNamed: gameClassName];
78 game = _contentView.game;
79 [game addObserver: self
80 forKeyPath: @"currentPlayer"
81 options: NSKeyValueObservingOptionInitial
83 [game addObserver: self
90 - (void)observeValueForKeyPath:(NSString *)keyPath
92 change:(NSDictionary *)change
93 context:(void *)context
95 Game *game = _contentView.game;
96 if( object == game ) {
97 Player *p = game.winner;
100 PlaySound(@"Sosumi");
103 p = game.currentPlayer;
104 msg = @"Your turn, %@";
106 _headline.text = [NSString stringWithFormat: msg, p.name];
110 alert = [[UIAlertView alloc] initWithTitle: msg
111 message: @"Congratulations!"
114 cancelButton:nil otherButtons:nil];
122 - (void)modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex;
125 [self startGameNamed: nil];