-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuction.cpp
More file actions
239 lines (224 loc) · 12.7 KB
/
Auction.cpp
File metadata and controls
239 lines (224 loc) · 12.7 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "Game.h"
#include <iostream>
#include <string>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Game::biddersMenu(int currenBidderTurn)
{
int chosenOption = 0;
cout << "\x1B[92m" << "[" << player[currenBidderTurn].getName() << "] " << "\x1B[0m" << "Turn" << endl;
cout << "------------Bidding Menu------------" << endl;
cout << "1. Bid" << endl;
cout << "2. Morgage" << endl;
cout << "3. Balance" << endl;
cout << "4. Owned Properties" << endl;
cout << "5. Withdraw From Bid" << endl;
cin >> chosenOption;
if(cin.fail())
{
cin.clear();
cin.ignore(1000, '\n');
cout << "\x1B[91m" << "You've Entered a non-digit Input" << "\x1B[0m" << endl;
biddersMenu(currenBidderTurn);
}
return chosenOption;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Game::biddingPrice()
{
int bidPrice = 0;
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "How much would you like to bid? $";
cin >> bidPrice;
if(cin.fail())
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "The input you've entered is INVALID" << endl;
biddingPrice();
}
return bidPrice;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Game::auction(int propertyLocation)
{
int numBidders = numPlayers;
bool playerBidStatus[4];
int playerCurrentBid[4];
//Initialize Array
for(int i = 0; i < numBidders; i++)
{
playerBidStatus[i] = true;
playerCurrentBid[i] = 0;
}
while(numBidders != 1)
{
for(int i = 0; (1 != numBidders) && (i < numPlayers); i++)
{
system("clear");
if(player[i].getBankruptStatus() == false && playerBidStatus[i] == true)
{
cout << "############################################################# " << "\x1B[92m" << "AUCTION GROUND" << "\x1B[0m" << " ##################################################################" << endl;
cout << "Current Bids: " << endl;
for(int j = 0; j < numPlayers; j++)
{
if(playerBidStatus[j] == true && i != j)
{
cout << "[" << player[j].getName() << "] " << "\x1B[91m" << "$" << playerCurrentBid[j] << "\x1B[0m" << " ";
}
else if(playerBidStatus[j] == true && i == j)
{
cout << "[" << player[j].getName() << "] " << "\x1B[92m" << "$" << playerCurrentBid[j] << "\x1B[0m" << " ";
}
}
cout << endl;
getPropertyInfo(propertyLocation);
int repeater = 0;
while(repeater == 0)
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << " Does Player [" << player[i].getName() << "] want to bid?" << endl;
int biddersMenuOption = biddersMenu(i);
switch(biddersMenuOption)
{
case 1:
{
int bidPrice = 0;
bidPrice = biddingPrice();
int highestBid = 0;
for(int j = 0; j < numBidders; j++)
{
if(playerCurrentBid[j] > highestBid)
{
highestBid = playerCurrentBid[j];
}
}
//Checks if the bid price is not negative and if the bid price is higher than the previous
while(highestBid >= bidPrice || bidPrice <= 0)
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "Player " << player[i].getName() << " your bid is too low!" << endl;
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << " Our highest bid is currently " << "\x1B[92m" << "$" << highestBid << "\x1B[0m" << endl << endl;
biddersMenuOption = biddersMenu(i);
bidPrice = biddingPrice();
}
playerCurrentBid[i] = bidPrice;
// Checks player balance if they have the money to buy a property with their bid price.
string morgageResponse;
while((player[i].getBalance() - bidPrice) < 0 && playerBidStatus[i])
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "You're bidding price is higher than your balance!" << endl;
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "Would you like to morgage some of your properties? Enter y/n" << endl;
cin >> morgageResponse;
if(toupper(morgageResponse) == "Y")
{
int savedCurrentTurn = currentTurn;
currentTurn = i + 1;
morgage();
currentTurn = savedCurrentTurn;
biddersMenuOption = biddersMenu(i);
bidPrice = biddingPrice();
playerCurrentBid[i] = bidPrice;
}
else
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << player[i].getName() << " has withdrawn from the bidding ground." << endl;
playerBidStatus[i] = false;
numBidders--;
}
}
if (playerBidStatus[0] && i == 0)
{
playerCurrentBid[0] = bidPrice;
cout << "Player " << "\x1B[92m" << "[" << player[i].getName() << "] " << "\x1B[0m" << "has bid for " << "\x1B[92m" << "$" << bidPrice << "\x1B[0m" << endl << endl;
}
if (playerBidStatus[1] && i == 1)
{
playerCurrentBid[1] = bidPrice;
cout << "Player " << "\x1B[92m" << "[" << player[i].getName() << "] " << "\x1B[0m" << "has bid for " << "\x1B[92m" << "$" << bidPrice << "\x1B[0m" << endl;
}
if (playerBidStatus[2] && i == 2)
{
playerCurrentBid[2] = bidPrice;
cout << "Player " << "\x1B[92m" << "[" << player[i].getName() << "] " << "\x1B[0m" << "has bid for " << "\x1B[92m" << "$" << bidPrice << "\x1B[0m" << endl;
}
if (playerBidStatus[3] && i == 3)
{
playerCurrentBid[3] = bidPrice;
cout << "Player " << "\x1B[92m" << "[" << player[i].getName() << "] " << "\x1B[0m" << "has bid for " << "\x1B[92m" << "$" << bidPrice << "\x1B[0m" << endl;
}
repeater = 1;
break;
}
case 2:
{
morgage();
break;
}
case 3:
{
cout << "Current Balance: " << "\x1B[92m" << "$" << player[i].getBalance() << "\x1B[0m" << endl;
break;
}
case 4:
{
listOfOwnedProperties();
break;
}
case 5:
{
//Need to find player with the higher bid
int highestBid = 0;
int playerWithHighestBid;
for(int j = 0; j < numPlayers; j++)
{
if(playerCurrentBid[j] > highestBid && playerBidStatus[j] == true)
{
highestBid = playerCurrentBid[j];
playerWithHighestBid = j;
}
}
if(playerWithHighestBid == i)
{
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << player[i].getName() << " you are not allowed to leave the auction ground because you are our highest bidder!" << endl;
}
else
{
playerBidStatus[i] = false;
numBidders--;
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << player[i].getName() << " has withdrawn!" << endl;
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "There are " << numBidders << " left!" << endl;
repeater = 1;
}
break;
}
default:
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "You've Entered an Invalid Option." << endl;
break;
}
}
}
int numBiddersCheck = numPlayers;
if(numBidders == 1)
{
int winner;
for(int k = 0; k < numBiddersCheck; k++)
{
if(playerBidStatus[k] == true)
{
winner = k;
}
}
cout << endl;
system("clear");
cout << "\x1B[92m" << "[Mr.Monopoly] " << "\x1B[0m" << "Congratulations, " << player[winner].getName() << "! You're the proud owner of " << property[propertyLocation].getPropertyName() << endl;
property[propertyLocation].setOwner(player[winner].getName());
int winnerBalance = player[winner].getBalance();
cout << "Transaction: " << "\x1B[92m" << "$" << winnerBalance << "\x1B[97m" << " - $" << playerCurrentBid[winner] << endl;
player[winner].setBalance(winnerBalance - playerCurrentBid[winner]);
cout << "Current Balance: " << "\x1B[92m" << "$" << player[winner].getBalance() << "\x1B[0m" << endl;
}
}
}
}