[置顶] ios 水果连连看游戏源码

原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917

demo功能:水果连连看游戏源码。iphone6.1 测试通过。功能是清除屏幕上的所有的水果,并尝试每个关卡上获得更高的分数。包括“开始游戏”,“继续游戏”,“游戏中暂停”等功能。

demo说明:基于cocos2d 写的水果连连看游戏源码。cocos2d介绍

demo截屏:

[置顶] ios 水果连连看游戏源码

[置顶] ios 水果连连看游戏源码

demo主要代码:   主游戏窗口view

#import "PlayLayer.h"

extern CCLabel * ccLP(NSString * value, float fontSize, CGPoint pos);
@interface PlayLayer ()
-(void) initBallsSprite;
-(void) initNumberLabel;
-(void) initMenu;
-(void) showStartHint;
-(void) startHintCallback: (id) sender;
-(void) goNextLevel;
@end @implementation PlayLayer #pragma mark init part
-(id) init {
if( (self=[super init] )) {
game = [[Game alloc] init];
chart = [[Chart alloc] initWith: [game level]]; Skill *bombSkill = [[Bomb alloc] initWithChart:chart linkDelegate:self];
Skill *suffleSkill = [[Suffle alloc] initWithChart:chart linkDelegate:self]; game.bombSkill = bombSkill;
game.suffleSkill = suffleSkill; [game setState: GameStatePrepare];
startHintIndex = 0;
startHintArray = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"Level %d",[game.level no]],@"Ready",@"Go",nil];
[startHintArray retain]; self.isTouchEnabled = NO;
[self initBallsSprite];
[self initNumberLabel];
[self initMenu];
} return self;
} -(void) initBallsSprite{
for (int y=0; y<kRowCount; y++) {
for (int x=0; x<kColumnCount; x++) {
Tile *tile = [chart get: ccp(x,y)];
int posX = (x-1)*kTileSize + kLeftPadding + kTileSize/2;
int posY = (y-1)*kTileSize + kTopPadding + kTileSize/2; if (tile.kind < 0) {
continue;
} NSString *imageName = [NSString stringWithFormat: @"q%d.png", tile.kind];
tile.sprite = [CCSprite spriteWithFile:imageName];
tile.sprite.scaleX = kDefaultScaleX;
tile.sprite.scaleY = kDefaultScaleY;
tile.sprite.position = ccp(posX, posY);
[self addChild: tile.sprite z: 3];
}
}
} -(void) initNumberLabel{
{
CCLabel *scoreValueLabel = ccLP(@"0", 28.0f, ccp(50,225));
[self addChild: scoreValueLabel z:1 tag:kScoreLabelTag];
} {
int time = [game.level timeLimit];
NSString *timeValueString = [NSString stringWithFormat: @"%d", time];
CCLabel *timeValueLabel = ccLP(timeValueString, 28.0f, ccp(50,275));
[self addChild: timeValueLabel z:1 tag:kTimeLabelTag];
} { CCLabel *timeLabel = ccLP(@"time", 28.0f, ccp(50,300));
[self addChild:timeLabel];
} {
CCLabel *scoreLabel = ccLP(@"score", 28.0f, ccp(50,250));
[self addChild:scoreLabel];
} } -(void) initMenu{
CCMenuItemFont *bombItem = [CCMenuItemFont itemFromString:@"Bomb" target:game.bombSkill selector: @selector(run:)];
CCMenuItemFont *suffleItem = [CCMenuItemFont itemFromString:@"Suffle" target:game.suffleSkill selector: @selector(run:)];
CCMenuItemFont *stopItem = [CCMenuItemFont itemFromString:@"Pause" target:self selector: @selector(goPause:)]; game.bombSkill.assItem = bombItem;
game.suffleSkill.assItem = suffleItem; CCMenu *menu = [CCMenu menuWithItems:bombItem, suffleItem, stopItem, nil];
[menu alignItemsVerticallyWithPadding: -1];
menu.position = ccp(-100,65);
[self addChild:menu z: 2 tag: kMenuTag];
} -(void) goPause: (id) sender{
[SceneManager goPause];
}


demo下载地址:http://download.csdn.net/detail/donny_zhang/5706237

上一篇:2.9 while循环


下一篇:护肤品总结 Skin Care (1)