扫雷02 雷区块类的设计
customer_define.h编写
1: #ifndef __CUSTOMER_DEFINE_H__
2: #define __CUSTOMER_DEFINE_H__
3:
4: #include "cocos2d.h"
5: USING_NS_CC;
6: /** scene函数的宏定义,创建一个scene,并addChild这个类型的对象地址(cocos2.2.3遗留的习惯)
7: * define a scene function for a specific type,such as CCLayer
8: * @__TYPE__ class type to add scene(),monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: white"> 9: */
10: #define SCENE_FUNC(__TYPE__) \
11: static cocos2d::CCScene* scene() \
12: { \
13: cocos2d::CCScene* scene = cocos2d::CCScene::create(); \
14: __TYPE__ * sprite = __TYPE__::create(); \
15: scene->addChild(sprite); \
16: return scene; \
17: } \
18:
19:
20: //cocos3.0之后使用cocos2d::log替代了CCLog,但是和数学函数log重名,难得去写cocs2d::
21: #define CCLog cocos2d::log
22: //获取窗口(屏幕)的大小,修改为3.0的用法了,原本是
23: //#define WinSize (cocos2d::CCDirector::sharedDirector()->getWinSize())
24: #define WinSize (cocos2d::Director::getInstance()->getWinSize())
25: //获取窗口的宽度
26: #define WinWidth (cocos2d::Director::getInstance()->getWinSize().width)
27: //获取窗口的高度
28: #define WinHeigth (cocos2d::Director::getInstance()->getWinSize().height)
29:
30: #endif // !__CUSTOMER_DEFINE_H__
修改设计尺寸与窗口尺寸
窗口尺寸仅仅是在windows和Linux下,在手机上就是屏幕大小
设计雷区方格块类
雷区是一个个的小方块,要显示图片,所以直接继承自Sprite了。
为了方便后面的有雷的位置的判断,添加了几个成员变量。
1: class MineBlock :public Sprite
2: {
3: public:
4: MineBlock() { _dig = false; }
5: void setValue(short v) { _value = (short)v; }
6: int getValue() { return (int)_value; }
7: bool getFlag() { return _flag; }
8: void setFlag(bool flag) { _flag = flag; }
9: bool getDig() { return _dig; }
10: void setDig(bool dig) { _dig = dig; }
11: bool callinitWithTexture(Texture2D* t) { return Sprite::initWithTexture(t); }
12: private:
13: short _value; //周围的雷数,之前有char表示,在移植到安卓的时候出错
14: bool _flag; //是否被标记
15: bool _dig; //是否被挖开
16: };