-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBidding.cpp
84 lines (68 loc) · 1.26 KB
/
Bidding.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 "stdafx.h"
#include "Bidding.h"
#include<iostream>
using namespace std;
Bidding::Bidding() {};
Bidding::Bidding(int year, int totalCoin)
{
age = new int(year);
playerTotalCoin = new int(totalCoin);
};
int Bidding::getBidding()
{
return (*biddingCoins);
}
int Bidding::getRun()
{
return *OnlyOnce;
}
int Bidding::getAge()
{
return *age;
}
// you can only bid one time
void Bidding::runOnce(bool CPU)
{
if (OnlyOnce == 0) {
bid(CPU);
OnlyOnce++;
}
else {
cout << "This player has already made a bid" << endl;
}
}
// give the player access to one bidding
void Bidding::bid(bool CPU)
{
int selectedCoin;
while (true) {
cout << endl;
if (!CPU) {
while (true) {
cout << "how many coins do you want to bid ?" << endl;
cin >> selectedCoin;
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
else {
break;
}
}
}
else {
selectedCoin = rand() % 10;
cout << " The CPU bid for ";
cout << selectedCoin;
cout << " coins" << endl << endl;
}
if (selectedCoin <= *playerTotalCoin && selectedCoin >= 0) {
biddingCoins = new int(selectedCoin);
break;
}
else {
cout << endl;
cout << "Maximum bidding is : " << *playerTotalCoin << endl;
}
}
}