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