# HG changeset patch # User Jens Alfke # Date 1216094415 25200 # Node ID 28392c9a969fef860c11153a50dfb03236cb75de # Parent 73f8c889f053baa2b545f205f428f27c9c7b2e9b Tweaks and fixes, including renaming Game's "board" property/ivar to "table", which is less confusing. Released as part of Your Move 1.0a2. diff -r 73f8c889f053 -r 28392c9a969f GeekGameBoard-iPhone.xcodeproj/project.pbxproj --- a/GeekGameBoard-iPhone.xcodeproj/project.pbxproj Wed Jul 09 17:07:45 2008 -0700 +++ b/GeekGameBoard-iPhone.xcodeproj/project.pbxproj Mon Jul 14 21:00:15 2008 -0700 @@ -11,6 +11,8 @@ 1D60589B0D05DD56006BFB54 /* main-iPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main-iPhone.m */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; + 27124B380E2852A700B61BE3 /* Player.m in Sources */ = {isa = PBXBuildFile; fileRef = 27124B350E2852A700B61BE3 /* Player.m */; }; + 27124B390E2852A700B61BE3 /* Turn.m in Sources */ = {isa = PBXBuildFile; fileRef = 27124B370E2852A700B61BE3 /* Turn.m */; }; 2740502B0DEF36DF0006A9EE /* Pop.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 274050290DEF36DF0006A9EE /* Pop.aiff */; }; 2740502C0DEF36DF0006A9EE /* Tink.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 2740502A0DEF36DF0006A9EE /* Tink.aiff */; }; 279F4B590D85C51700B32DBF /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 279F4B580D85C51700B32DBF /* AudioToolbox.framework */; }; @@ -59,6 +61,11 @@ 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 1D6058910D05DD3D006BFB54 /* GeekGameBoard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GeekGameBoard.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 27124B330E2852A700B61BE3 /* Game+Protected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Game+Protected.h"; sourceTree = ""; }; + 27124B340E2852A700B61BE3 /* Player.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Player.h; sourceTree = ""; }; + 27124B350E2852A700B61BE3 /* Player.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Player.m; sourceTree = ""; }; + 27124B360E2852A700B61BE3 /* Turn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Turn.h; sourceTree = ""; }; + 27124B370E2852A700B61BE3 /* Turn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Turn.m; sourceTree = ""; }; 274050290DEF36DF0006A9EE /* Pop.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; name = Pop.aiff; path = /System/Library/Sounds/Pop.aiff; sourceTree = ""; }; 2740502A0DEF36DF0006A9EE /* Tink.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; name = Tink.aiff; path = /System/Library/Sounds/Tink.aiff; sourceTree = ""; }; 279F4B580D85C51700B32DBF /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; @@ -230,6 +237,11 @@ children = ( 27C99AFE0D820868005AFD4F /* Game.h */, 27C99AFF0D820868005AFD4F /* Game.m */, + 27124B330E2852A700B61BE3 /* Game+Protected.h */, + 27124B340E2852A700B61BE3 /* Player.h */, + 27124B350E2852A700B61BE3 /* Player.m */, + 27124B360E2852A700B61BE3 /* Turn.h */, + 27124B370E2852A700B61BE3 /* Turn.m */, 27C99B000D820868005AFD4F /* TicTacToeGame.h */, 27C99B010D820868005AFD4F /* TicTacToeGame.m */, 27C99B020D820868005AFD4F /* CheckersGame.h */, @@ -402,6 +414,8 @@ 27C99B510D82106E005AFD4F /* GGBLayer.m in Sources */, 279F4B620D85C63000B32DBF /* GGBTextLayer.m in Sources */, 279F4B6A0D85CBFC00B32DBF /* iPhoneAppDelegate.m in Sources */, + 27124B380E2852A700B61BE3 /* Player.m in Sources */, + 27124B390E2852A700B61BE3 /* Turn.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -444,8 +458,8 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CODE_SIGN_IDENTITY = "Laurence ANDERSEN"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Laurence ANDERSEN"; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Jens Alfke"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -461,11 +475,12 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CODE_SIGN_IDENTITY = "Laurence ANDERSEN"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Laurence ANDERSEN"; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Jens Alfke"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; SDKROOT = iphoneos2.0; WARNING_CFLAGS = "-Wall"; diff -r 73f8c889f053 -r 28392c9a969f Source/Bit.h --- a/Source/Bit.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Bit.h Mon Jul 14 21:00:15 2008 -0700 @@ -43,8 +43,10 @@ { @private int _restingZ; // Original z position, saved while pickedUp +#if !TARGET_OS_IPHONE float _restingShadowOpacity, _restingShadowRadius; CGSize _restingShadowOffset; +#endif BOOL _pickedUp; Player *_owner; // Player that owns this Bit NSInteger _tag; diff -r 73f8c889f053 -r 28392c9a969f Source/Bit.m --- a/Source/Bit.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Bit.m Mon Jul 14 21:00:15 2008 -0700 @@ -111,13 +111,17 @@ scale = kPickedUpScale; z = kPickedUpZ; _restingZ = self.zPosition; +#if !TARGET_OS_IPHONE _restingShadowOpacity = self.shadowOpacity; _restingShadowOffset = self.shadowOffset; _restingShadowRadius = self.shadowRadius; +#endif } else { +#if !TARGET_OS_IPHONE shadow = _restingShadowOpacity; offset = _restingShadowOffset; radius = _restingShadowRadius; +#endif opacity = 1; scale = 1.0/kPickedUpScale; z = _restingZ; diff -r 73f8c889f053 -r 28392c9a969f Source/BitHolder.m --- a/Source/BitHolder.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/BitHolder.m Mon Jul 14 21:00:15 2008 -0700 @@ -54,8 +54,6 @@ } setObj(&_bit,bit); ChangeSuperlayer(bit,self,-1); - if( bit ) - NSLog(@"%@: xform = \n%@",bit,StringFromTransform3D(bit.aggregateTransform));//TEMP } } diff -r 73f8c889f053 -r 28392c9a969f Source/BoardView.h --- a/Source/BoardView.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/BoardView.h Mon Jul 14 21:00:15 2008 -0700 @@ -30,7 +30,7 @@ { @private Game *_game; // Current Game - GGBLayer *_gameboard; // Game's main layer + GGBLayer *_table; // Game's root layer NSSize _oldSize; // Used during mouse-down tracking: @@ -50,7 +50,7 @@ } @property (retain) Game *game; -@property (readonly) CALayer *gameboard; +@property (readonly) CALayer *table; - (void) startGameNamed: (NSString*)gameClassName; diff -r 73f8c889f053 -r 28392c9a969f Source/BoardView.m --- a/Source/BoardView.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/BoardView.m Mon Jul 14 21:00:15 2008 -0700 @@ -38,7 +38,7 @@ @implementation BoardView -@synthesize gameboard=_gameboard; +@synthesize table=_table; - (void) dealloc @@ -50,24 +50,24 @@ - (void) _removeGameBoard { - if( _gameboard ) { - RemoveImmediately(_gameboard); - _gameboard = nil; + if( _table ) { + RemoveImmediately(_table); + _table = nil; } } - (void) createGameBoard { [self _removeGameBoard]; - _gameboard = [[CALayer alloc] init]; - _gameboard.frame = [self gameBoardFrame]; - _gameboard.autoresizingMask = kCALayerMinXMargin | kCALayerMaxXMargin | kCALayerMinYMargin | kCALayerMaxYMargin; + _table = [[CALayer alloc] init]; + _table.frame = [self gameBoardFrame]; + _table.autoresizingMask = kCALayerMinXMargin | kCALayerMaxXMargin | kCALayerMinYMargin | kCALayerMaxYMargin; // Tell the game to set up the board: - _game.board = _gameboard; + _game.table = _table; - [self.layer addSublayer: _gameboard]; - [_gameboard release]; + [self.layer addSublayer: _table]; + [_table release]; } @@ -79,7 +79,7 @@ - (void) setGame: (Game*)game { if( game!=_game ) { - _game.board = nil; + _game.table = nil; setObj(&_game,game); [self createGameBoard]; } @@ -133,9 +133,9 @@ { [super setFrameSize: newSize]; if( _oldSize.width > 0.0f ) { - CGAffineTransform xform = _gameboard.affineTransform; + CGAffineTransform xform = _table.affineTransform; xform.a = xform.d = MIN(newSize.width,newSize.height)/MIN(_oldSize.width,_oldSize.height); - _gameboard.affineTransform = xform; + _table.affineTransform = xform; } else [self createGameBoard]; } @@ -189,7 +189,7 @@ offset: (CGPoint*)outOffset { CGPoint where = [self _convertPointFromWindowToLayer: locationInWindow ]; - CALayer *layer = [_gameboard hitTest: where]; + CALayer *layer = [_table hitTest: where]; while( layer ) { if( match(layer) ) { CGPoint bitPos = [self.layer convertPoint: layer.position diff -r 73f8c889f053 -r 28392c9a969f Source/CheckersGame.h --- a/Source/CheckersGame.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/CheckersGame.h Mon Jul 14 21:00:15 2008 -0700 @@ -28,7 +28,7 @@ See: http://en.wikipedia.org/wiki/Draughts */ @interface CheckersGame : Game { - Grid *_grid; + Grid *_board; } @end diff -r 73f8c889f053 -r 28392c9a969f Source/CheckersGame.m --- a/Source/CheckersGame.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/CheckersGame.m Mon Jul 14 21:00:15 2008 -0700 @@ -71,7 +71,7 @@ - (Piece*) pieceForPlayer: (int)playerNum { Piece *p = [[Piece alloc] init]; - p.bounds = CGRectMake(0,0,floor(_grid.spacing.width),floor(_grid.spacing.height)); + p.bounds = CGRectMake(0,0,floor(_board.spacing.width),floor(_board.spacing.height)); p.style = (playerNum ?kPieceStyle2 :kPieceStyle1); p.owner = [self.players objectAtIndex: playerNum]; p.name = playerNum ?@"2" :@"1"; @@ -87,29 +87,29 @@ - (void) setUpBoard { - RectGrid *grid = [[RectGrid alloc] initWithRows: 8 columns: 8 frame: _board.bounds]; - _grid = grid; - [_board addSublayer: _grid]; - CGPoint pos = _grid.position; - pos.x = floor((_board.bounds.size.width-grid.frame.size.width)/2); - grid.position = pos; - grid.allowsMoves = YES; - grid.allowsCaptures = NO; - grid.cellColor = CreateGray(0.0, 0.25); - grid.altCellColor = CreateGray(1.0, 0.25); - grid.lineColor = nil; - grid.reversed = ! [[self.players objectAtIndex: 0] isLocal]; + RectGrid *board = [[RectGrid alloc] initWithRows: 8 columns: 8 frame: _table.bounds]; + _board = board; + [_table addSublayer: _board]; + CGPoint pos = _board.position; + pos.x = floor((_table.bounds.size.width-board.frame.size.width)/2); + board.position = pos; + board.allowsMoves = YES; + board.allowsCaptures = NO; + board.cellColor = CreateGray(0.0, 0.5); + board.altCellColor = CreateGray(1.0, 0.25); + board.lineColor = nil; + board.reversed = ! [[self.players objectAtIndex: 0] isLocal]; for( int i=0; i<32; i++ ) { int row = i/4; - [_grid addCellAtRow: row column: 2*(i%4) + (row&1)]; + [_board addCellAtRow: row column: 2*(i%4) + (row&1)]; } - [_grid release]; // its superlayer still retains it + [_board release]; // its superlayer still retains it } - (NSString*) initialStateString {return @"111111111111--------222222222222";} -- (NSString*) stateString {return _grid.stateString;} -- (void) setStateString: (NSString*)state {_grid.stateString = state;} +- (NSString*) stateString {return _board.stateString;} +- (void) setStateString: (NSString*)state {_board.stateString = state;} - (Piece*) makePieceNamed: (NSString*)name { @@ -178,7 +178,7 @@ - (Player*) checkForWinner { - NSCountedSet *remaining = _grid.countPiecesByPlayer; + NSCountedSet *remaining = _board.countPiecesByPlayer; if( remaining.count==1 ) return [remaining anyObject]; else @@ -192,7 +192,7 @@ for( NSString *ident in [move componentsSeparatedByString: @"-"] ) { while( [ident hasSuffix: @"!"] || [ident hasSuffix: @"*"] ) ident = [ident substringToIndex: ident.length-1]; - GridCell *dst = [_grid cellWithName: ident]; + GridCell *dst = [_board cellWithName: ident]; if( dst == nil ) return NO; if( src && ! [self animateMoveFrom: src to: dst] ) diff -r 73f8c889f053 -r 28392c9a969f Source/DiscPiece.m --- a/Source/DiscPiece.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/DiscPiece.m Mon Jul 14 21:00:15 2008 -0700 @@ -41,7 +41,9 @@ [_imageLayer release]; // superlayer is holding onto it } _imageLayer.frame = CGRectInset(self.bounds, outerDiameter-diameter, outerDiameter-diameter); +#if !TARGET_OS_IPHONE _imageLayer.cornerRadius = diameter/2; +#endif _imageLayer.contents = (id) image; self.cornerRadius = outerDiameter/2; self.borderWidth = 3; diff -r 73f8c889f053 -r 28392c9a969f Source/GGBLayer.h --- a/Source/GGBLayer.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/GGBLayer.h Mon Jul 14 21:00:15 2008 -0700 @@ -43,8 +43,6 @@ and update every other layer that shares the same style dictionary. */ - (void) setValue: (id)value ofStyleProperty: (NSString*)prop; -- (CATransform3D) aggregateTransform; - @end @@ -59,5 +57,3 @@ void EndDisableAnimations(void); CGColorRef GetEffectiveBackground( CALayer *layer ); - -NSString* StringFromTransform3D( CATransform3D xform ); diff -r 73f8c889f053 -r 28392c9a969f Source/GGBLayer.m --- a/Source/GGBLayer.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/GGBLayer.m Mon Jul 14 21:00:15 2008 -0700 @@ -124,6 +124,7 @@ } +#if 0 - (CATransform3D) aggregateTransform { CATransform3D xform = CATransform3DIdentity; @@ -146,7 +147,7 @@ } return str; } - +#endif #if TARGET_OS_IPHONE diff -r 73f8c889f053 -r 28392c9a969f Source/GGBUtils.m --- a/Source/GGBUtils.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/GGBUtils.m Mon Jul 14 21:00:15 2008 -0700 @@ -19,10 +19,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "GGBUtils.h" - -#if TARGET_OS_IPHONE #import -#endif #ifndef _MYUTILITIES_COLLECTIONUTILS_ @@ -54,7 +51,6 @@ } -#if TARGET_OS_IPHONE static SystemSoundID GetSound( NSString *name ) { static NSMutableDictionary *sSoundIDs; @@ -64,19 +60,24 @@ NSString *type = name.pathExtension; if( ! type.length ) type = @"aiff"; - NSString *path = [[NSBundle mainBundle] pathForResource: name.stringByDeletingPathExtension + name = name.stringByDeletingPathExtension; + + NSString *path = [[NSBundle mainBundle] pathForResource: name ofType: type]; +#if ! TARGET_OS_IPHONE + if( ! path ) + path = [@"/System/Library/Sounds" stringByAppendingPathComponent: [name stringByAppendingPathExtension: type]]; +#endif NSURL *url; if( path ) url = [NSURL fileURLWithPath: path]; else { - NSLog(@"Couldn't find sound %@",name); + NSLog(@"WARNING: Couldn't find sound %@",name); return 0; } - //url = [NSURL fileURLWithPath: [@"/Library/Sounds/" stringByAppendingPathComponent: name]]; SystemSoundID soundID; if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) { - NSLog(@"Couldn't load sound %@",url); + NSLog(@"WARNING: Couldn't load sound %@",url); return 0; } @@ -87,29 +88,17 @@ } return [soundIDObj unsignedIntValue]; } -#endif void PreloadSound( NSString* name ) { -#if TARGET_OS_IPHONE - GetSound(name); -#else - NSSound *sound = [[NSSound soundNamed: @"Pop"] copy]; - sound.volume = 0; - [sound play]; - [sound release]; -#endif + (void) GetSound(name); } void PlaySound( NSString* name ) { -#if TARGET_OS_IPHONE AudioServicesPlaySystemSound( GetSound(name) ); -#else - [[NSSound soundNamed: name] play]; -#endif } void Beep() diff -r 73f8c889f053 -r 28392c9a969f Source/Game.h --- a/Source/Game.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Game.h Mon Jul 14 21:00:15 2008 -0700 @@ -29,7 +29,7 @@ /** Abstract superclass. Keeps track of the rules and turns of a game. */ @interface Game : NSObject { - GGBLayer *_board; + GGBLayer *_table; NSArray *_players; Player *_winner; NSMutableArray *_turns; @@ -55,8 +55,8 @@ /** Designated initializer: override this if your subclass needs additional initialization. */ - (id) init; -/** Convenience initializer that calls -init, -setBoard:, and -nextTurn. */ -- (id) initNewGameWithBoard: (GGBLayer*)board; +/** Convenience initializer that calls -init, -setTable:, and -nextTurn. */ +- (id) initNewGameWithTable: (GGBLayer*)table; /** NSCoding initializer. Calls -init, but then restores saved payers, states, moves. */ - (id) initWithCoder: (NSCoder*)decoder; @@ -69,7 +69,7 @@ @property (readonly) Player *currentPlayer, *winner, *remotePlayer; @property (readonly, getter=isLocal) BOOL local; // Are all players local? -@property (retain) GGBLayer *board; // The root layer for the game. +@property (retain) GGBLayer *table; // The root layer for the game. @property (readonly) NSArray *turns; @property (readonly) Turn *currentTurn, *latestTurn; diff -r 73f8c889f053 -r 28392c9a969f Source/Game.m --- a/Source/Game.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Game.m Mon Jul 14 21:00:15 2008 -0700 @@ -68,11 +68,11 @@ } -- (id) initNewGameWithBoard: (GGBLayer*)board +- (id) initNewGameWithTable: (GGBLayer*)board { self = [self init]; if( self ) { - self.board = board; + self.table = board; NSAssert1(_players && _turns, @"%@ failed to set numberOfPlayers",self); } return self; @@ -81,7 +81,7 @@ - (void) dealloc { - [_board release]; + [_table release]; [_players release]; [_turns release]; [_extraValues release]; @@ -117,19 +117,19 @@ NSAssert1(NO,@"%@ forgot to implement -setUpBoard",[self class]); } -- (GGBLayer*) board +- (GGBLayer*) table { - return _board; + return _table; } -- (void) setBoard: (GGBLayer*)board +- (void) setTable: (GGBLayer*)board { - setObj(&_board,board); + setObj(&_table,board); if( board ) { // Store a pointer to myself as the value of the "Game" property // of my root layer. (CALayers can have arbitrary KV properties stored into them.) // This is used by the -[CALayer game] category method defined below, to find the Game. - [_board setValue: self forKey: @"Game"]; + [_table setValue: self forKey: @"Game"]; BeginDisableAnimations(); @@ -263,7 +263,7 @@ if( curTurn.status > kTurnEmpty && curTurn.status < kTurnFinished ) { if( _winner ) self.winner = nil; - if( _board ) + if( _table ) self.stateString = curTurn.previousTurn.boardState; curTurn.status = kTurnEmpty; } @@ -308,7 +308,7 @@ NSParameterAssert(turnNo<=self.maxTurnNo); unsigned oldTurnNo = _currentTurnNo; if( turnNo != oldTurnNo ) { - if( _board ) { + if( _table ) { Turn *turn = [_turns objectAtIndex: turnNo]; NSString *state; if( turn.status == kTurnEmpty ) @@ -325,7 +325,6 @@ @try{ if( ! [self applyMoveString: move] ) { _currentTurnNo = oldTurnNo; - NSBeep(); NSLog(@"WARNING: %@ failed to apply stored move '%@'!", self,move); return; } @@ -341,7 +340,6 @@ } if( ! [self.stateString isEqual: state] ) { _currentTurnNo = oldTurnNo; - NSBeep(); NSLog(@"WARNING: %@ failed to apply stored state '%@'!", self,state); return; } @@ -360,7 +358,7 @@ || ! [self canBit: bit moveFrom: src to: dst] ) return NO; - ChangeSuperlayer(bit, _board.superlayer, -1); + ChangeSuperlayer(bit, _table.superlayer, -1); bit.pickedUp = YES; dst.highlighted = YES; [bit performSelector: @selector(setPickedUp:) withObject:nil afterDelay: 0.15]; @@ -397,8 +395,8 @@ if( oldHolder != dst ) return [self animateMoveFrom: oldHolder to: dst]; } else - bit.position = [dst convertPoint: GetCGRectCenter(dst.bounds) toLayer: _board.superlayer]; - ChangeSuperlayer(bit, _board.superlayer, -1); + bit.position = [dst convertPoint: GetCGRectCenter(dst.bounds) toLayer: _table.superlayer]; + ChangeSuperlayer(bit, _table.superlayer, -1); bit.pickedUp = YES; dst.highlighted = YES; diff -r 73f8c889f053 -r 28392c9a969f Source/GoGame.h --- a/Source/GoGame.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/GoGame.h Mon Jul 14 21:00:15 2008 -0700 @@ -28,7 +28,7 @@ See: http://en.wikipedia.org/wiki/Go_%28board_game%29 */ @interface GoGame : Game { - RectGrid *_grid; + RectGrid *_board; Stack *_captured[2]; } diff -r 73f8c889f053 -r 28392c9a969f Source/GoGame.m --- a/Source/GoGame.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/GoGame.m Mon Jul 14 21:00:15 2008 -0700 @@ -48,31 +48,31 @@ - (void) setUpBoard { int dimensions = [[self class] dimensions]; - CGSize size = _board.bounds.size; + CGSize size = _table.bounds.size; CGFloat boardSide = MIN(size.width,size.height); - RectGrid *grid = [[RectGrid alloc] initWithRows: dimensions columns: dimensions + RectGrid *board = [[RectGrid alloc] initWithRows: dimensions columns: dimensions frame: CGRectMake(floor((size.width-boardSide)/2), floor((size.height-boardSide)/2), boardSide,boardSide)]; - _grid = grid; + _board = board; /* grid.backgroundColor = GetCGPatternNamed(@"Wood.jpg"); grid.borderColor = kTranslucentLightGrayColor; grid.borderWidth = 2; */ - grid.lineColor = kTranslucentGrayColor; - grid.cellClass = [GoSquare class]; - [grid addAllCells]; - ((GoSquare*)[grid cellAtRow: 2 column: 2]).dotted = YES; - ((GoSquare*)[grid cellAtRow: 6 column: 6]).dotted = YES; - ((GoSquare*)[grid cellAtRow: 2 column: 6]).dotted = YES; - ((GoSquare*)[grid cellAtRow: 6 column: 2]).dotted = YES; - grid.usesDiagonals = grid.allowsMoves = grid.allowsCaptures = NO; - [_board addSublayer: grid]; - [grid release]; + board.lineColor = kTranslucentGrayColor; + board.cellClass = [GoSquare class]; + [board addAllCells]; + ((GoSquare*)[board cellAtRow: 2 column: 2]).dotted = YES; + ((GoSquare*)[board cellAtRow: 6 column: 6]).dotted = YES; + ((GoSquare*)[board cellAtRow: 2 column: 6]).dotted = YES; + ((GoSquare*)[board cellAtRow: 6 column: 2]).dotted = YES; + board.usesDiagonals = board.allowsMoves = board.allowsCaptures = NO; + [_table addSublayer: board]; + [board release]; - CGRect gridFrame = grid.frame; - CGFloat pieceSize = (int)grid.spacing.width & ~1; // make sure it's even + CGRect gridFrame = board.frame; + CGFloat pieceSize = (int)board.spacing.width & ~1; // make sure it's even CGFloat captureHeight = gridFrame.size.height-4*pieceSize; _captured[0] = [[Stack alloc] initWithStartPos: CGPointMake(2*pieceSize,0) spacing: CGSizeMake(0,pieceSize) @@ -82,7 +82,7 @@ CGRectGetMinY(gridFrame)+3*pieceSize, 2*pieceSize, captureHeight); _captured[0].zPosition = kPieceZ+1; - [_board addSublayer: _captured[0]]; + [_table addSublayer: _captured[0]]; [_captured[0] release]; _captured[1] = [[Stack alloc] initWithStartPos: CGPointMake(0,captureHeight) @@ -93,7 +93,7 @@ CGRectGetMinY(gridFrame)+pieceSize, 2*pieceSize, captureHeight); _captured[1].zPosition = kPieceZ+1; - [_board addSublayer: _captured[1]]; + [_table addSublayer: _captured[1]]; [_captured[1] release]; PreloadSound(@"Pop"); @@ -107,7 +107,7 @@ - (Piece*) pieceForPlayer: (int)index { NSString *imageName = index ?@"bot086.png" :@"bot089.png"; - CGFloat pieceSize = (int)(_grid.spacing.width * 0.9) & ~1; // make sure it's even + CGFloat pieceSize = (int)(_board.spacing.width * 0.9) & ~1; // make sure it's even Piece *stone = [[Piece alloc] initWithImageNamed: imageName scale: pieceSize]; stone.owner = [self.players objectAtIndex: index]; return [stone autorelease]; @@ -191,11 +191,11 @@ - (NSString*) stateString { - int n = _grid.rows; + int n = _board.rows; unichar state[n*n]; for( int y=0; y)srcHolder to: (id)dstHolder { Hex *src=(Hex*)srcHolder, *dst=(Hex*)dstHolder; - int playerIndex = self.currentPlayer.index; Turn *turn = self.currentTurn; if( turn.move.length==0 ) @@ -80,7 +84,7 @@ PlaySound(isKing ?@"Funk" :@"Tink"); // "King" a piece that made it to the last row: - if( dst.row == (playerIndex ?0 :8) ) + if( dst.fr == nil ) if( ! isKing ) { PlaySound(@"Blow"); bit.scale = 1.4; @@ -109,11 +113,14 @@ [capture destroyBit]; // Now check if another capture is possible. If so, don't end the turn: - if( (dst.fl.bit.unfriendly && dst.fl.fl.empty) || (dst.fr.bit.unfriendly && dst.fr.fr.empty) ) + if( (dst.fl.bit.unfriendly && dst.fl.fl.empty) + || (dst.fr.bit.unfriendly && dst.fr.fr.empty) + || (dst. r.bit.unfriendly && dst. r. r.empty) ) return; if( isKing ) - if( (dst.bl.bit.unfriendly && dst.bl.bl.empty) || (dst.br.bit.unfriendly && dst.br.br.empty) - || (dst.l.bit.unfriendly && dst.l.l.empty) || (dst.r.bit.unfriendly && dst.r.r.empty)) + if( (dst.bl.bit.unfriendly && dst.bl.bl.empty) + || (dst.br.bit.unfriendly && dst.br.br.empty) + || (dst.l.bit.unfriendly && dst.l.l.empty) ) return; } diff -r 73f8c889f053 -r 28392c9a969f Source/KlondikeGame.m --- a/Source/KlondikeGame.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/KlondikeGame.m Mon Jul 14 21:00:15 2008 -0700 @@ -50,7 +50,7 @@ - (void) setUpBoard { - CGSize boardSize = _board.bounds.size; + CGSize boardSize = _table.bounds.size; CGFloat xSpacing = floor(boardSize.width/7); CGSize kCardSize; kCardSize.width = round(xSpacing * 0.9); // 1/7th of width, with 10% gap @@ -62,19 +62,19 @@ _deck = [[[Deck alloc] initWithCardsOfClass: [PlayingCard class]] autorelease]; [_deck shuffle]; _deck.position = pos; - [_board addSublayer: _deck]; + [_table addSublayer: _deck]; pos.x += xSpacing; _sink = [[[Deck alloc] init] autorelease]; _sink.position = pos; - [_board addSublayer: _sink]; + [_table addSublayer: _sink]; pos.x += xSpacing; for( CardSuit suit=kSuitClubs; suit<=kSuitSpades; suit++ ) { pos.x += xSpacing; Deck *aces = [[[Deck alloc] init] autorelease]; aces.position = pos; - [_board addSublayer: aces]; + [_table addSublayer: aces]; _aces[suit] = aces; } @@ -88,7 +88,7 @@ stackFrame.origin.x += xSpacing; stack.backgroundColor = nil; //kAlmostInvisibleWhiteColor; stack.dragAsStacks = YES; - [_board addSublayer: stack]; + [_table addSublayer: stack]; // According to the rules, one card should be added to each stack in turn, instead // of populating entire stacks one at a time. However, if one trusts the Deck's diff -r 73f8c889f053 -r 28392c9a969f Source/Player.m --- a/Source/Player.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Player.m Mon Jul 14 21:00:15 2008 -0700 @@ -8,6 +8,7 @@ #import "Player.h" #import "Game.h" +#import "GGBUtils.h" #pragma mark - diff -r 73f8c889f053 -r 28392c9a969f Source/TicTacToeGame.m --- a/Source/TicTacToeGame.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/TicTacToeGame.m Mon Jul 14 21:00:15 2008 -0700 @@ -50,19 +50,19 @@ - (void) setUpBoard { // Create a 3x3 grid: - CGFloat center = floor(CGRectGetMidX(_board.bounds)); + CGFloat center = floor(CGRectGetMidX(_table.bounds)); [_grid release]; _grid = [[RectGrid alloc] initWithRows: 3 columns: 3 frame: CGRectMake(center-150,0, 300,300)]; [_grid addAllCells]; _grid.allowsMoves = _grid.allowsCaptures = NO; _grid.cellColor = CreateGray(1.0, 0.25); _grid.lineColor = kTranslucentLightGrayColor; - [_board addSublayer: _grid]; + [_table addSublayer: _grid]; // Create piece dispensers for the two players: for( int playerNumber=0; playerNumber<=1; playerNumber++ ) { Piece *p = [self pieceForPlayer: playerNumber]; - CGFloat x = floor(CGRectGetMidX(_board.bounds)); + CGFloat x = floor(CGRectGetMidX(_table.bounds)); #if TARGET_OS_IPHONE x = x - 80 + 160*playerNumber; CGFloat y = 360; @@ -73,7 +73,7 @@ [_dispenser[playerNumber] release]; _dispenser[playerNumber] = [[Dispenser alloc] initWithPrototype: p quantity: 0 frame: CGRectMake(x-45,y-45, 90,90)]; - [_board addSublayer: _dispenser[playerNumber]]; + [_table addSublayer: _dispenser[playerNumber]]; } } diff -r 73f8c889f053 -r 28392c9a969f Source/Turn.h --- a/Source/Turn.h Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Turn.h Mon Jul 14 21:00:15 2008 -0700 @@ -58,4 +58,9 @@ @property BOOL replaying; + + +/** Changes a Turn's status from finished back to complete. For use only by -[Game unfinishLastTurn] */ +- (void) _unfinish; + @end diff -r 73f8c889f053 -r 28392c9a969f Source/Turn.m --- a/Source/Turn.m Wed Jul 09 17:07:45 2008 -0700 +++ b/Source/Turn.m Mon Jul 14 21:00:15 2008 -0700 @@ -130,6 +130,15 @@ } +- (void) _unfinish +{ + NSAssert(_status==kTurnFinished,@"Turn must be finished"); + [self willChangeValueForKey: @"status"]; + _status = kTurnComplete; + [self didChangeValueForKey: @"status"]; +} + + - (Turn*) previousTurn { unsigned n = self.turnNumber; @@ -169,7 +178,7 @@ { if( ! _replaying ) { NSAssert(_status