zoukankan      html  css  js  c++  java
  • [置顶] ios 水果连连看游戏源码

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

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

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


    demo截屏:



    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


  • 相关阅读:
    Log4Net 自定义级别,分别记录到不同的文件中
    带着忧伤,寻觅快乐
    程序员进阶学习书籍
    PHP编码技巧
    PHP精度问题
    Laravel5 构造器高级查询条件写法
    正则表达式 /i /g /m /ig /gi
    MySQL运算符的优先级
    PHP获取当前页面完整路径URL
    使用ssl模块配置同时支持http和https并存
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3174439.html
Copyright © 2011-2022 走看看