Last active
October 13, 2015 18:38
-
-
Save tks2shimizu/4239354 to your computer and use it in GitHub Desktop.
card game 25 source code 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloWorldScene.h" | |
#include "SimpleAudioEngine.h" | |
using namespace cocos2d; | |
using namespace CocosDenshion; | |
using namespace std; | |
CCScene* HelloWorld::scene() | |
{ | |
CCScene* scene = CCScene::create(); | |
HelloWorld* layer = HelloWorld::create(); | |
scene->addChild(layer); | |
return scene; | |
} | |
bool HelloWorld::init() | |
{ | |
if (!CCLayer::init()) | |
{ | |
return false; | |
} | |
//変数初期化 | |
srand((unsigned)time(NULL)); | |
//ボタンを作成し配置する | |
makeButtons(); | |
return true; | |
} | |
void HelloWorld::makeButtons() | |
{ | |
//数値配列を初期化する | |
vector<int> numbers; | |
for (int i = 1; i <= 25; i++) | |
numbers.push_back(i); | |
//カードを5x5に配置する | |
for (int x = 0; x < 5; x++) | |
{ | |
for (int y = 0; y < 5; y++) | |
{ | |
//ランダムで1つの値を取得する | |
int index = rand() % numbers.size(); | |
//カードを生成する | |
CCString* fileName = CCString::createWithFormat("frontside%02d.png", numbers[index]); | |
CCSprite* button = CCSprite::create(fileName->getCString()); | |
button->setPosition(ccp((x + 0.5) * 128 + 160, (y + 0.5) * 128)); | |
button->setTag(numbers[index]); | |
this->addChild(button); | |
//数値配列から値を削除する | |
numbers.erase(numbers.begin() + index); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __HELLOWORLD_SCENE_H__ | |
#define __HELLOWORLD_SCENE_H__ | |
#include "cocos2d.h" | |
class HelloWorld : public cocos2d::CCLayer | |
{ | |
private: | |
void makeButtons(); | |
public: | |
virtual bool init(); | |
static cocos2d::CCScene* scene(); | |
CREATE_FUNC(HelloWorld); | |
}; | |
#endif // __HELLOWORLD_SCENE_H__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment