Source/Game+Protected.h
author Jens Alfke <jens@mooseyard.com>
Sat Jul 05 17:46:43 2008 -0700 (2008-07-05)
changeset 11 436cbdf56810
child 12 4e567e11f45f
permissions -rw-r--r--
* Improved drag-and-drop (supports CandyBar)
* Fixed DiscPiece
* Inheritable layer styles
etc.
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@10
    15
jens@10
    16
jens@10
    17
/** Game API for subclasses to use / override */
jens@10
    18
@interface Game (Protected)
jens@10
    19
jens@10
    20
/** Should return a string describing the initial state of a new game.
jens@10
    21
    The default value is an empty string. */
jens@10
    22
- (NSString*) initialStateString;
jens@10
    23
jens@10
    24
jens@10
    25
#pragma mark  Abstract methods for subclasses to implement:
jens@10
    26
jens@10
    27
/** Called by -setBoard: Should all all necessary Grids/Pieces/Cards/etc. to _board.
jens@10
    28
    This method is always called during initialization of a new Game, and may be called
jens@10
    29
    again afterwards, for example if the board area is resized. */
jens@10
    30
- (void) setUpBoard;
jens@10
    31
jens@10
    32
/** Should return the winning player, if the current position is a win, else nil.
jens@10
    33
    Default implementation returns nil. */
jens@10
    34
- (Player*) checkForWinner;
jens@10
    35
jens@10
    36
jens@10
    37
#pragma mark  Protected methods for subclasses to call:
jens@10
    38
jens@10
    39
/** Sets the number of players in the game. Subclass initializers should call this. */
jens@10
    40
- (void) setNumberOfPlayers: (unsigned)n;
jens@10
    41
jens@10
    42
/** Animate a piece moving from src to dst. Used in implementing -applyMoveString:. */
jens@10
    43
- (BOOL) animateMoveFrom: (CALayer<BitHolder>*)src to: (CALayer<BitHolder>*)dst;
jens@10
    44
jens@10
    45
/** Animate a piece being placed in dst. Used in implementing -applyMoveString:. */
jens@10
    46
- (BOOL) animatePlacementIn: (CALayer<BitHolder>*)dst;
jens@10
    47
jens@10
    48
/** Checks for a winner and advances to the next player. */
jens@10
    49
- (void) endTurn;
jens@10
    50
jens@10
    51
@end
jens@10
    52
jens@10
    53
jens@10
    54
/** Optional Game API for tracking the history of a game, and being able to replay moves. */
jens@10
    55
@interface Game (State)
jens@10
    56
jens@10
    57
/** A string describing the current state of the game (the positions of all pieces,
jens@10
    58
 orderings of cards, player scores, ... */
jens@10
    59
@property (copy) NSString* stateString;
jens@10
    60
jens@10
    61
/** Add a move to the game based on the contents of the string.
jens@10
    62
 The string must have been returned by -currentMove at some point. */
jens@10
    63
- (BOOL) applyMoveString: (NSString*)move;
jens@10
    64
jens@10
    65
@end