-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
118 lines (102 loc) · 3.61 KB
/
main.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Alex Ray
Data Structures
Final Project--deck of cards simulation
*/
#include "DeckOfCards.h"
#include "helper.h"
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
DeckOfCards *deck = new DeckOfCards();
Helper *helper = new Helper();
// Getting user input
int input;
do {
cout << "======Main Menu======" << endl;
cout << "1. Print deck" << endl;
cout << "2. Perfectly shuffle deck" << endl;
cout << "3. Pick random card" << endl;
cout << "4. Choose card from specified position" << endl;
cout << "5. Get specified card from deck" << endl;
cout << "6. Deal cards" << endl;
cout << "7. Return deck to original state" << endl;
cout << "8. Quit" << endl;
cin >> input;
if (input == 1) {
deck->printDeck();
}
else if (input == 2) {
deck->perfectShuffle();
}
else if (input == 3) {
Card *tmp = deck->pickRandomCard();
cout << "You got: " << tmp->name << " of " << tmp->suit << "s!" << endl;
}
else if (input == 4) {
int pos;
string posString;
cin.ignore();
// Input checking
while (true) {
cout << "Please enter the position of the card in the deck (number between 1 and 52)" << endl;
getline(cin, posString);
pos = atoi(posString.c_str()); // String to int
if (pos > 0 && pos < 53 && helper->isInt(posString))
break;
}
Card *tmp = deck->pickCardFromPosition(pos - 1);
cout << "You picked: " << tmp->name << " of " << tmp->suit << "s!" << endl;
}
else if (input == 5) {
string name;
string suit;
cout << "Please enter the name of the card" << endl;
cin.ignore();
getline(cin, name);
name = helper->toLowerCase(name); // making input string lower case
name = helper->alphaToDigit(name); // Changing "one" to "1", etc
cout << "Please enter the suit of the card" << endl;
getline(cin, suit);
suit = helper->toLowerCase(suit);
cout << name << endl;
cout << suit << endl;
Card *tmp = deck->getCard(name, suit);
if (tmp != NULL)
cout << tmp->name << " of " << tmp->suit << "s was found!" << endl;
else
cout << "Card not found!" << endl;
}
else if (input == 6) {
int num;
string numString;
cin.ignore();
// Input checking
while (true) {
cout << "Please enter the number of cards you'd like to deal (number between 1 and 52)" << endl;
cout << "Dealt cards will be pushed to the bottom of the deck" << endl;
getline(cin, numString);
num = atoi(numString.c_str()); // String to int
if (num > 0 && num < 53 && helper->isInt(numString))
break;
}
queue<Card*> q = deck->dealCards(num);
Card *tmp;
int counter = 1;
while (!q.empty()) {
tmp = q.front();
q.pop();
cout << "Card number " << counter << " is " << tmp->name << " of " << tmp->suit << "s" << endl;
counter++;
}
}
else if (input == 7) {
deck->rebuildDeck();
}
else
cout << "Goodbye!" << endl;
}
while (input != 8);
return 0;
}