Source/DemoBoardView.m
changeset 10 6c78cc6bd7a6
parent 8 45c82a071aca
child 11 436cbdf56810
     1.1 --- a/Source/DemoBoardView.m	Wed May 28 12:47:10 2008 -0700
     1.2 +++ b/Source/DemoBoardView.m	Thu Jul 03 17:44:30 2008 -0700
     1.3 @@ -26,15 +26,6 @@
     1.4  #import "QuartzUtils.h"
     1.5  
     1.6  
     1.7 -/**  WARNING: THIS CODE REQUIRES GARBAGE COLLECTION!
     1.8 - **  This sample application uses Objective-C 2.0 garbage collection.
     1.9 - **  Therefore, the source code in this file does NOT perform manual object memory management.
    1.10 - **  If you reuse any of this code in a process that isn't garbage collected, you will need to
    1.11 - **  add all necessary retain/release/autorelease calls, and implement -dealloc methods,
    1.12 - **  otherwise unpleasant leakage will occur!
    1.13 - **/
    1.14 -
    1.15 -
    1.16  @implementation DemoBoardView
    1.17  
    1.18  
    1.19 @@ -46,6 +37,14 @@
    1.20  static NSString* sCurrentGameName = @"CheckersGame";
    1.21  
    1.22  
    1.23 +- (IBAction) toggleRemoteOpponent: (id)sender
    1.24 +{
    1.25 +    NSAssert(self.game.currentTurn==0,@"Game has already begun");
    1.26 +    Player *opponent = [self.game.players objectAtIndex: 1];
    1.27 +    opponent.local = !opponent.local;
    1.28 +}
    1.29 +
    1.30 +
    1.31  - (void) startGameNamed: (NSString*)gameClassName
    1.32  {
    1.33      [super startGameNamed: gameClassName];
    1.34 @@ -112,19 +111,26 @@
    1.35  {
    1.36      Game *game = self.game;
    1.37      if( object == game ) {
    1.38 -        NSLog(@"maxTurn = %u, currentTurn=%u", self.game.maxTurn,self.game.currentTurn);
    1.39 +        NSLog(@"maxTurn = %u, currentTurn = %u", 
    1.40 +              self.game.maxTurn,self.game.currentTurn);
    1.41 +        NSLog(@"Game state = '%@'", self.game.stateString);
    1.42 +
    1.43          _turnSlider.maxValue = self.game.maxTurn;
    1.44          _turnSlider.numberOfTickMarks = self.game.maxTurn+1;
    1.45          
    1.46          Player *p = game.winner;
    1.47          NSString *msg;
    1.48          if( p ) {
    1.49 +            // The game is won
    1.50              [[NSSound soundNamed: @"Sosumi"] play];
    1.51 -            msg = @"%@ wins! Congratulations!";
    1.52 +            if( self.game.local )
    1.53 +                msg = @"%@ wins! Congratulations!";
    1.54 +            else
    1.55 +                msg = p.local ?@"You Win! Congratulations!" :@"You Lose ... :-(";
    1.56          } else {
    1.57 +            // Otherwise go on to the next turn:
    1.58              p = game.currentPlayer;
    1.59              msg = @"Your turn, %@";
    1.60 -            NSLog(@"Game state = '%@'", self.game.stateString);
    1.61          }
    1.62          _headline.string = [NSString stringWithFormat: msg, p.name];
    1.63      }
    1.64 @@ -149,13 +155,6 @@
    1.65  }
    1.66  
    1.67  
    1.68 -- (IBAction) enterFullScreen: (id)sender
    1.69 -{
    1.70 -    [super enterFullScreen: sender];
    1.71 -    [self startGameNamed: sCurrentGameName];        // restart game so it'll use the new size
    1.72 -}
    1.73 -
    1.74 -
    1.75  #pragma mark -
    1.76  #pragma mark NSAPPLICATION DELEGATE:
    1.77