Source/Game+Protected.h
author Jens Alfke <jens@mooseyard.com>
Thu Jul 17 13:29:04 2008 -0700 (2008-07-17)
changeset 19 3b750982ff39
parent 10 6c78cc6bd7a6
child 22 4cb50131788f
permissions -rw-r--r--
Don't load Checkers sound files till a game is displayed on a board; this speeds up launch.
jens@10
     1
//
jens@10
     2
//  Game+Protected.h
jens@10
     3
//  YourMove
jens@10
     4
//
jens@10
     5
//  Created by Jens Alfke on 7/3/08.
jens@10
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@10
     7
//
jens@10
     8
jens@10
     9
jens@10
    10
#import "Game.h"
jens@10
    11
#import "Player.h"
jens@10
    12
#import "Turn.h"
jens@10
    13
#import "Bit.h"
jens@10
    14
#import "BitHolder.h"
jens@12
    15
@class Piece;
jens@10
    16
jens@10
    17
jens@10
    18
/** Game API for subclasses to use / override */
jens@10
    19
@interface Game (Protected)
jens@10
    20
jens@10
    21
/** Should return a string describing the initial state of a new game.
jens@10
    22
    The default value is an empty string. */
jens@10
    23
- (NSString*) initialStateString;
jens@10
    24
jens@10
    25
jens@10
    26
#pragma mark  Abstract methods for subclasses to implement:
jens@10
    27
jens@10
    28
/** Called by -setBoard: Should all all necessary Grids/Pieces/Cards/etc. to _board.
jens@10
    29
    This method is always called during initialization of a new Game, and may be called
jens@10
    30
    again afterwards, for example if the board area is resized. */
jens@10
    31
- (void) setUpBoard;
jens@10
    32
jens@10
    33
/** Should return the winning player, if the current position is a win, else nil.
jens@10
    34
    Default implementation returns nil. */
jens@10
    35
- (Player*) checkForWinner;
jens@10
    36
jens@10
    37
jens@10
    38
#pragma mark  Protected methods for subclasses to call:
jens@10
    39
jens@10
    40
/** Sets the number of players in the game. Subclass initializers should call this. */
jens@10
    41
- (void) setNumberOfPlayers: (unsigned)n;
jens@10
    42
jens@10
    43
/** Animate a piece moving from src to dst. Used in implementing -applyMoveString:. */
jens@10
    44
- (BOOL) animateMoveFrom: (CALayer<BitHolder>*)src to: (CALayer<BitHolder>*)dst;
jens@10
    45
jens@10
    46
/** Animate a piece being placed in dst. Used in implementing -applyMoveString:. */
jens@10
    47
- (BOOL) animatePlacementIn: (CALayer<BitHolder>*)dst;
jens@10
    48
jens@10
    49
/** Checks for a winner and advances to the next player. */
jens@10
    50
- (void) endTurn;
jens@10
    51
jens@10
    52
@end
jens@10
    53
jens@10
    54
jens@10
    55
/** Optional Game API for tracking the history of a game, and being able to replay moves. */
jens@10
    56
@interface Game (State)
jens@10
    57
jens@10
    58
/** A string describing the current state of the game (the positions of all pieces,
jens@10
    59
 orderings of cards, player scores, ... */
jens@10
    60
@property (copy) NSString* stateString;
jens@10
    61
jens@10
    62
/** Add a move to the game based on the contents of the string.
jens@10
    63
 The string must have been returned by -currentMove at some point. */
jens@10
    64
- (BOOL) applyMoveString: (NSString*)move;
jens@10
    65
jens@12
    66
/** An optional method called as a subroutine by -[Grid setStateString:].
jens@12
    67
    If you decide to call that in your -setStateString: implementation, you need to implement this too. */ 
jens@12
    68
- (Piece*) makePieceNamed: (NSString*)name;
jens@12
    69
jens@10
    70
@end