Skip to content

Commit

Permalink
no bug but stupid
Browse files Browse the repository at this point in the history
  • Loading branch information
D-W- committed Aug 6, 2014
1 parent 0320087 commit 5a5c054
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 29 deletions.
30 changes: 15 additions & 15 deletions About.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ USING_NS_CC;

Scene* GameAbout::createScene()
{
auto scene = Scene::create();
auto layer = GameAbout::create();
scene->addChild(layer);
return scene;
auto scene = Scene::create();
auto layer = GameAbout::create();
scene->addChild(layer);
return scene;
}


bool GameAbout::init()
{

if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
//背景
auto sprite = Sprite::create("about/aboutui.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite);
auto sprite = Sprite::create("about/aboutui.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite);

//响应键盘消息
auto keyListener = EventListenerKeyboard::create();
Expand All @@ -36,7 +36,7 @@ bool GameAbout::init()
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(GameAbout::onTouchBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
return true;
}

//返回主界面
Expand Down
63 changes: 49 additions & 14 deletions GameLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ GameLayer::GameLayer()
m_height(0),
m_isTouchEnable(true),
m_raindrop(NULL),
m_markSize(0)
m_markSize(0),
m_isTrapped(false)
{

}
Expand Down Expand Up @@ -197,13 +198,14 @@ void GameLayer::initCloud()
//移动雨滴
void GameLayer::moveRaindrop()
{
SquareSprite* next;
SquareSprite* next = NULL;
int row = m_raindrop->getRow();
int col = m_raindrop->getCol();
int bestWay = 81;
int odd = row%2;
for(int i = 0;i<6;++i)
for(int i = 0;i<6;++i)//分别向可以走的六个方向调用寻路的递归函数
{
//每次调用都重新初始化标记数组
memset((void*)m_mark,false,m_markSize);
int next_row = row + choices[odd][i][0];
int next_col = col + choices[odd][i][1];
Expand All @@ -223,39 +225,72 @@ void GameLayer::moveRaindrop()
next = next_sprite;
}
}
else//雨滴成功逃脱了
{
//更换到endlayer
//CCDirector::sharedDirector()->replaceScene(EndLayer::createScene());
//Director::getInstance()->end();
m_isTrapped = true;
}
}
}
if(bestWay == 81)//如果雨滴被围住了,随便找一个方向走
{
for(int i = 0;i<6;++i)
{
int next_row = row + choices[odd][i][0];
int next_col = col + choices[odd][i][1];
SquareSprite* next_sprite = m_matrix[next_row*MATRIX_WIDTH + next_col];
if(!next_sprite->getSelected())//可以走就走
{
next = next_sprite;
}
}
}
m_raindrop->runAction(MoveTo::create(0.3, next->getPosition()));
m_raindrop->setCol(next->getCol());
m_raindrop->setRow(next->getRow());
if(next)
{
m_raindrop->runAction(MoveTo::create(0.3, next->getPosition()));
m_raindrop->setCol(next->getCol());
m_raindrop->setRow(next->getRow());
}
else{//雨滴被围住了
//更换到endlayer
Director::getInstance()->end();
//CCDirector::sharedDirector()->replaceScene(EndLayer::createScene());
}
if(m_isTrapped){
Director::getInstance()->end();
}
}
//雨滴的逃生路线
//雨滴的逃生路线,result代表最短路径的长度,用于筛选最短路径,返回值也是result
//返回值 -1代表雨滴成功逃脱了,进入结束页面
// 81代表雨滴被围住了。。
int GameLayer::findWay(int row,int col,int result)
{
m_mark[row*m_width+col] = true;
int odd = row%2;
int best_way = 81;
if(col <= 0 || col >= 8 || row <= 0 || row >= 8){ //走到终点
if(col <= 0 || col >= 8 || row <= 0 || row >= 8){//走到终点
if(result == 1){
return -1;//雨滴已经走到了终点
}
return result;
}
for(int i = 0;i<6;++i)
{
int next_row = row + choices[odd][i][0];
int next_col = col + choices[odd][i][1];
SquareSprite* next_sprite = m_matrix[next_row*MATRIX_WIDTH + next_col];
if(next_sprite->getSelected() || m_mark[next_row*m_width+next_col])//已经变成云了
if(next_sprite->getSelected() || m_mark[next_row*m_width+next_col])//已经变成云了或该点走过了
{
continue;
}
else
{
int res = findWay(next_row,next_col,result+1);
if(res != -1)
if(res < best_way)
{
if(res < best_way)
{
best_way = res;
}
best_way = res;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions GameLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GameLayer : public Layer
bool m_isTouchEnable;
Raindrop* m_raindrop;
int m_markSize;
bool m_isTrapped;

Point positionOfItem(int row, int col);
int findWay(int row,int col,int result);
Expand Down

0 comments on commit 5a5c054

Please sign in to comment.