summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: 710d7a253a52b6ab4299cec8ced56db6b7e1ae3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Kamil Kaminski
 * NetID: kkamin8
 *
 * CS340
 * Project 1, Poker Game
 *
 *
 */

#include "game.h"

int main(int argc, char *argv[])
{
    /* seed rand() */
    srand((unsigned int ) time(NULL));

    /* pokerGame instance */
    Game *pokerGame = new Game();
    PRINT_COLOR(ANSI_COLOR_GREEN, "\tWelcome to Poker Game\n\n");

    /* number of opponents user input */
    pokerGame->askForNumberOfOpponents();

    /* pokerGame loop */
    bool quit = false;
    while (!quit)
    {
        cout << "\nThe deck is being shuffled" << endl;
        pokerGame->shufflePile();

#ifdef DEBUG
        cout << "Deck after shuffle" << endl;
        pokerGame->printPile();
#endif

        cout << "\nDealing cards to the user" << endl;
        pokerGame->dealUserCards();
        pokerGame->sortUserCards();
        cout << "Cards in your hand: ";
        pokerGame->printUserCards();

        cout << "Number of same cards: " <<
             pokerGame->numOfSameCards(pokerGame->getUserCards()) << endl;

        if ( pokerGame->pairOrBetter(pokerGame->getUserCards()))
            cout << "User has pair or better" << endl;

        struct countAndSuit userCountAndSuit = pokerGame->numOfSameSuit(pokerGame->getUserCards());
        cout << "Top suit: " << *pokerGame->suits[userCountAndSuit.whatSuit] << ", count: "
             << userCountAndSuit.count << endl;

        cout << "\nDealing cards to opponent(s)" << endl;
        pokerGame->dealOpponentCards(pokerGame->numOfOpponents);
        pokerGame->sortOpponentCards(pokerGame->numOfOpponents);
        cout << "Opponents' cards:" << endl;
        pokerGame->printOpponentCards(pokerGame->numOfOpponents);

#ifdef DEBUG
        cout << "\nDeck after being delt to opponents and user" << endl;
        pokerGame->printPile();
#endif

        /* ask to repeat the game and reset the deck of cards */
        pokerGame->repeatGame(&quit);
        pokerGame->resetDeck();
    }

    cout << "\nThank you for playing\n" << pokerGame->handsPlayed << ": Hands played\n"
         << pokerGame->handsWon << ": Hands won" << endl;

    delete pokerGame;
    PRINT_COLOR(ANSI_COLOR_CYAN, "\tBye!\n");

    return 0;
}