Source/HexchequerGame.m
changeset 10 6c78cc6bd7a6
parent 7 428a194e3e59
child 12 4e567e11f45f
     1.1 --- a/Source/HexchequerGame.m	Sun Mar 16 15:06:47 2008 -0700
     1.2 +++ b/Source/HexchequerGame.m	Thu Jul 03 17:44:30 2008 -0700
     1.3 @@ -30,19 +30,20 @@
     1.4  @implementation HexchequerGame
     1.5  
     1.6  
     1.7 -- (Grid*) x_makeGrid
     1.8 +- (void) setUpBoard
     1.9  {
    1.10      HexGrid *grid = [[HexGrid alloc] initWithRows: 9 columns: 9 frame: _board.bounds];
    1.11      _grid = grid;
    1.12 +    [_board addSublayer: _grid];
    1.13      CGPoint pos = grid.position;
    1.14 -    pos.x = floor((_board.bounds.size.width-grid.frame.size.width)/2);
    1.15 +    pos.x += grid.spacing.width / 4;    // The right edge of the grid is blank because of the unused cells outside the hexagon
    1.16      grid.position = pos;
    1.17      grid.allowsMoves = YES;
    1.18      grid.allowsCaptures = NO;      // no land-on captures, that is
    1.19      grid.cellColor = CreateGray(1.0, 0.25);
    1.20      grid.lineColor = kTranslucentLightGrayColor;
    1.21 -    
    1.22      [grid addCellsInHexagon];
    1.23 +    [_cells removeAllObjects];
    1.24      for( int y=0; y<9; y++ ) {
    1.25          for( int x=0; x<9; x++ ) {
    1.26              GridCell *cell = [_grid cellAtRow: y column: x];
    1.27 @@ -50,14 +51,12 @@
    1.28                  [_cells addObject: cell];
    1.29          }
    1.30      }
    1.31 -    self.stateString = @"111111111111111111-------------------------222222222222222222";
    1.32 -    
    1.33 -    [self performSelector: @selector(applyMoveString:) withObject: @"C4D4" afterDelay: 2.0];
    1.34 -    [self performSelector: @selector(applyMoveString:) withObject: @"G3F3" afterDelay: 5.0];
    1.35 -    [self performSelector: @selector(applyMoveString:) withObject: @"D4E4" afterDelay: 8.0];
    1.36 -    [self performSelector: @selector(applyMoveString:) withObject: @"F3D4" afterDelay: 11.0];
    1.37 -    
    1.38 -    return grid;
    1.39 +}
    1.40 +
    1.41 +
    1.42 +- (NSString*) initialStateString
    1.43 +{
    1.44 +    return @"111111111111111111-------------------------222222222222222222";
    1.45  }
    1.46  
    1.47  
    1.48 @@ -78,9 +77,11 @@
    1.49      Hex *src=(Hex*)srcHolder, *dst=(Hex*)dstHolder;
    1.50      int playerIndex = self.currentPlayer.index;
    1.51  
    1.52 -    if( self.currentMove.length==0 )
    1.53 -        [self.currentMove appendString: src.name];
    1.54 -    [self.currentMove appendString: dst.name];
    1.55 +    Turn *turn = self.currentTurn;
    1.56 +    if( turn.move.length==0 )
    1.57 +        [turn addToMove: src.name];
    1.58 +    [turn addToMove: @"-"];
    1.59 +    [turn addToMove: dst.name];
    1.60      
    1.61      BOOL isKing = ([bit valueForKey: @"King"] != nil);    
    1.62      PlaySound(isKing ?@"Funk" :@"Tink");
    1.63 @@ -111,9 +112,9 @@
    1.64      
    1.65      if( capture ) {
    1.66          PlaySound(@"Pop");
    1.67 -        Bit *bit = capture.bit;
    1.68 -        _numPieces[bit.owner.index]--;
    1.69 -        [bit destroy];
    1.70 +        [turn addToMove: @"!"];
    1.71 +        _numPieces[capture.bit.owner.index]--;
    1.72 +        [capture destroyBit];
    1.73          
    1.74          // Now check if another capture is possible. If so, don't end the turn:
    1.75          if( (dst.fl.bit.unfriendly && dst.fl.fl.empty) || (dst.fr.bit.unfriendly && dst.fr.fr.empty) )