Source/Game+Protected.h
author Jens Alfke <jens@mooseyard.com>
Sun Feb 06 16:31:03 2011 -0800 (2011-02-06)
changeset 29 0b1c315ffc64
parent 12 4e567e11f45f
permissions -rw-r--r--
Minor compiler-compatibility fixes.
     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 @class Piece;
    16 
    17 
    18 /** Game API for subclasses to use / override */
    19 @interface Game (Protected)
    20 
    21 /** Should return a string describing the initial state of a new game.
    22     The default value is an empty string. */
    23 - (NSString*) initialStateString;
    24 
    25 
    26 #pragma mark  Abstract methods for subclasses to implement:
    27 
    28 /** Called by -setTable: Should all all necessary Grids/Pieces/Cards/etc. to _table.
    29     This method is always called during initialization of a new Game, and may be called
    30     again afterwards, for example if the table area is resized. */
    31 - (void) setUpBoard;
    32 
    33 /** Called after the tablePerspectiveAngle property changes. */
    34 - (void) perspectiveChanged;
    35 
    36 /** Should return the winning player, if the current position is a win, else nil.
    37     Default implementation returns nil. */
    38 - (Player*) checkForWinner;
    39 
    40 
    41 #pragma mark  Protected methods for subclasses to call:
    42 
    43 /** Sets the number of players in the game. Subclass initializers should call this. */
    44 - (void) setNumberOfPlayers: (unsigned)n;
    45 
    46 /** The angle by which the table is tilted "away from" the viewer to give 3D perspective.
    47     Subclasses should not change this! It won't do anything. */
    48 @property CGFloat tablePerspectiveAngle;
    49 
    50 /** Animate a piece moving from src to dst. Used in implementing -applyMoveString:. */
    51 - (BOOL) animateMoveFrom: (CALayer<BitHolder>*)src to: (CALayer<BitHolder>*)dst;
    52 
    53 /** Animate a piece being placed in dst. Used in implementing -applyMoveString:. */
    54 - (BOOL) animatePlacementIn: (CALayer<BitHolder>*)dst;
    55 
    56 /** Checks for a winner and advances to the next player. */
    57 - (void) endTurn;
    58 
    59 @end
    60 
    61 
    62 /** Optional Game API for tracking the history of a game, and being able to replay moves. */
    63 @interface Game (State)
    64 
    65 /** A string describing the current state of the game (the positions of all pieces,
    66  orderings of cards, player scores, ... */
    67 @property (copy) NSString* stateString;
    68 
    69 /** Add a move to the game based on the contents of the string.
    70  The string must have been returned by -currentMove at some point. */
    71 - (BOOL) applyMoveString: (NSString*)move;
    72 
    73 /** An optional method called as a subroutine by -[Grid setStateString:].
    74     If you decide to call that in your -setStateString: implementation, you need to implement this too. */ 
    75 - (Piece*) makePieceNamed: (NSString*)name;
    76 
    77 @end