Source/Stack.h
changeset 11 436cbdf56810
child 21 2eb229411d73
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Source/Stack.h	Sat Jul 05 17:46:43 2008 -0700
     1.3 @@ -0,0 +1,68 @@
     1.4 +/*  This code is based on Apple's "GeekGameBoard" sample code, version 1.0.
     1.5 +    http://developer.apple.com/samplecode/GeekGameBoard/
     1.6 +    Copyright © 2007 Apple Inc. Copyright © 2008 Jens Alfke. All Rights Reserved.
     1.7 +
     1.8 +    Redistribution and use in source and binary forms, with or without modification, are permitted
     1.9 +    provided that the following conditions are met:
    1.10 +
    1.11 +    * Redistributions of source code must retain the above copyright notice, this list of conditions
    1.12 +      and the following disclaimer.
    1.13 +    * Redistributions in binary form must reproduce the above copyright notice, this list of
    1.14 +      conditions and the following disclaimer in the documentation and/or other materials provided
    1.15 +      with the distribution.
    1.16 +
    1.17 +    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    1.18 +    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    1.19 +    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    1.20 +    BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.21 +    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    1.22 +    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    1.23 +    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    1.24 +    THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.25 +*/
    1.26 +#import "Bit.h"
    1.27 +#import "BitHolder.h"
    1.28 +
    1.29 +
    1.30 +/** A holder for multiple Bits that lines them up in stacks or rows.
    1.31 +    For example, this is used in solitaire card games for each pile in the "tableau". */
    1.32 +@interface Stack : BitHolder
    1.33 +{
    1.34 +    CGPoint _startPos;                      // see properties below for descriptions
    1.35 +    CGSize _spacing;       
    1.36 +    CGSize _wrapSpacing;   
    1.37 +    int _wrapInterval;     
    1.38 +    NSMutableArray *_bits; 
    1.39 +    BOOL _dragAsStacks;    
    1.40 +}
    1.41 +
    1.42 +- (id) initWithStartPos: (CGPoint)startPos spacing: (CGSize)spacing;
    1.43 +
    1.44 +- (id) initWithStartPos: (CGPoint)startPos spacing: (CGSize)spacing
    1.45 +           wrapInterval: (int)wrapInterval wrapSpacing: (CGSize)wrapSpacing;
    1.46 +
    1.47 +@property CGPoint startPos;                 // Position where first Bit should go
    1.48 +@property CGSize spacing;                   // Spacing between successive Bits
    1.49 +@property CGSize wrapSpacing;               // Spacing between wrapped-around sub-piles
    1.50 +@property int wrapInterval;                 // How many Bits to add before wrapping
    1.51 +@property BOOL dragAsStacks;                // If set to YES, dragging a Bit drags a DraggedStack
    1.52 +@property (readonly) NSArray *bits;         // The Bits, in order
    1.53 +@property (readonly) Bit *topBit;           // The topmost Bit (last item in self.bits)
    1.54 +
    1.55 +/** Adds a Bit to the end */
    1.56 +- (void) addBit: (Bit*)bit;
    1.57 +
    1.58 +@end
    1.59 +
    1.60 +
    1.61 +/** A subset of a Stack, dragged out of it if its dragAsStacks flag is set.
    1.62 +    This is used in typical card solitaire games.
    1.63 +    A DraggedStack exists only during a drag; afterwards, its Cards
    1.64 +    are incorporated into the destination Stack. */
    1.65 +@interface DraggedStack : Bit
    1.66 +
    1.67 +- (id) initWithBits: (NSArray*)bits;
    1.68 +
    1.69 +@property (readonly) NSArray *bits;
    1.70 +
    1.71 +@end