forked from Mordequess/CS247_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuman.cpp
84 lines (73 loc) · 2.13 KB
/
Human.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
#include "Human.h"
#include <vector>
#include "Command.h"
Human::Human(int playernum, Played* played) : Player(playernum, played) {
}
void Human::print() {
std::cout << played_ << std::endl;
std::vector<Card*> currHand = getHand();
std::cout << "Your hand:";
for (int i = 0; i < currHand.size() ; i++) {
std::cout << " " << *currHand[i];
}
std::cout << "\n";
std::cout << "Legal plays:";
for (int i = 0; i < currHand.size() ; i++) {
if (isLegal(currHand[i])) {
std::cout << " " << *currHand[i];
}
}
std::cout << "\n";
}
void Human::playTurn(bool printinfo) {
if (printinfo) {
print();
}
Command command;
std::cin >> command;
switch (command.type) {
//play a card
case PLAY: {
if (!(inHand(&command.card)) || !(isLegal(&command.card))) {
throw "This is not a legal play.";
}
else {
std::vector<Card*> hand = getHand();
std::cout << "Player " << plnumber_ << " plays " << command.card << "." << std::endl;
playCard(&command.card);
hand.erase(std::remove(hand.begin(), hand.end(), &command.card), hand.end());
//std::vector<Card*>::iterator position = find(hand.begin(), hand.end(), command.card);
//hand.erase(position);
}
break;
}
//discard a card
case DISCARD: {
if (legalPlays(getHand()).size() != 0) {
throw "You have a legal play. You may not discard.";
}
else {
std::cout << "Player " << plnumber_ << " discards " << command.card << "." << std::endl;
discardCard(&command.card);
}
break;
}
//print the deck
case DECK: {
throw "print deck";
break;
}
//exit program
case QUIT: {
throw "quit";
break;
}
//replace current human player with a computer
case RAGEQUIT: {
throw "rage quit";
break;
}
default:
break;
} // switch
}