-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipant.cpp
121 lines (97 loc) · 2.28 KB
/
participant.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* kjs170430_Project4/participant.cpp
* Copyright 2017, Kristopher Sewell, All rights reserved.
*
* Course: CE1337 Section: 501 Project: 4
*/
#include "participant.hpp"
Participant::Participant() {
m_spinGain = 0;
setName();
}
Participant::Participant(BettingSystem * bs, string name) {
m_CurrentBetTable = bs;
setName(name);
}
Participant::~Participant() {
delBetArray();
}
void Participant::initBank() {
string strin;
std::cout << "For Player: " << getName()
<< " enter a starting balance up to $10,000.\n";
std::cin >> strin;
if (checkIsDigit(strin)) { //is it safe to convert into a digit.
int testVal = atoi(strin.c_str());
if (testVal > 0 && testVal < 10001) {
m_bank = testVal;
} else {
std::cout << "That amount is not valid.";
Participant::initBank(); //try again.
}
}
}
void Participant::PayOut(int diff) {
m_spinGain += diff;
m_totalGain += diff;
m_bank += diff;
}
void Participant::resetSpin() {
m_spinGain = 0;
}
void Participant::setName(string name) {
m_name = name;
}
void Participant::setName() {
string name;
std::cout << "Please enter your name.\n";
std::getline(std::cin,name);
m_name = name;
}
void Participant::setBetArray() {
SIZE = getBetNum();
m_bets = new BetMessage*[SIZE];
for (int k = 0; k < SIZE; k++) {
m_bets[k] = new BetMessage();
}
}
void Participant::delBetArray() {
for (int i = 0; i < SIZE && m_bets != nullptr; i++) {
delete m_bets[i];
}
delete [] m_bets;
m_bets = nullptr;
}
string Participant::getName() const {
return m_name;
}
int Participant::getBetNum() {
string temp;
std::cout << "How many bets would you like to make?\nYou may make up to 8 bets: ";
std::cin >> temp;
std::cout << std::endl;
if (checkIsDigit(temp)) {
int rtn = atoi(temp.c_str());
if (rtn < 9 && rtn > 0) {
return rtn;
}
}
getBetNum();
return 0; //should never run.
}
int Participant::getBank() const {
return m_bank;
}
int Participant::getTotalGain() const {
return m_totalGain;
}
int Participant::getSpinGain() const {
return m_spinGain;
}
int Participant::getSIZE() const {
return SIZE;
}
BetMessage* Participant::getBet(int index) {
if (m_bets == nullptr) {return nullptr;}
return m_bets[index];
}