void playBlackJack(struct Player* player, struct Player* dealer) { int i; printFramedText("Game start"); printf("\n"); initPlayer(player, FALSE); initPlayer(dealer, TRUE); shuffleCards(&s_cardDeck); for(i = 0; i < 2; i++) { drawCard(player); } for(i = 0; i < 2; i++) { drawCard(dealer); } showCards(player, dealer); // In case of same card, ask if player splits card. if(canSplitCard(player)){ if(getUserDecision("You have two same number cards. Split card ?")) { printFramedText("Player split card"); printf("\n"); splitCard(player); showCards(player, dealer); } } // Player draw card. while(player->isStand == FALSE) { if(player->isSplit) printf("[Slot %d] ", (int)getCurrentSlotID(player)); if(getUserDecision("Draw one more card ?")) { printFramedText("Player draw card"); printf("\n"); drawCard(player); showCards(player, dealer); } else { struct CardSlot* slot = getCurrentSlot(player); slot->isEndDraw = TRUE; } player->isStand = isStand(player); } // Dealer draw card. while(isStand(dealer) == FALSE) { drawCard(dealer); } dealer->isStand = TRUE; // Show play result. printFramedText("Dealer draw card"); printf("\n"); showCards(player, dealer); printPlayResult(player, dealer); onGameEnd(); }
void ISitableRoom::onGameDidEnd() { for ( uint8_t nIdx = 0 ; nIdx < m_nSeatCnt ; ++nIdx ) { auto pPlayer = m_vSitdownPlayers[nIdx] ; if ( pPlayer == nullptr ) { continue; } if ( pPlayer->isHaveState(eRoomPeer_StayThisRound) && getDelegate() ) { getDelegate()->onUpdatePlayerGameResult(this,pPlayer->getUserUID(),pPlayer->getGameOffset()) ; LOGFMTD("update room peer offset uid = %u, offset = %d",pPlayer->getUserUID(),pPlayer->getGameOffset()); } if ( pPlayer->getNoneActTimes() >= getMaxNoneActTimeForStandUp() || (pPlayer->isDelayStandUp() || pPlayer->getCoin() < coinNeededToSitDown() || (getDelegate() && getDelegate()->isPlayerLoseReachMax(this,pPlayer->getUserUID())) ) ) { playerDoStandUp(pPlayer); pPlayer = nullptr ; m_vSitdownPlayers[nIdx] = nullptr ; } if ( pPlayer ) { pPlayer->onGameEnd() ; } } m_vSortByPeerCardsAsc.clear(); IRoom::onGameDidEnd() ; }
Presenter::Presenter(IView *view) { this->view = view; this->game = new GameController(); QObject* qview = dynamic_cast<QObject*>(view); connect(qview, SIGNAL(onNewGame()), this->game, SLOT(onNewGame())); connect(qview, SIGNAL(onPause()), this->game, SLOT(onPause())); connect(qview, SIGNAL(onRotate()), this->game, SLOT(onRotate())); connect(qview, SIGNAL(onToLeft()), this->game, SLOT(onMoveLeft())); connect(qview, SIGNAL(onToRight()), this->game, SLOT(onMoveRight())); connect(qview, SIGNAL(onSpeedup()), this->game, SLOT(onSpeedup())); connect(qview, SIGNAL(onEndGame()), this->game, SLOT(onEnd())); connect(game, SIGNAL(onStateChanged()), this, SLOT(StateChange())); connect(game, SIGNAL(onGameEnd()), this, SLOT(EndGame())); // instead of speedup connect(qview, SIGNAL(onMakeMove()), this->game, SLOT(onMove())); }
void TaskBullseye::vMain(float dt){ dt = 1000.f/GAME_FPS; if ( _pBullseyeRound == NULL ){ _pBullseyeRound = BullseyeRound::create(_round, &_targets); if ( _pBullseyeRound == NULL ){ _round = 1; _pBullseyeRound = BullseyeRound::create(_round, &_targets); } _arrowRemain = 3; _roundScore[0] = -1.f; _roundScore[1] = -1.f; _roundScore[2] = -1.f; _scoreIdx = 0; } _pBullseyeRound->vMain(dt); { std::list<Arrow*>::iterator it = _arrows.begin(); std::list<Arrow*>::iterator itEnd = _arrows.end(); for ( ; it != itEnd; ){ if ( (*it)->main() ){ float score = (*it)->getScore()*10.f; if ( score < 0.001f ){ --_life; if ( _life == -1 ){ float roundScore = max(0.f, _roundScore[0]) + max(0.f, _roundScore[1]) + max(0.f, _roundScore[2]); _totalScore += roundScore; onGameEnd(); } }else if ( score >= 9.f ){ ++_life; if ( _life > 3 ){ _life = 3; } } _roundScore[_scoreIdx] = score; ++_scoreIdx; delete (*it); it = _arrows.erase(it); itEnd = _arrows.end(); }else{ ++it; } } } { std::list<Target*>::iterator it = _targets.begin(); std::list<Target*>::iterator itEnd = _targets.end(); for ( ; it != itEnd; ){ if ( (*it)->main(dt) ){ delete (*it); it = _targets.erase(it); itEnd = _targets.end(); }else{ std::list<Arrow*>::iterator itAR = _arrows.begin(); std::list<Arrow*>::iterator itAREnd = _arrows.end(); for ( ; itAR != itAREnd; ++itAR ){ if ( !(*itAR)->isDie() ){ (*it)->checkArrow(*itAR); } } ++it; } } } if ( _arrowRemain == 0 && _arrows.empty() ){ if ( _pBullseyeRound && (!_pBtnNext->isShow()) && (!_pBtnRestart->isShow() ) ){ float roundScore = _roundScore[0] + _roundScore[1] + _roundScore[2]; _totalScore += roundScore; if ( _round == ROUND_NUM ){ onGameEnd(); }else{ _pBtnNext->show(true); } } } }