void Board2048::runGame(){ srand(time(0)); try { /* check board */ if(board.size()==0){ throw exception(); } /* rand a key to put on the board */ randKey(2); /* Show the initial board */ assert(getKeyNum()==2); showBoard('N'); while(1){ /* get input char */ getInput(); if(b_quit == 'q') break; else if(b_quit=='n'){ b_quit = ' '; continue; } moveBoard(); randKey(1); showBoard('N'); checkOver(); if(b_quit == 'q') break; } cout<<endl; }catch(exception e){ cout<<"Board was NOT initialized"<<endl; } }
bool GameController::init() { ////////////////////////////// // 1. super init first if ( !Node::init() ) { return false; } bool_first_touch = true; //screen variables visibleSize = Director::getInstance()->getVisibleSize(); origin = Director::getInstance()->getVisibleOrigin(); //catching touch auto eventListener = EventListenerTouchOneByOne::create(); eventListener->onTouchBegan = CC_CALLBACK_2(GameController::onTouchBegan, this); eventListener->onTouchMoved = CC_CALLBACK_2(GameController::onTouchMoved, this); eventListener->onTouchEnded = CC_CALLBACK_2(GameController::onTouchEnded, this); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this); auto physicsContactListener = EventListenerPhysicsContact::create(); physicsContactListener->onContactBegin = CC_CALLBACK_1(GameController::onContactBegin, this); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(physicsContactListener, this); //designing background loadAssets(); //moving board moveBoard(); return true; }