forked from jaredtao/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.h
42 lines (41 loc) · 940 Bytes
/
Player.h
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
#pragma once
#include "IStrategy.h"
#include <sstream>
#include <string>
class Player
{
public:
Player(const std::string &name, IStrategy *strategy) : m_strategy(strategy), m_name(name) {}
Hand nextHand()
{
return m_strategy->nextHand();
}
void win()
{
m_strategy->study(true);
m_gameCount++;
m_winCount++;
}
void lose()
{
m_strategy->study(false);
m_gameCount++;
m_loseCount++;
}
void even()
{
m_gameCount++;
}
std::string getString() const
{
std::stringstream ss;
ss << "Player: " << m_name << " gameCount:" << m_gameCount << " win:" << m_winCount << " lose:" << m_loseCount << " even:" << m_gameCount - m_loseCount - m_winCount;
return ss.str();
}
private:
IStrategy *m_strategy;
std::string m_name;
int m_gameCount = 0;
int m_winCount = 0;
int m_loseCount = 0;
};