void showSnake2(void) { updateSnakesTimer = blinkAppleTimer = -1; snake[0].score == snake[1].score == 0; newRound(); }
void BlackJack::newDeal() { player.clearHand(); dealer.clearHand(); hideCard = true; if(!player.getBalance()) { cout << "Sorry you are out of funds. Game Over.\n"; exitGame(); } cout << " *********************************\n" << " * d key = deal | q key = quit *\n" << " *********************************\n" << " Enter: "; char input; cin >> input; while(tolower(input) != 'd' && tolower(input) != 'q') { cout << "Enter a valid option: \n" << "Enter: "; cin >> input; } if(tolower(input) == 'd') { ClearScreen(); control = true; // Run menu() again. newRound(); } else { exitGame(); } }
static void gameOver(byte s) { endRound(); matrix.setLed(0, apple.y, apple.x, true); // In case the apple is off at that time strcpy_P(buffer, (char *) pgm_read_word(&(strings[GAME_OVER]))); printLcd(3, 0, buffer); switch (s) { case 0: strcpy_P(buffer2, (char *) pgm_read_word(&(strings[PLAYER_WIN]))); printLcd(0, 1, buffer2); printLcd(7, 1, "2"); snake[1].score++; break; case 1: strcpy_P(buffer2, (char *) pgm_read_word(&(strings[PLAYER_WIN]))); printLcd(0, 1, buffer2); printLcd(7, 1, "1"); snake[0].score++; break; case 2: strcpy_P(buffer2, (char *) pgm_read_word(&(strings[TIE]))); printLcd(4, 1, buffer2); } wipeMatrix(); delay(500); newRound(); }
static void gameOver(void) { endRound(); matrix.setLed(0, apple.y, apple.x, true); // In case the apple is off at that time strcpy_P(buffer, (char *) pgm_read_word(&(strings[GAME_OVER]))); printLcd(3, 1, buffer); wipeMatrix(); delay(500); newRound(); }
void Model::newGame(const int randomValue) { finished = false; for (int i = 0; i < 4; i++) { players_[i]->wipeScore(); } srand48(randomValue); newRound(); }
//************************************ // Method: play - main function for game handles entire game play until user exits // FullName: Game::play // Access: public // Returns: void // Qualifier: //************************************ void Game::play() { char userInput='c'; while (!m_endGame && userInput=='c')//user asks to continue playing and game isnt over { //set current players order to reflect on UI UIs::UI::setPlayers(getPlayerAt(0),getPlayerAt(1),getPlayerAt(2),getPlayerAt(3)); newRound();//play a game round if (m_endGame) { UIs::UI::displayMessage("Game over!! enter e to exit or n for new game"); } else { UIs::UI::displayMessage("enter e to exit,c to continue or n for new game"); } userInput=UIs::UI::getUserGameInput(); while((userInput=='c'&& m_endGame )||(userInput!='e' && userInput!='c' && userInput!='n'))//input isn't valid { UIs::UI::clearInputLine(); if (m_endGame) { UIs::UI::displayErrorMessage("ERROR:the input you entered is invalid: use n or e only!"); } else { UIs::UI::displayErrorMessage("ERROR:the input you entered is invalid: use c n or e only!"); } userInput=UIs::UI::getUserGameInput(); } UIs::UI::clearConsole(); if (userInput=='n')//new game { UIs::UI::plotGoodbyeScreen(m_numberOfRounds,returnNameOfWinningPlayer());//summery destroyGame(); //Clear game settings initGame(); //initialize new game from user decisions play(); //Start anew } else if (userInput =='e')//exit { UIs::UI::plotGoodbyeScreen(m_numberOfRounds,returnNameOfWinningPlayer()); m_endGame=true;//ask to end game } else // must be c { UIs::UI::setPlayers(getPlayerAt(0),getPlayerAt(1),getPlayerAt(2),getPlayerAt(3));//new order- winner starts } }//end main while }
void GameInstanceServer::connectLocallyTo(MessagePeer* buddy, bool recursive /*= true*/) { if (true) //if ( ! gameinfo->getGameRunning() ) { // we have got a new client! Create a SpaceShip just for him GameMessagePeer::connectLocallyTo(buddy, recursive); // Dispatch to server thread, if necessary(see docs on difference between // io_service::dispatch() and io_service::post() m_eventService.dispatch([this, buddy]() { SpaceShipServer::pointer hisShip{ new SpaceShipServer(buddy->name(), osg::Vec3f(), osg::Quat(0, osg::Vec3f(1, 0, 0)), RemotePeersManager::getManager()->getPeersId(buddy), this, m_physicsEngine) }; //GameMessage::pointer constructItMsg = m_asteroidField->creationMessage(); //buddy->send(constructItMsg); GameMessage::pointer constructItMsg; for (std::pair<MessagePeer*, SpaceShipServer::pointer> aShip : m_peerSpaceShips) { constructItMsg = aShip.second->creationMessage(); buddy->send(constructItMsg); } broadcastLocally(hisShip->creationMessage()); m_peerSpaceShips.insert(std::make_pair(buddy, hisShip)); GameMessage::pointer constructGameInfoMsg = m_gameInfo->creationMessage(); buddy->send(constructGameInfoMsg); GameMessage::pointer constructPlanetSystem = m_planetSystem->creationMessage(); buddy->send(constructPlanetSystem); if (true) //if all players clicked "im ready" { m_gameInfo->setGameRunning(true); m_currentRound = 0; newRound(); } }); } else { //deny connection } }
void Launcher::launchGame1() { m_parent->hide(); Opts o("./config/options.txt"); int nbIa = o.getNbIa(); int lvl = o.getLevelIa(); const int nbPlayer = 1; int gameStatus = 0; std::vector<int> scores(nbIa + nbPlayer, 0); size_t i = 0; //_initLaunchGame(); while ((gameStatus = newRound(scores, nbIa, lvl, nbPlayer)) >= 0); while (i < scores.size() && scores[i] != SCORE_TO_WIN) i += 1; if (i < scores.size()) std::cout << "Winner is player " << i + 1 << std::endl; m_parent->show(); }
void Model::nextPlayer(int index) { cardsPlayed++; if (cardsPlayed == 52) { for (int i = 0; i < 4; i++) { int scores = players_[i]->increaseScore(); if (scores >= 80) finished = true; } if (finished) { int winner = 0; int minScore = players_[0]->getOldScore(); for (int i = 1; i < 4; i++) { if (players_[i]->getOldScore() < minScore) minScore = players_[i]->getOldScore(); } for (int i = 3; i >= 0; i--) { if (players_[i]->getOldScore() == minScore) winner = winner*10+(i+1); } notifyEndGame(winner, minScore); } else { notifyEndOfRound(); newRound(); } } else { if (currentPlayer == 3) currentPlayer = 0; else currentPlayer++; processCurrentPlayer(); notifyCardPlayed(index); } }
void GameInstanceServer::checkForEndround() { if (m_gameInfo->getGameRunning()) { m_eventService.dispatch([this]() { // Dispatch to the server thread for (std::map<MessagePeer*, SpaceShipServer::pointer>::iterator peerSpaceShip = m_peerSpaceShips.begin(); peerSpaceShip != m_peerSpaceShips.end(); ++peerSpaceShip) { unsigned int physId = peerSpaceShip->second->getPhysicsId(); osg::Vec3f pos = m_physicsEngine->getShipPosition(physId); if (m_gameInfo->shipInFinishArea(pos)) { peerSpaceShip->second->incrementPlayerScore(); //broadcasts update automatically GameMessage::pointer msg = m_gameInfo->objectiveMessage(); m_currentRound >= m_gameLength ? endGame() : newRound(); break; } } }); } }
BlackJack::BlackJack() : hideCard(true) , control(true) { newRound(); }
void kpok::drawClick() { if (!drawButton->isEnabled()) return; // If this is the start of a new round, then deal new cards. if (m_game.getState() == StateStartRound) { drawButton->setEnabled(false); betBox->setEnabled(false); newRound(); } else if (m_game.getState() == StateBet1) { // bet emit showClickToHold(false); bet(); if (m_game.getState() == StateExchangeCards) {// should be set in bet() drawClick(); } } else if (m_game.getState() == StateRaise1) { // continue bet bet(); if (m_game.getState() == StateExchangeCards) {// should be set in bet() drawClick(); } } else if (m_game.getState() == StateExchangeCards) { // exchange cards drawButton->setEnabled(false); playerBox[0]->setHeldEnabled(false); betBox->setEnabled(false); bool skip[PokerHandSize]; for (int i = 0; i < PokerHandSize; i++) skip[i] = false; for (int i = 0; i < m_game.getNumActivePlayers(); i++) { if (!m_game.getActivePlayer(i)->getHuman()) m_game.getActivePlayer(i)->exchangeCards(skip); else { for (int i = 0; i < PokerHandSize; i++) { skip[i] = playerBox[0]->getHeld(i); if (!skip[i]) playerBox[0]->paintDeck(i); } } drawCards(m_game.getActivePlayer(i), skip); } if (playerBox[0]->getHeld(0)) drawTimer->start(0, TRUE); else drawTimer->start(drawDelay, TRUE); } else if (m_game.getState() == StateBet2) { // raise setBetButtonEnabled(false); bet(); if (m_game.getState() == StateSee)//should be set in bet()->if no one has raised drawClick(); } else if (m_game.getState() == StateRaise2) { bet(); if (m_game.getState() == StateSee) drawClick(); } else if (m_game.getState() == StateSee) winner(); }
void showSnake(void) { updateSnakeTimer = blinkAppleTimer = -1; newRound(); }