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