PlayerArea::PlayerArea(const position_type &where) : Rectangle( where, Texture("./resources/playerarea.png") ) { // set playerarea scale this->scale_x(25.f); this->scale_y(10.f); // play deck first, then discard deck, then war deck, so accessors grab the correct child this->add_child(Deck(true, this->position() + position_type(7, 0))); this->add_child(Deck(false, this->position() + position_type(-7, 0))); this->add_child(Deck(false, this->position() + position_type(0, 0))); }
int main(int argc, const char *argv[]) { // generating a deck Deck deck = Deck(); std::cout << "Before shuffling:" << std::endl; deck.print(); // shuffing deck.shuffle(); std::cout << "After shuffling:" << std::endl; deck.print(); // picking up cards from the deck const int pickNum = 5; pickNCards(deck, pickNum); return 0; }
//Default constructor Round::Round() { _board.reserve(5); //Setup vector of cards for board _playerCount = 8; //Define number of players _players.reserve(_playerCount); //Setup vector of players for (int player = 0; player < _playerCount; player++) { //For each player string name = "Player "; stringstream number; number << player + 1; _players[player] = Player(name + number.str()); //Setup name as "Player" and a consecutive number } _deck = Deck(); //Create a deck _deck.shuffle(); //Shuffle the deck };
/********************************************************************** * Purpose: This function is a constructor that builds the areas. * * Entry: This function does not take any arguments. * * Exit: This function does not have a return. * ************************************************************************/ Board::Board() : m_deck(Deck()), m_freecell(FreeCellArea()), m_homecell(HomeCellArea()), m_playarea(PlayArea()) { Populate(); }
int main (int argc, char * const argv[]) { // insert code here...this is the main function, it creates a shuffled deck and begin the story srand(time(NULL)); Deck deck1=Deck(); deck1.shuffle(); char ch='y'; int money=100; int moneyevolve[100]={money}; int moneycount=0; cout << "Welcome to BlackJack!\n"; while ((ch=='y' || ch=='Y') && (money>0)) { Hand gnomehand=Hand(); Hand omehand=Hand(); gnomehand.takeacard(deck1); omehand.takeacard(deck1); gnomehand.takeacard(deck1); omehand.takeacard(deck1); cout << "You have $"<< money; cout << endl; int bet=money+10; while (bet>money) { cout << "Please input your bet as a multiple of 10: \n"; cin >> bet; } money-=bet; cout << "Now you have $"<<money<<endl; omehand.display(1); cout << "Your hand: "; gnomehand.display(2); int gnomesum,black=0; gnomesum=gnomehand.sumup(); if (gnomesum==BLACKJACK) { black=1; } else{ cout << "Double down?y/n?\n"; char d; cin >> d; if (d=='y' || d=='Y') { money-=bet; bet*=2; gnomehand.takeacard(deck1); gnomehand.displaynew(); } else { cout << "hit me? y/n?\n"; char c; cin >> c; while (c=='y' || c=='Y') { gnomehand.takeacard(deck1); gnomehand.displaynew(); if (gnomehand.sumup()>=BLACKJACK) { c='n'; } else {cin >>c;} } } } gnomesum=gnomehand.sumup(); cout << "Your sum is :"<< gnomesum<<endl; if (black==1) { cout << "Congratulations! You have blackjack!\n"; } else if (gnomesum>BLACKJACK) { cout << "Busted! ChouChou!\n"; } cout << "Dealers full hand: "; omehand.display(2); int omesum,omeblack=0; omesum=omehand.sumup(); if (omesum==BLACKJACK) { omeblack=1; } else {while (omesum<=16) { omehand.takeacard(deck1); omehand.displaynew(); omesum=omehand.sumup(); } } cout << "Dealer's sum: "<< omesum<<endl; if (omeblack==1) { cout << "Dealer has blackjack!\n"; } else if (omesum>BLACKJACK) { cout << "Dealer busted!\n"; } if (black==1 && omeblack==1 ) { money+=bet; cout << "Both blackjack! Money back!\n"; } else if (black==1) { money+=bet*5/2; cout << "Awesome! Blackjack money!\n"; } else if (gnomesum<=BLACKJACK && omesum>BLACKJACK) { money+=bet*2; cout << "I win!\n"; } else if (gnomesum<=BLACKJACK && gnomesum>omesum) { money+=bet*2; cout << "I win!\n"; } cout << "Now you have $"<< money<< endl; moneycount++; moneyevolve[moneycount]=money; cout << "Continue?y/n\n"; cin >> ch; deck1.needtoshuffle(); } cout << "Thanks for playing! \n"; for (int i=0; i<=moneycount; i++) { cout << moneyevolve[i]<<" "; } cout << endl; return 0; }
#include "game.h" Deck Game::m_gameDeck=Deck(0);//only one game at a time therefore only one deck, and no jokers in this game //************************************ // 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)
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // Testing code for card drwaing // Deck newDeck = Deck(); Card randomCard = newDeck.popRandomCard(); // Card randomCard5 = newDeck.popRandomCard(); // CardDrawing *cardDraw5 = new CardDrawing(); // QPixmap pix5 = QPixmap(QString::fromStdString(randomCard5.convert())); // cardDraw2->drawWithPixmap(pix5); // ui->player1Layout->addWidget(cardDraw5); Table table = Table(); table.setCapacity(2); table.setTableName("Royal Casino"); table.setPortNo(12000); Player player = Player("Vivek"); player.setUnique_num(1); player.addCardToHand(newDeck.popRandomCard()); player.addCardToHand(newDeck.popRandomCard()); player.addCardToHand(newDeck.popRandomCard()); Player player2 = Player("Dipesh"); player2.setUnique_num(2); player2.addCardToHand(newDeck.popRandomCard()); player2.addCardToHand(newDeck.popRandomCard()); player2.addCardToHand(newDeck.popRandomCard()); Player player3 = Player("Satya"); player3.setUnique_num(3); player3.addCardToHand(newDeck.popRandomCard()); player3.addCardToHand(newDeck.popRandomCard()); player3.addCardToHand(newDeck.popRandomCard()); table.addPlayerToTable(player); table.addPlayerToTable(player2); table.addPlayerToTable(player3); gameDecider(&table); std::vector<Card> * playerHand = player.getCardHand(); for(int itereator = 0; itereator!= playerHand->size(); itereator++){ Card card = playerHand->at(itereator); qDebug()<<card.getValue()<<"\n"; CardDrawing *cardDrawing = new CardDrawing(); QPixmap pixmap = QPixmap(QString::fromStdString(card.convert())); cardDrawing->drawWithPixmap(pixmap); ui->player1Layout->addWidget(cardDrawing); } std::vector<Card> * player2Hand = player2.getCardHand(); for(int itereator = 0; itereator!= player2Hand->size(); itereator++){ Card card = player2Hand->at(itereator); qDebug()<<card.getValue()<<"\n"; CardDrawing *cardDrawing = new CardDrawing(); QPixmap pixmap = QPixmap(QString::fromStdString(card.convert())); cardDrawing->drawWithPixmap(pixmap); ui->player2Layout->addWidget(cardDrawing); } std::vector<Card> * player3Hand = player3.getCardHand(); for(int itereator = 0; itereator!= player3Hand->size(); itereator++){ Card card = player3Hand->at(itereator); qDebug()<<card.getValue()<<"\n"; CardDrawing *cardDrawing = new CardDrawing(); QPixmap pixmap = QPixmap(QString::fromStdString(card.convert())); cardDrawing->drawWithPixmap(pixmap); ui->player3Layout->addWidget(cardDrawing); } // To hide remaining player name // ui->player2Name->hide(); //ui->player3Name->hide(); ui->player4Name->hide(); ui->player5Name->hide(); ui->player1Name->setText(player.getName()); ui->player2Name->setText(player2.getName()); ui->player3Name->setText(player3.getName()); }