//检测游戏是否结束 void GameScene :: doCheck() { bool isGameOver = true ; //判断每一个的上下左右和自己是否相同 for ( int y = 0 ; y < 4; y++) { for ( int x = 0 ; x < 4; x++) { if ( cardArr [x ][ y]-> getNumber () == 0 || ( x< 3 && cardArr[ x ][y ]-> getNumber() == cardArr [x + 1][ y ]->getNumber ()) || ( x> 0 && cardArr[ x ][y ]-> getNumber() == cardArr [x - 1][ y ]->getNumber ()) || ( y< 3 && cardArr[ x ][y ]-> getNumber() == cardArr [x ][ y+ 1 ]->getNumber ()) || ( y> 0 && cardArr[ x ][y ]-> getNumber() == cardArr [x ][ y- 1 ]->getNumber ()) ) { isGameOver = false; } } } if ( isGameOver ) { //重来 Director ::getInstance ()-> replaceScene( TransitionFade ::create ( 1, GameScene ::createScene ())); } }
//分数 int score ; //显示分数控件 LabelTTF * cardNumberTTF ; //设置分数 void setScore ( int score );
//设置分数 void GameScene :: setScore( int score ) { cardNumberTTF ->setString ( __String:: createWithFormat ("%i" , score)-> getCString ()); }
score = 0; cardNumberTTF = LabelTTF:: create ("0" , "Consolas" , 70 ); cardNumberTTF ->setPosition ( Point( visibleSize .width / 2 + 340 , visibleSize .height / 2 - 100 )); addChild (cardNumberTTF );
//改变分数 score += cardArr[ x ][y ]-> getNumber();
【来写个2048吧】—— 游戏结束检测与添加分数,布布扣,bubuko.com
原文地址:http://blog.csdn.net/wxk_bigworld/article/details/25206229