1.1 --- a/Source/KlondikeGame.m Mon Mar 10 17:30:57 2008 -0700
1.2 +++ b/Source/KlondikeGame.m Thu May 29 15:04:06 2008 -0700
1.3 @@ -24,21 +24,19 @@
1.4 #import "Deck.h"
1.5 #import "PlayingCard.h"
1.6 #import "Stack.h"
1.7 +#import "QuartzUtils.h"
1.8
1.9
1.10 #define kStackHeight 500
1.11
1.12
1.13 -/** WARNING: THIS CODE REQUIRES GARBAGE COLLECTION!
1.14 - ** This sample application uses Objective-C 2.0 garbage collection.
1.15 - ** Therefore, the source code in this file does NOT perform manual object memory management.
1.16 - ** If you reuse any of this code in a process that isn't garbage collected, you will need to
1.17 - ** add all necessary retain/release/autorelease calls, and implement -dealloc methods,
1.18 - ** otherwise unpleasant leakage will occur!
1.19 - **/
1.20 +@implementation KlondikeGame
1.21
1.22
1.23 -@implementation KlondikeGame
1.24 ++ (BOOL) landscapeOriented
1.25 +{
1.26 + return YES;
1.27 +}
1.28
1.29
1.30 - (id) initWithBoard: (GGBLayer*)board
1.31 @@ -47,29 +45,43 @@
1.32 if (self != nil) {
1.33 [self setNumberOfPlayers: 1];
1.34
1.35 + CGSize boardSize = board.bounds.size;
1.36 + CGFloat xSpacing = floor(boardSize.width/7);
1.37 + CGSize kCardSize;
1.38 + kCardSize.width = round(xSpacing * 0.9); // 1/7th of width, with 10% gap
1.39 + kCardSize.height = round(kCardSize.width * 1.5);
1.40 + CGFloat gap = xSpacing-kCardSize.width;
1.41 + [Card setCardSize: kCardSize];
1.42 +
1.43 + CGPoint pos = {floor(gap/2)+kCardSize.width/2, floor(boardSize.height-kCardSize.height/2)};
1.44 _deck = [[Deck alloc] initWithCardsOfClass: [PlayingCard class]];
1.45 [_deck shuffle];
1.46 - _deck.position = CGPointMake(kCardWidth/2+16,kCardHeight/2+16);
1.47 + _deck.position = pos;
1.48 [board addSublayer: _deck];
1.49
1.50 + pos.x += xSpacing;
1.51 _sink = [[Deck alloc] init];
1.52 - _sink.position = CGPointMake(3*kCardWidth/2+32,kCardHeight/2+16);
1.53 + _sink.position = pos;
1.54 [board addSublayer: _sink];
1.55
1.56 + pos.x += xSpacing;
1.57 for( CardSuit suit=kSuitClubs; suit<=kSuitSpades; suit++ ) {
1.58 + pos.x += xSpacing;
1.59 Deck *aces = [[Deck alloc] init];
1.60 - aces.position = CGPointMake(kCardWidth/2+16+(kCardWidth+16)*(suit%2),
1.61 - 120+kCardHeight+(kCardHeight+16)*(suit/2));
1.62 + aces.position = pos;
1.63 [board addSublayer: aces];
1.64 _aces[suit] = aces;
1.65 }
1.66
1.67 + CGRect stackFrame = {{floor(gap/2), gap},
1.68 + {kCardSize.width, boardSize.height-kCardSize.height-2*gap}};
1.69 + CGPoint startPos = CGPointMake(kCardSize.width/2,kCardSize.height/2);
1.70 + CGSize spacing = {0, floor((stackFrame.size.height-kCardSize.height)/11.0)};
1.71 for( int s=0; s<7; s++ ) {
1.72 - Stack *stack = [[Stack alloc] initWithStartPos: CGPointMake(kCardWidth/2,
1.73 - kStackHeight-kCardHeight/2.0)
1.74 - spacing: CGSizeMake(0,-22)];
1.75 - stack.frame = CGRectMake(260+s*(kCardWidth+16),16, kCardWidth,kStackHeight);
1.76 - stack.backgroundColor = nil;
1.77 + Stack *stack = [[Stack alloc] initWithStartPos: startPos spacing: spacing];
1.78 + stack.frame = stackFrame;
1.79 + stackFrame.origin.x += xSpacing;
1.80 + stack.backgroundColor = nil; //kAlmostInvisibleWhiteColor;
1.81 stack.dragAsStacks = YES;
1.82 [board addSublayer: stack];
1.83