-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardsDriver.cpp
More file actions
70 lines (51 loc) · 1.76 KB
/
CardsDriver.cpp
File metadata and controls
70 lines (51 loc) · 1.76 KB
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
#include "Cards.h"
#include "Player.h"
#include "Orders.h"
int main() {
// Constants to store deck/hand size
const int DECK_SIZE = 17;
const int HAND_SIZE = 2;
// Create player and deck objects
Player myPlayer;
Deck myDeck;
// Initialize vectors
Hand hand;
myPlayer.myHand = &hand;
OrdersList ord;
myPlayer.myOrders = ⩝
// Fills deck according to size (will round to nearest multiple of 5)
myDeck.fillDeck(DECK_SIZE);
// Outputs cards in deck (not shuffled)
cout << myDeck << "\n" << endl;
// Draws cards from deck into player hand
for (int i = 0; i < HAND_SIZE; i++)
myPlayer.myHand->handCards.push_back(myDeck.draw());
// Outputs player hand
cout << myPlayer.myHand << "\n" << endl;
// Track used in loops
int index = -1;
int size = myPlayer.myHand->handCards.size();
for (int i = 0; i < size; i++) {
size = myPlayer.myHand->handCards.size();
// Validate input
while (index < 0 || index > size) {
cout << setw(15) << "--- Please choose which card you wish to play --- \n";
cout << myPlayer.myHand;
cout << "Press 0 to cancel action \n" << endl;
cout << "What card (index) do you wish to play? : ";
cin >> index;
}
// Play card if choice successful
if (index != 0) {
myPlayer.myHand->handCards[index - 1]->play(&myPlayer, &myDeck);
}
else
cout << "Play action has been cancelled! \n" << endl;
index = -1; // Reset variable
}
// Outputs cards in deck (is shuffled)
cout << myDeck << "\n" << endl;
// Outputs player hand (empty)
cout << myPlayer.myHand << "\n" << endl;
return 0;
}