/* Iterates through each player and calls their turn and after_turn methods */ int FiveCardDraw::round(){ if (playersStillInRound.size()>1){ int position = dealerPos + index::one; int numPlayers = playersStillInRound.size(); for (unsigned int i = index::zero; i < playersStillInRound.size(); i++){ if (position >= numPlayers){ position = index::zero; } try { cout << playersStillInRound[position]->name << " is taking a turn" << endl; int num = turn(*playersStillInRound[position]); if (num == index::zero){ after_turn(*playersStillInRound[position]); } else{ return num; } position++; } catch (errorMsg err) { throw err; } } betting(); } return errorMsg::success; }
/* Deals out cards to each person, then calls before_turn method */ int FiveCardDraw::before_round(){ pot = 0; checkForNoChips(); collectAntes(); for (shared_ptr<Player> player : players){ player->foldOrAllIn = false; } playersStillInRound = {}; for (int i = 0; i < players.size(); i++){ playersStillInRound.push_back(players[i]); } betting(); if (playersStillInRound.size()>1){ deck.shuffle(); unsigned int numPlayers = players.size(); int cardsToBeDealed = numPlayers * gameOfPoker::sizeOfHand5; unsigned int position = dealerPos + index::one; for (int i = index::zero; i < cardsToBeDealed; i++){ if (position >= numPlayers){ position = index::zero; } //Adds a card to the player's hand from the deck if (deck.size() > index::zero) { players[position]->hand << deck; } else { throw errorMsg::noCardsLeft; } position++; } cout << "in before round method" << endl; //calls before_turn method for each player for (unsigned int i = index::zero; i < playersStillInRound.size(); i++){ cout << "calling before turn on " << playersStillInRound[i]->name << endl; before_turn(*playersStillInRound[i]); } for (int i = 0; i < playersStillInRound.size(); i++){ cout << "still in round: " << playersStillInRound[i]->name << endl; } } return errorMsg::success; }
void newGame() { game.jackpot = 0; printf("Choose your game mode :\n1 - Chararacter mode\n2 - Symbole mode\n"); game.mode = getIntegerLesserThan(2); clearScreen(); newPlayer(); while(game.player.wantToPlay == 1) { betting(); clearScreen(); if(game.isGodMode == 1) { game.player.profit = getProfitFromResult(0); } else { launchGambling(); game.player.profit = getProfitFromResult(getResult()); } updatePlayerBalance(); printResult(); replay(); } }
void GameScene::onMessage(CCObject* obj) { CCArray* arr = (CCArray*)obj; int typ =((CCInteger*)arr->data->arr[0])->getValue(); string data = string(((CCString*)arr->data->arr[1])->getCString()); if(typ == TYPE_JOIN) { vector<string> elems; stringstream ss(data); string item; while (std::getline(ss, item, '|')) { elems.push_back(item); } ss.flush(); int idx = atoi(elems[0].c_str()); player_info[idx].setPlayerName(elems[1]); player_info[idx].setMoney(atoi(elems[2].c_str())); updatePlayerInfo(); } else if(typ == TYPE_STATUS) { mStatus = atoi(data.c_str()); } else if(typ == TYPE_DRAW_CARD) { vector<string> elems; stringstream ss(data); string item; while (std::getline(ss, item, '|')) { elems.push_back(item); } ss.flush(); if(elems[0] == "t") { for(int i=1; i<elems.size(); i++) common_slot->setCard(i-1, elems[i].c_str()); } else { int idx = atoi(elems[0].c_str()); for(int i=1; i<elems.size(); i++) player_slot[idx]->setCard(i-1, elems[i].c_str()); } } else if(typ == TYPE_MYTURN) { showPopup(atoi(data.c_str())); } else if(typ == TYPE_BETTING) { vector<string> elems; stringstream ss(data); string item; while (std::getline(ss, item, '|')) { elems.push_back(item); } ss.flush(); betting(atoi(elems[0].c_str()), atoi(elems[1].c_str()), atoi(elems[2].c_str())); } }
void play() //Plays game { int p=0; // holds value of player_total int i=1; // counter for asking user to hold or stay (aka game turns) char choice3; cash = cash; cash_test(); printf("\nCash: $%d\n",cash); //Prints amount of cash user has randcard(); //Generates random card player_total = p + l; //Computes player total p = player_total; printf("\nYour Total is %d\n", p); //Prints player total dealer(); //Computes and prints dealer total betting(); //Prompts user to enter bet amount while(i<=21) //While loop used to keep asking user to hit or stay at most twenty-one times // because there is a chance user can generate twenty-one consecutive 1's { if(p==21) //If user total is 21, win { printf("\nUnbelievable! You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(p>21) //If player total is over 21, loss { printf("\nWoah Buddy, You Went WAY over.\n"); loss = loss+1; cash = cash - bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(p<=21) //If player total is less than 21, ask to hit or stay { printf("\n\nWould You Like to Hit or Stay?"); scanf("%c", &choice3); while((choice3!='H') && (choice3!='h') && (choice3!='S') && (choice3!='s')) // If invalid choice entered { printf("\n"); printf("Please Enter H to Hit or S to Stay.\n"); scanf("%c",&choice3); } if((choice3=='H') || (choice3=='h')) // If Hit, continues { randcard(); player_total = p + l; p = player_total; printf("\nYour Total is %d\n", p); dealer(); if(dealer_total==21) //Is dealer total is 21, loss { printf("\nDealer Has the Better Hand. You Lose.\n"); loss = loss+1; cash = cash - bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(dealer_total>21) //If dealer total is over 21, win { printf("\nDealer Has Went Over!. You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } } if((choice3=='S') || (choice3=='s')) // If Stay, does not continue { printf("\nYou Have Chosen to Stay at %d. Wise Decision!\n", player_total); stay(); } } i++; //While player total and dealer total are less than 21, re-do while loop } // End While Loop } // End Function