jens@10: // jens@10: // Game+Protected.h jens@10: // YourMove jens@10: // jens@10: // Created by Jens Alfke on 7/3/08. jens@10: // Copyright 2008 Jens Alfke. All rights reserved. jens@10: // jens@10: jens@10: jens@10: #import "Game.h" jens@10: #import "Player.h" jens@10: #import "Turn.h" jens@10: #import "Bit.h" jens@10: #import "BitHolder.h" jens@12: @class Piece; jens@10: jens@10: jens@10: /** Game API for subclasses to use / override */ jens@10: @interface Game (Protected) jens@10: jens@10: /** Should return a string describing the initial state of a new game. jens@10: The default value is an empty string. */ jens@10: - (NSString*) initialStateString; jens@10: jens@10: jens@10: #pragma mark Abstract methods for subclasses to implement: jens@10: jens@10: /** Called by -setBoard: Should all all necessary Grids/Pieces/Cards/etc. to _board. jens@10: This method is always called during initialization of a new Game, and may be called jens@10: again afterwards, for example if the board area is resized. */ jens@10: - (void) setUpBoard; jens@10: jens@10: /** Should return the winning player, if the current position is a win, else nil. jens@10: Default implementation returns nil. */ jens@10: - (Player*) checkForWinner; jens@10: jens@10: jens@10: #pragma mark Protected methods for subclasses to call: jens@10: jens@10: /** Sets the number of players in the game. Subclass initializers should call this. */ jens@10: - (void) setNumberOfPlayers: (unsigned)n; jens@10: jens@10: /** Animate a piece moving from src to dst. Used in implementing -applyMoveString:. */ jens@10: - (BOOL) animateMoveFrom: (CALayer*)src to: (CALayer*)dst; jens@10: jens@10: /** Animate a piece being placed in dst. Used in implementing -applyMoveString:. */ jens@10: - (BOOL) animatePlacementIn: (CALayer*)dst; jens@10: jens@10: /** Checks for a winner and advances to the next player. */ jens@10: - (void) endTurn; jens@10: jens@10: @end jens@10: jens@10: jens@10: /** Optional Game API for tracking the history of a game, and being able to replay moves. */ jens@10: @interface Game (State) jens@10: jens@10: /** A string describing the current state of the game (the positions of all pieces, jens@10: orderings of cards, player scores, ... */ jens@10: @property (copy) NSString* stateString; jens@10: jens@10: /** Add a move to the game based on the contents of the string. jens@10: The string must have been returned by -currentMove at some point. */ jens@10: - (BOOL) applyMoveString: (NSString*)move; jens@10: jens@12: /** An optional method called as a subroutine by -[Grid setStateString:]. jens@12: If you decide to call that in your -setStateString: implementation, you need to implement this too. */ jens@12: - (Piece*) makePieceNamed: (NSString*)name; jens@12: jens@10: @end