-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrategyHuman.cpp
More file actions
68 lines (62 loc) · 1.93 KB
/
StrategyHuman.cpp
File metadata and controls
68 lines (62 loc) · 1.93 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
#include "StrategyHuman.h"
#include <iostream>
//public constructor
StrategyHuman::StrategyHuman (Player* p)
: Strategy(p) {
}
//implementation of virtual method takeTurn. Player takes his turn and plays it.
Command StrategyHuman::takeTurn ( std::vector<Card>& playableCards) {
Command c;
//print current table and current hand
p_->printTable();
p_->printHand();
//print legal plays
std::cout<<"Legal Plays:";
for (int i = 0; (unsigned)i < playableCards.size(); i++) {
std::cout<<" "<<playableCards[i];
}
std::cout<<std::endl;
//loop until valid command is input
while (true) {
std::cout<<">";
std::cin>>c;
if (c.type == QUIT) {
//return the quit command. This will eventually result in throwing Game::QuitException
return c;
}
else if (c.type == DECK) {
//print out deck (possible because we have a pointer to the deck in the player)
//continue looping in this case
p_->printDeck();
}
else if (c.type == PLAY) {
try {
//try playing the card
p_->playCard(c.card, playableCards);
return c;
}
catch (IllegalMoveException& err){
//output error message
//but continue looping
std::cout<<err.msg()<<std::endl;
}
}
else if (c.type == DISCARD) {
try {
//try discarding the card
p_->discardCard(c.card, playableCards);
return c;
}
catch (IllegalMoveException& err){
//output error message
//but continue looping
std::cout<<err.msg()<<std::endl;
}
}
else if (c.type == RAGEQUIT) {
//cause player to ragequit
p_->rageQuit();
return c;
}
}
}