初学者cocos2dx 写2048 为了和大家一起分享
第一个是在头文件
部分的代码是学习不变 大多数写自己。
class HelloWorld : public cocos2d::CCLayer
{
public: virtual bool init();
static cocos2d::CCScene* scene();
void menuCloseCallback(CCObject* pSender);
CREATE_FUNC(HelloWorld); //以上为自己主动生成的代码
bool doUp(); //实现上下左右移动功能
bool doDown();
bool doLeft();
bool doRight();
void createCardSprite(cocos2d::CCSize size); //创建出一个4*4的精灵矩阵
void HelloWorld:: Random_createCardSprite(); //随机生成数字 随机位置生成 bool HelloWorld:: FullScreen(); //推断是否全屏充满了数字 而且不能移动
bool HelloWorld:: GameOver();// 游戏结束
void random_num(int x,int y);// 随机生成2跟4 void Random_createCardSprite_easy(int flag); // 设置这个函数的目的本来是想设置游戏难度 因为并未实现选难度的功能 所以 这个函数仅仅有仅仅有调用 Random_createCardSprite(int flag);的功能
void HelloWorld:: Random_createCardSprite(int flag); //随机生成数字 有规律的生成 向上移动则在以下生成 private:int firstX,firstY,endX,endY; //触摸点的坐标 CardSprite *CardNum[4][4]; //创建 数字精力的数组对象 4*4};
class CardSprite: public cocos2d::CCSprite
{
public:
virtual bool init();
static CardSprite* createCardSprite(int numbers,int width,int height,float CardSpriteX,float CardSpriteY);
CREATE_FUNC(CardSprite);
int GetNumber();//取得这个精灵所代表的数字 void SetNumber(int NewNumbers); //改动这个精灵所代表的数字
void change_num_view(); //改变数字的外观 依据 数字大小转换颜色
private:
int number; //这个精灵所代表的数字
void NumberInit(int numbers,int width,int height,float X,float Y); //初始化“数字” //定义显示数字的控件
cocos2d::CCLabelTTF *labelTTFCardNumber; //显示背景
cocos2d::CCLayerColor *layerColorBG;
};版权声明:本文博主原创文章,博客,未经同意不得转载。
初学者cocos2dx 写2048 为了和大家一起分享的更多相关文章
- 用C挑战无准备写2048
下午在刷题过程中,忽然想写2048了,以弥补以前写的那个千多行的,所以简单思考了一下准备采取的数据结构就开始了,本以为一个小时能搞定,结果后面改bug还是多花了些时间.因为在医院,所以声音不敢太大,如 ...
- 一起来写2048(160行python代码)
前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家,而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...
- 一起写2048(160行python代码)
前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家.而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...
- js280行代码写2048
2048 原作者就是用Js写的,一直想尝试.但久久未动手. 昨天教学生学习JS代码.最好还是就做个有趣的游戏好了.2048这么火,是一个不错的选择. 思路: 1. 数组 ,2维数组4x4 2. 移动算 ...
- python写2048小游戏
#!/usr/bin/env python # coding=utf-8 #******************************************************** # > ...
- object-c cocos2d-x 写程序时注意调试的技巧
(1)写程序时最好在类的init函数中显示类名,表明现在在执行哪个类,样例代码 CCLOG(@"cocos2d: Using Director Type:%@", [self cl ...
- R语言写2048游戏
2048 是一款益智游戏,只需要用方向键让两两相同的数字碰撞就会诞生一个翻倍的数字,初始数字由 2 或者 4 构成,直到游戏界面全部被填满,游戏结束. 编程时并未查看原作者代码,不喜勿喷. 程序结构如 ...
- js写2048游戏代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 小游戏:200行python代码手写2048
#-*- coding: utf-8 -*- import curses from random import randrange, choice from collections import de ...
随机推荐
- curl的封装
首先要搭建一个httpserver,这里採用tomcat6为例: 过程:新建一个Servlet,并使用tomcat的默认port号8080监听,最后写一个jsp来測试能否够訪问该server 1)新建 ...
- k-d tree算法
k-d树(k-dimensional树的简称),是一种分割k维数据空间的数据结构.主要应用于多维空间关键数据的搜索(如:范围搜索和最近邻搜索). 应用背景 SIFT算法中做特征点匹配的时候就会利用到k ...
- 解决方式:QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
在用QSqlDatabase时遇到报错QSqlDatabase: an instance of QCoreApplication is required for loading driver plug ...
- 使用OGG"Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程
使用OGG的 "Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程 因此.最好是在vncserver中调用该 ...
- VS调试技巧之附加进程
用过VS一段时间的程序猿们相信都有过这种调试经历:每次按下F5进行断点调试时,都要等待好长时间:先让解决方式编译通过,然后启动VS自带的简版IIS作为server启动,进而开启浏览器,最后进行对应的操 ...
- 【android】在Eclipse在联想引jar包源代码
(前提是你有jar包源代码!!) .确保Referenced LIbraies下已经有该jar包,否则的话,右击该jar包选build path->add to build path. 二.右键 ...
- wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are
安装node错: wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development pac ...
- twitter 监测登陆活动
http://vicenteaguileradiaz.com/download/tinfoleak/tinfoleak-1.2.tar.gz
- php-GD库函数(三)
<?php //imagefilledellipse — 画一椭圆并填充 /*bool imagefilledellipse ( resource $image , int $cx , int ...
- NodeJS - Express4.0错误:Cannot read property &#39;Store&#39; of undefined
Express在使用mongodb的时候app配置出错 //settings.js module.exports={ cookieSecret:"xxxx", db:"d ...