Source/Game.h
changeset 11 436cbdf56810
parent 8 45c82a071aca
child 15 73f8c889f053
     1.1 --- a/Source/Game.h	Wed May 28 12:47:10 2008 -0700
     1.2 +++ b/Source/Game.h	Sat Jul 05 17:46:43 2008 -0700
     1.3 @@ -20,56 +20,72 @@
     1.4      CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
     1.5      THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     1.6  */
     1.7 -@class GGBLayer, Bit, BitHolder, Player;
     1.8 +
     1.9 +#import <Foundation/Foundation.h>
    1.10 +@class GGBLayer, Bit, BitHolder, Player, Turn;
    1.11  @protocol BitHolder;
    1.12  
    1.13  
    1.14  /** Abstract superclass. Keeps track of the rules and turns of a game. */
    1.15 -@interface Game : NSObject
    1.16 +@interface Game : NSObject <NSCoding>
    1.17  {
    1.18 -    NSString *_uniqueID;
    1.19      GGBLayer *_board;
    1.20      NSArray *_players;
    1.21 -    Player *_currentPlayer, *_winner;
    1.22 -    NSMutableString *_currentMove;
    1.23 -    NSMutableArray *_states, *_moves;
    1.24 -    unsigned _currentTurn;
    1.25 +    Player *_winner;
    1.26 +    NSMutableArray *_turns;
    1.27 +    unsigned _currentTurnNo;
    1.28 +    NSMutableDictionary *_extraValues;
    1.29 +    BOOL _requireConfirmation;
    1.30  }
    1.31  
    1.32 -/** Returns the name used to identify this game in URLs.
    1.33 -     (By default it just returns the class name with the "Game" suffix removed.) */
    1.34 +#pragma mark  Class properties:
    1.35 +
    1.36 +/** The name used to identify this class of game in URLs.
    1.37 +    (By default it just returns the class name with the "Game" suffix removed.) */
    1.38  + (NSString*) identifier;
    1.39  
    1.40 -/** Returns the human-readable name of this game.
    1.41 +/** The human-readable name of this class of game.
    1.42      (By default it just returns the class name with the "Game" suffix removed.) */
    1.43  + (NSString*) displayName;
    1.44  
    1.45 +/** Is this game's board wider than it's high? */
    1.46  + (BOOL) landscapeOriented;
    1.47  
    1.48 +
    1.49 +/** Designated initializer: override this if your subclass needs additional initialization. */
    1.50 +- (id) init;
    1.51 +
    1.52 +/** Convenience initializer that calls -init, -setBoard:, and -nextTurn. */
    1.53 +- (id) initNewGameWithBoard: (GGBLayer*)board;
    1.54 +
    1.55 +/** NSCoding initializer. Calls -init, but then restores saved payers, states, moves. */
    1.56 +- (id) initWithCoder: (NSCoder*)decoder;
    1.57 +
    1.58 +/** NSCoding method to save Game to an archive. */
    1.59 +- (void) encodeWithCoder: (NSCoder*)coder;
    1.60 +
    1.61 +
    1.62  @property (readonly, copy) NSArray *players;
    1.63 -@property (readonly) Player *currentPlayer, *winner;
    1.64 +@property (readonly) Player *currentPlayer, *winner, *remotePlayer;
    1.65 +@property (readonly, getter=isLocal) BOOL local;            // Are all players local?
    1.66  
    1.67 -@property (readonly) NSArray *states, *moves;
    1.68 -@property (readonly) unsigned maxTurn;
    1.69 -@property unsigned currentTurn;
    1.70 +@property (retain) GGBLayer *board;                         // The root layer for the game.
    1.71 +
    1.72 +@property (readonly) NSArray *turns;
    1.73 +@property (readonly) Turn *currentTurn, *latestTurn;
    1.74 +@property (readonly) unsigned maxTurnNo;
    1.75 +@property unsigned currentTurnNo;
    1.76  @property (readonly) BOOL isLatestTurn;
    1.77  
    1.78 +@property BOOL requireConfirmation;
    1.79 +- (void) cancelCurrentTurn;
    1.80 +- (void) confirmCurrentTurn;
    1.81  
    1.82 -/** A globally-unique string assigned to this game instance, to help networked players identify it. */
    1.83 -@property (readonly) NSString* uniqueID;
    1.84  
    1.85 -- (BOOL) animateMoveFrom: (BitHolder*)src to: (BitHolder*)dst;
    1.86 +#pragma mark  Methods for subclasses to implement:
    1.87  
    1.88 -
    1.89 -- (id) initWithUniqueID: (NSString*)uniqueID;
    1.90 -- (id) init;
    1.91 -
    1.92 -
    1.93 -// Methods for subclasses to implement:
    1.94 -
    1.95 -/** Designated initializer. After calling the superclass implementation,
    1.96 -    it should add the necessary Grids, Pieces, Cards, Decks etc. to the board. */
    1.97 -- (id) initWithBoard: (GGBLayer*)board;
    1.98 +/** An icon for a player (usually the same as the image of the player's pieces.) */
    1.99 +- (CGImageRef) iconForPlayer: (int)playerIndex;
   1.100  
   1.101  
   1.102  /** Should return YES if it is legal for the given bit to be moved from its current holder.
   1.103 @@ -96,60 +112,4 @@
   1.104      Default implementation always returns YES. */
   1.105  - (BOOL) clickedBit: (Bit*)bit;
   1.106  
   1.107 -/** Should return the winning player, if the current position is a win, else nil.
   1.108 -    Default implementation returns nil. */
   1.109 -- (Player*) checkForWinner;
   1.110 -
   1.111 -/** A string describing the current state of the game (the positions of all pieces,
   1.112 -    orderings of cards, player scores, ... */
   1.113 -@property (copy) NSString* stateString;
   1.114 -
   1.115 -/** Add a move to the game based on the contents of the string. */
   1.116 -- (BOOL) applyMoveString: (NSString*)move;
   1.117 -
   1.118 -
   1.119 -// Protected methods for subclasses to call:
   1.120 -
   1.121 -/** Sets the number of players in the game. Subclass initializers should call this. */
   1.122 -- (void) setNumberOfPlayers: (unsigned)n;
   1.123 -
   1.124 -/** The current move in progress. Append text to it as the user makes moves. */
   1.125 -@property (readonly) NSMutableString* currentMove;
   1.126 -
   1.127 -/** Advance to the next player, when a turn is over. */
   1.128 -- (void) nextPlayer;
   1.129 -
   1.130 -/** Checks for a winner and advances to the next player. */
   1.131 -- (void) endTurn;
   1.132 -
   1.133  @end
   1.134 -
   1.135 -
   1.136 -
   1.137 -/** A mostly-passive object used to represent a player. */
   1.138 -@interface Player : NSObject <NSCoding>
   1.139 -{
   1.140 -    Game *_game;
   1.141 -    NSString *_name;
   1.142 -}
   1.143 -
   1.144 -- (id) initWithGame: (Game*)game;
   1.145 -
   1.146 -@property (readonly) Game *game;
   1.147 -@property (copy) NSString *name;
   1.148 -@property (readonly) int index;
   1.149 -@property (readonly, getter=isCurrent) BOOL current;
   1.150 -@property (readonly, getter=isFriendly) BOOL friendly;
   1.151 -@property (readonly, getter=isUnfriendly) BOOL unfriendly;
   1.152 -@property (readonly) Player *nextPlayer, *previousPlayer;
   1.153 -
   1.154 -@end
   1.155 -
   1.156 -
   1.157 -
   1.158 -@interface CALayer (Game)
   1.159 -
   1.160 -/** Called on any CALayer in the game's layer tree, will return the current Game object. */
   1.161 -@property (readonly) Game *game;
   1.162 -
   1.163 -@end