-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerchant.cpp
More file actions
375 lines (304 loc) · 12.5 KB
/
Copy pathMerchant.cpp
File metadata and controls
375 lines (304 loc) · 12.5 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// Author: Matayay Karuna
#include <iostream>
#include <string>
#include <cctype>
#include "Merchant.h"
using namespace std;
Merchant::Merchant()
{
price = 1;
}
int Merchant::getPrice()
{
return price;
}
void Merchant::setPrice( double new_price )
{
price = new_price;
}
void Merchant::menu()
{
// Declare variables.
int choice;
int amount;
char confirm;
int gold;
int item_price;
int cookware;
int pot = 2 * price;
int pan = 10 * price;
int cauldron = 20 * price;
int ingrediants = 1 * price;
int weapons;
int club = 2 * price;
int spear = 2 * price;
int rapier = 5 * price;
int axe = 15 * price;
int longsword = 50 * price;
int armor = 5 * price;
int treasures;
int ring = 10;
int necklace = 20;
int bracelet = 30;
int circlet = 40;
int goblet = 50;
// Declare arrays.
string cookware_arr[3] = { "Ceramic Pot(s)", "Frying Pan(s)", "Cauldron(s)" };
string weapons_arr[5] = { "Stone Club(s)", "Iron Spear(s)", "(+1) Mythril Rapier(s)", "(+2) Flaming Battle-Axe(s)", "(+3) Vorpal Longsword(s)" };
string treasures_arr[5] = { "Silver Ring(s)", "Ruby Necklace(s)", "Emerald Bracelet(s)", "Diamond Circlet(s)", "Gem-encrusted Goblet(s)" };
int cookware_price[3] = { pot, pan, cauldron };
int weapons_price[5] = { club, spear, rapier, axe, longsword };
int treasures_price[5] = { ring, necklace, bracelet, circlet, goblet };
cout << "\n" << "If you're looking to get supplies, you've come to the right place." << endl <<
"I would be happy to part with some of my wares...for the proper price!" << endl;
do
{
cout << "\n";
printInventory();
cout << "\n" << "Choose one of the following:" << endl <<
"1. Ingredients: To make food, you have to cook raw ingredients." << endl <<
"2. Cookware: You will need something to cook those ingredients." << endl <<
"3. Weapons: It's dangerous to go alone, take this!" << endl <<
"4. Armor: If you want to survive monster attacks, you will need some armor." << endl <<
"5. Sell treasures: If you find anything shiny, I would be happy to take it off your hands." << endl <<
"6. Leave: Make sure you get everything you need, I'm leaving after this sale!" << endl;
cin >> choice;
if ( choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 5 && choice != 6 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( choice == 1 )
{
cout << "\n" << "How many kg of ingredients do you need [" << ingrediants << " gold/kg]?" << "(Enter a positive mulitple of 5, or 0 to cancel): " << endl;
cin >> amount;
if ( amount < 0 || amount % 5 != 0 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( amount == 0 )
{
continue;
}
gold = getGold();
item_price = ingrediants * amount;
if ( gold < item_price )
{
cout << "You cannot afford to buy this." << endl;
}
else
{
cout << "\n" << "You want to buy " << amount << " kg of ingrediants for " << item_price << " Gold? (y/n): " << endl;
cin >> confirm;
if ( tolower(confirm) != 'y' )
{
continue;
}
setGold(gold - item_price);
setIngrediants(getIngrediants() + amount);
cout << "\n" << "Thank you for your patronage! What else can I get for you?" << endl;
}
}
else if ( choice == 2 )
{
cout << "\n" << "I have a several types of cookware, which one would you like?" << endl <<
"Each type has a different probability of breaking when used, marked with (XX%)." << endl;
do
{
cout << "\n" << "Choose one of the following:" << endl <<
"1. (25%) Ceramic Pot " << pot << " gold" << endl <<
"2. (10%) Frying Pan " << pan << " gold" << endl <<
"3. ( 2%) Cauldron " << cauldron << " gold" << endl <<
"4. Cancel" << endl;
cin >> cookware;
if ( cookware != 1 && cookware != 2 && cookware != 3 && cookware != 4 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( cookware == 4 )
{
break;
}
cout << "\n" << "How many would you like? (Enter a positive integer, or 0 to cancel): " << endl;
cin >> amount;
if ( amount < 0 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( amount > 0 )
{
gold = getGold();
item_price = cookware_price[cookware-1] * amount;
if ( gold < item_price )
{
cout << "You cannot afford to buy this." << endl;
}
else
{
cout << "\n" << "You want to buy " << amount << " " << cookware_arr[cookware-1] << " for " << item_price << " Gold? (y/n): " << endl;
cin >> confirm;
if ( tolower(confirm) != 'y' )
{
continue;
}
setGold(gold - item_price);
setCookware((getCookware(cookware-1) + amount), (cookware-1));
cout << "\n" << "Thank you for your patronage! What else can I get for you?" << endl;
}
}
}
while ( cookware != 3 );
}
else if ( choice == 3 )
{
cout << "\n" << "I have a plentiful collection of weapons to choose from, what would you like?" << endl <<
"Note that some of them provide you a special bonus in combat, marked by a (+X)." << endl;
do
{
cout << "\n" << "Choose one of the following:" << endl <<
"1. Stone Club " << club << " gold" << endl <<
"2. Iron Spear " << spear << " gold" << endl <<
"3. (+1) Mythril Rapier " << rapier << " gold" << endl <<
"4. (+2) Flaming Battle-Axe " << axe << " gold" << endl <<
"5. (+3) Vorpal Longsword " << longsword << " gold" << endl <<
"6. Cancel" << endl;
cin >> weapons;
if ( weapons != 1 && weapons != 2 && weapons != 3 && weapons != 4 && weapons != 5 && weapons != 6 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( weapons == 6 )
{
break;
}
cout << "\n" << "How many would you like? (Enter a positive integer, or 0 to cancel): " << endl;
cin >> amount;
if ( amount < 0 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( amount > 0 )
{
gold = getGold();
item_price = weapons_price[weapons-1] * amount;
if ( gold < item_price )
{
cout << "You cannot afford to buy this." << endl;
}
else if ( (getTotalWeapons() + amount) > getMaxWeapons() )
{
cout << "You cannot carry any more weapons." << endl;
}
else
{
cout << "\n" << "You want to buy " << amount << " " << weapons_arr[weapons-1] << " for " << item_price << " Gold? (y/n): " << endl;
cin >> confirm;
if ( tolower(confirm) != 'y' )
{
continue;
}
setGold(gold - item_price);
setWeapon((getWeapons(weapons-1) + amount), (weapons-1));
cout << "\n" << "Thank you for your patronage! What else can I get for you?" << endl;
}
}
}
while( weapons != 5 );
}
else if ( choice == 4 )
{
cout << "\n" << "How many suits of armor can I get you? (Enter a positive integer, or 0 to cancel): " << endl;
cin >> amount;
if ( amount < 0 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( amount == 0 )
{
continue;
}
gold = getGold();
item_price = armor * amount;
if ( gold < item_price )
{
cout << "You cannot afford to buy this." << endl;
}
else if ( (getArmor() + amount) > getMaxArmor() )
{
cout << "You cannot carry any more armor." << endl;
}
else
{
cout << "\n" << "You want to buy " << amount << " suit(s) of armor for " << item_price << " Gold? (y/n): " << endl;
cin >> confirm;
if ( tolower(confirm) != 'y' )
{
continue;
}
setGold(gold - item_price);
setArmor(getArmor() + amount);
cout << "\n" << "Thank you for your patronage! What else can I get for you?" << endl;
}
}
else if ( choice == 5 )
{
do
{
cout << "\n" << "What would you like to sell?" << endl <<
"1. 1 Room: Silver ring - 10 gold pieces each" << endl <<
"2. 2 Rooms: Ruby necklace - 20 gold pieces each" << endl <<
"3. 3 Rooms: Emerald bracelet - 30 gold pieces each" << endl <<
"4. 4 Rooms: Diamond circlet - 40 gold pieces each" << endl <<
"5. 5 Rooms: Gem-encrusted goblet - 50 gold pieces each" << endl <<
"6. Cancel." << endl;
cin >> treasures;
if ( treasures != 1 && treasures != 2 && treasures != 3 && treasures != 4 && treasures != 5 && treasures != 6 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( treasures == 6 )
{
break;
}
cout << "\n" << "How many would you like to sell? (Enter a positive integer, or 0 to cancel): " << endl;
cin >> amount;
if ( amount < 0 )
{
cout << "Invalid input, please try again." << endl;
continue;
}
else if ( amount > 0 )
{
gold = getGold();
item_price = treasures_price[treasures-1] * amount;
cout << "\n" << "You want to sell " << amount << " " << treasures_arr[treasures-1] << " for " << item_price << " Gold? (y/n): " << endl;
cin >> confirm;
if ( tolower(confirm) != 'y' )
{
continue;
}
else if ( getTreasures(treasures-1) < amount )
{
cout << "You are trying to sell items you do not have." << endl;
}
else
{
setGold(gold + item_price);
setTreasure((getTreasures(treasures-1) - amount), (treasures-1));
cout << "\n" << "Thank you for your patronage! What else can I get for you?" << endl;
}
}
}
while ( treasures != 6 );
}
}
while( choice != 6 );
return;
}