The document describes a game where the player controls buckets that can move left and right. It includes code for modeling the buckets, tests to verify the buckets can move, and code for a sprite to represent the buckets on screen. It then expands on this to add a bomber that moves between random locations, drops bombs, and has its own sprite. Tests are included to verify the bomber's behavior.
3. A game is a system in which players
engage in an artificial conflict,
defined by rules, that results in a
quantifiable outcome.
Rules of Play
Saturday, October 26, 13
18. Hello World Layer
+(CCScene *) scene
{
!// 'scene' is an autorelease object.
!CCScene *scene = [CCScene node];
!
!// 'layer' is an autorelease object.
!HelloWorldLayer *layer = [HelloWorldLayer node];
!
!// add layer as a child to scene
![scene addChild: layer];
!
!// return the scene
!return scene;
}
Saturday, October 26, 13
19. Hello World Layer
// on "init" you need to initialize your instance
-(id) init
{
! // always call "super" init
! // Apple recommends to re-assign "self" with the "super's" return value
! if( (self=[super init]) ) {
!!
! ! // create and initialize a Label
! ! CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World"
fontName:@"Marker Felt" fontSize:64];
!!
!!
!
!!
!!
!!
!!
!!
// ask director for the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
Saturday, October 26, 13
20. Buckets
OCDSpec2Context(BucketsSpec) {
Describe(@"moving", ^{
It(@"moves to the right", ^{
Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)];
[buckets move:1];
[ExpectFloat(buckets.position.x) toBe:11.0 withPrecision:0.00001];
});
It(@"moves to the left", ^{
Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)];
[buckets move:-1.0];
[ExpectFloat(buckets.position.x) toBe:9.0 withPrecision:0.00001];
});
});
}
Saturday, October 26, 13
21. Buckets
@implementation Buckets
-(id) initWithPosition:(CGPoint) position
{
if (self = [super init])
{
self.position = position;
}
return self;
}
-(void) move:(float) movement
{
self.position = CGPointMake(self.position.x + movement,
self.position.y);
}
@end
Saturday, October 26, 13
35. Random Locations
Describe(@"using the random number generator", ^{
It(@"uses the random number generator for its next location", ^{
id rand = [OCMockObject mockForProtocol:@protocol(RandomNumberGenerator)];
NSRange range = NSMakeRange(0, 100);
RandomLocationChooser *chooser = [RandomLocationChooser newChooserWithRange:range generator:rand];
float retVal = 0.0;
[[[rand stub] andReturnValue:OCMOCK_VALUE(retVal)] generate];
[ExpectFloat([chooser next]) toBe:0.0 withPrecision:0.0001];
});
Saturday, October 26, 13