Source/HexchequerGame.m
changeset 17 ccc5ed68222d
parent 15 73f8c889f053
child 20 7c9ecb09a612
     1.1 --- a/Source/HexchequerGame.m	Wed Jul 09 17:07:45 2008 -0700
     1.2 +++ b/Source/HexchequerGame.m	Mon Jul 14 21:46:09 2008 -0700
     1.3 @@ -32,24 +32,27 @@
     1.4  
     1.5  - (void) setUpBoard
     1.6  {
     1.7 -    HexGrid *grid = [[HexGrid alloc] initWithRows: 9 columns: 9 frame: _board.bounds];
     1.8 -    _grid = grid;
     1.9 -    [_board addSublayer: _grid];
    1.10 -    CGPoint pos = grid.position;
    1.11 -    pos.x += grid.spacing.width / 4;    // The right edge of the grid is blank because of the unused cells outside the hexagon
    1.12 -    grid.position = pos;
    1.13 -    grid.allowsMoves = YES;
    1.14 -    grid.allowsCaptures = NO;      // no land-on captures, that is
    1.15 -    grid.cellColor = CreateGray(1.0, 0.25);
    1.16 -    grid.lineColor = kTranslucentLightGrayColor;
    1.17 -    grid.reversed = ! [[self.players objectAtIndex: 0] isLocal];
    1.18 -    [grid addCellsInHexagon];
    1.19 +    // Create a hex grid and rotate it 30 degrees so the cells are edge-up:
    1.20 +    CGRect tableBounds = _table.bounds;
    1.21 +    CGFloat s = tableBounds.size.height / 9;
    1.22 +    HexGrid *board = [[HexGrid alloc] initWithRows: 9 columns: 9
    1.23 +                                           spacing: CGSizeMake(s,s)
    1.24 +                                          position: GetCGRectCenter(tableBounds)];
    1.25 +    board.anchorPoint = CGPointMake(0.47,0.5);  // Missing half-cells on right edge perturb center pt
    1.26 +    [board setValue: [NSNumber numberWithDouble: M_PI/6] forKeyPath: @"transform.rotation"];
    1.27 +    _board = board;
    1.28 +    [_table addSublayer: _board];
    1.29 +    board.allowsMoves = YES;
    1.30 +    board.allowsCaptures = NO;      // no land-on captures, that is
    1.31 +    board.cellColor = CreateGray(1.0, 0.25);
    1.32 +    board.lineColor = kTranslucentLightGrayColor;
    1.33 +    board.reversed = ! [[self.players objectAtIndex: 0] isLocal];
    1.34 +    [board addCellsInHexagon];
    1.35  }
    1.36  
    1.37 -
    1.38  - (NSString*) initialStateString
    1.39  {
    1.40 -    return @"111111111111111111-------------------------222222222222222222";
    1.41 +      return @"1111-1111--1111---1111-----------------2222---2222--2222-2222";
    1.42  }
    1.43  
    1.44  
    1.45 @@ -57,18 +60,19 @@
    1.46  {
    1.47      Hex *src=(Hex*)srcHolder, *dst=(Hex*)dstHolder;
    1.48      if( [bit valueForKey: @"King"] )
    1.49 -        if( dst==src.bl || dst==src.br || dst==src.l || dst==src.r
    1.50 +        if( dst==src.bl || dst==src.br || dst==src.l
    1.51             || (src.bl.bit.unfriendly && dst==src.bl.bl) || (src.br.bit.unfriendly && dst==src.br.br)
    1.52 -           || (src.l.bit.unfriendly  && dst==src.l.l)   || (src.r.bit.unfriendly  && dst==src.r.r) )
    1.53 +           || (src.l.bit.unfriendly  && dst==src.l.l) )
    1.54              return YES;    
    1.55 -    return dst==src.fl || dst==src.fr
    1.56 -        || (src.fl.bit.unfriendly && dst==src.fl.fl) || (src.fr.bit.unfriendly && dst==src.fr.fr);
    1.57 +    return dst==src.fl || dst==src.fr || dst==src.r
    1.58 +            || (src.fl.bit.unfriendly && dst==src.fl.fl) 
    1.59 +            || (src.fr.bit.unfriendly && dst==src.fr.fr) 
    1.60 +            || (src. r.bit.unfriendly && dst==src. r. r);
    1.61  }
    1.62  
    1.63  - (void) bit: (Bit*)bit movedFrom: (id<BitHolder>)srcHolder to: (id<BitHolder>)dstHolder
    1.64  {
    1.65      Hex *src=(Hex*)srcHolder, *dst=(Hex*)dstHolder;
    1.66 -    int playerIndex = self.currentPlayer.index;
    1.67  
    1.68      Turn *turn = self.currentTurn;
    1.69      if( turn.move.length==0 )
    1.70 @@ -80,7 +84,7 @@
    1.71      PlaySound(isKing ?@"Funk" :@"Tink");
    1.72  
    1.73      // "King" a piece that made it to the last row:
    1.74 -    if( dst.row == (playerIndex ?0 :8) )
    1.75 +    if( dst.fr == nil )
    1.76          if( ! isKing ) {
    1.77              PlaySound(@"Blow");
    1.78              bit.scale = 1.4;
    1.79 @@ -109,11 +113,14 @@
    1.80          [capture destroyBit];
    1.81          
    1.82          // Now check if another capture is possible. If so, don't end the turn:
    1.83 -        if( (dst.fl.bit.unfriendly && dst.fl.fl.empty) || (dst.fr.bit.unfriendly && dst.fr.fr.empty) )
    1.84 +        if( (dst.fl.bit.unfriendly && dst.fl.fl.empty) 
    1.85 +                || (dst.fr.bit.unfriendly && dst.fr.fr.empty) 
    1.86 +                || (dst. r.bit.unfriendly && dst. r. r.empty) )
    1.87              return;
    1.88          if( isKing )
    1.89 -            if( (dst.bl.bit.unfriendly && dst.bl.bl.empty) || (dst.br.bit.unfriendly && dst.br.br.empty)
    1.90 -                    || (dst.l.bit.unfriendly && dst.l.l.empty) || (dst.r.bit.unfriendly && dst.r.r.empty))
    1.91 +            if( (dst.bl.bit.unfriendly && dst.bl.bl.empty)
    1.92 +                    || (dst.br.bit.unfriendly && dst.br.br.empty)
    1.93 +                    || (dst.l.bit.unfriendly && dst.l.l.empty) )
    1.94                  return;
    1.95      }
    1.96