float CDeck::InitEmptyCells(float delayPerLetter) { float currentDelay = 0.0f; for (int i=0; i<m_Letters.size(); i++) { if (m_Letters[i] == NULL) { CStack * stack = CGameScene::Instance()->GetCurrentRoom()->GetStack(); if(stack->IsEmpty()) { return currentDelay; } CLetter * letter = stack->GetLetterFromStack(); addChild(letter,CLetter::STAY_LAYER); float scale = 0.45; Point pos = Point(CELL_OFFSET_X+(CELL_SIZE_X/2),CELL_OFFSET_Y+(CELL_SIZE_Y/2)); letter->setPosition(pos.x + i*CELL_SIZE_X,pos.y); letter->SetDeckCell(i); letter->SetLastPosType(CLetter::LPT_DECK); m_Letters[i] = letter; currentDelay += delayPerLetter; letter->ShowAction(currentDelay); } } return currentDelay; }
void CDeck::InitEmptyCells() { for (int i=0; i<m_Letters.size(); i++) { if (m_Letters[i] == NULL) { CStack * stack = CGameScene::Instance()->GetCurrentRoom()->GetStack(); if(stack->IsEmpty()) { return; } CLetter * letter = stack->GetLetterFromStack(); //CGameScene::Instance()->addChild(letter); addChild(letter,CLetter::STAY_LAYER); float scale = 0.45; Point pos = Point(CELL_OFFSET_X+(CELL_SIZE_X/2),CELL_OFFSET_Y+(CELL_SIZE_Y/2)); letter->setPosition(pos.x + i*CELL_SIZE_X,pos.y); //letter->setOpacity(0); //letter->setScale(0.2f); letter->SetDeckCell(i); letter->SetLastPosType(CLetter::LPT_DECK); m_Letters[i] = letter; //letter->ShowAction(); /* auto scaleAction = CCScaleTo::create(0.5f,scale,scale); auto showAction = CCFadeIn::create(0.3f); auto spawn = Spawn::create(scaleAction,NULL); letter->runAction(spawn);*/ } } ShowLetters(); }
int _tmain(int argc, _TCHAR* argv[]) { CStack st; int list[5]={1,2,3,4,5}; for(int i=0;i<5;i++) { st.Push(list[i]); } for(int i=0;i<5;i++) { cout <<st.Pop()<<endl; } for(int i=0;i<5;i++) { st.Push(list[i]); } st.Clear(); if(st.IsEmpty()) cout<<"stack is empty!"; return 0; }
/* 利用栈求解数制转换问题,这里求解10进制数p的d进制数。*/ string Conversion(int p, int d) { CStack<int> csiMem; int iN = p; while( iN ) { csiMem.Push( iN % d); iN /= d; } string sRes; while( !csiMem.IsEmpty() ) { int iCur = csiMem.Pop(); char c = ' '; if( iCur >= 10) c = 'A'+iCur-10; if( c == ' ') { char cNum[5] = ""; sprintf( cNum, "%d", iCur ); sRes += cNum; } else sRes += c; } return sRes; }