-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
69 lines (54 loc) · 1.33 KB
/
Player.cpp
File metadata and controls
69 lines (54 loc) · 1.33 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
#include "Player.h"
Player::Player(ScoreSheet *_ss) : d_ScoreSheet(_ss) {}
bool Player::operator!() const
{
return !*d_ScoreSheet;
}
std::vector<Color> Player::get_color_index_vect(std::istream& _in) const
{
std::vector<Color> dice_colors;
while(dice_colors.size() < 1)
{
//getting input line
std::string raw;
std::getline(_in, raw);
//converting input line into vector of dice colors
std::istringstream ss(raw);
std::string tmp;
while(ss >> tmp)
{
Color c = convert_to_color(tmp);
if(c != Color::INVALID)
dice_colors.push_back(c);
}
if(dice_colors.size() < 1)
std::cout << "invalid input please try again: ";
}
return dice_colors;
}
Color Player::convert_to_color(const std::string _str) const
{
if(_str == "red")
return Color::RED;
else if(_str == "yellow")
return Color::YELLOW;
else if(_str == "green")
return Color::GREEN;
else if(_str == "blue")
return Color::BLUE;
else if(_str == "white-1")
return Color::WHITE_1;
else if(_str == "white-2")
return Color::WHITE_2;
else
return Color::INVALID;
}
int Player::printScoreSheet() const
{
std::cout << *d_ScoreSheet;
return d_ScoreSheet->setTotal();
}
std::string Player::getName() const
{
return d_ScoreSheet->getName();
}