forked from AlexMPC/ALL-Project-2-master-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshop.cpp
More file actions
339 lines (295 loc) · 10.7 KB
/
shop.cpp
File metadata and controls
339 lines (295 loc) · 10.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
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
// ALL 2.cpp : Defines the entry point for the console application.
#include <iostream>
#include "libsqlite.hpp"
#include "global.h"
using namespace std;
//Gold decrease when bronze armour brought
int golddecarmourbronze(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-20 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Armour bronze - 20 points
int armourbronze(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET armor=armor+20 WHERE idUser =?;");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when silver armour brought
int golddecarmoursilver(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-40 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Armour silver - 60 points
int armoursilver(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET armor=armor+60 WHERE idUser =?;");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when gold armour brought
int golddecarmourgold(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-60 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Armour gold - 100 points
int armourgold(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET armor=armor+100 WHERE idUser =?;");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when large duration brought
int golddecleveljump(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-200 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Level jump - 1 level
int leveljump(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET level=level+1 WHERE idUser=?;");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when small duration brought
int golddecdurationsmall(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-10 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Duration increase - up 3
int durincsmall(sqlite::sqlite &db) {//Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE weapons_user SET duration=duration+3 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when medium duration brought
int golddecdurationmedium(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-30 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Duration increase - up 6 - medium
int durincmedium(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE weapons_user SET duration=duration+6 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Gold decrease when large duration brought
int golddecdurationlarge(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE users SET gold=gold-80 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Duration increase - up 20 - large
int durinclarge(sqlite::sqlite &db) { //Uses the already opened database connection
auto cur2 = db.get_statement();
cur2->set_sql("UPDATE weapons_user SET duration=duration+20 WHERE idUser =?");
cur2->prepare();
cur2->bind(1,globalUserID); //global user id is used to find the users id
cur2->step();
return 0;
}
//Calls the users amount of armour
int armourcall(sqlite::sqlite &db){ //Uses the already opened database connection
auto cur = db.get_statement();
cur->set_sql("SELECT armor, username FROM users WHERE idUser=?");
cur->prepare();
cur->bind(1,globalUserID); //global user id is used to find the users id
cur->step();
int armouruser = cur->get_int(0);
cout << armouruser << endl;
}
//Calls the users amount of gold
int goldamountcall(sqlite::sqlite &db){ //Uses the already opened database connection
auto cur = db.get_statement();
cur->set_sql("SELECT gold FROM users WHERE idUser=?;");
cur->prepare();
cur->bind(1,globalUserID); //global user id is used to find the users id
cur->step();
int goldamount = cur->get_int(0);
cout << goldamount << endl;
}
int shopMain(){
bool running=false;
while(running!=true)
{
sqlite::sqlite db( "dungeonCrawler.db" ); //Opens the connection to the database that will be used througout the program
auto cur = db.get_statement();
cur->set_sql("SELECT gold FROM users WHERE idUser=?;");
cur->prepare();
cur->bind(1,globalUserID); //global user id is used to find the users id
cur->step();
int goldamount = cur->get_int(0);
char broughtitem;
//List of items in the shop
cout << "Your current gold amount is: " << goldamount << endl;
cout << "+-------------+---------------------------------+------------+----------+" << endl;
cout << "| Item number | Item | Value | Cost |" << endl;
cout << "+-------------+---------------------------------+------------+----------+" << endl;
cout << "| 1 | Bronze armour potion | 20 points | 20 gold |" << endl;
cout << "| 2 | Silver armour Potion | 60 points | 40 gold |" << endl;
cout << "| 3 | Gold armour potion | 100 points | 60 gold |" << endl;
cout << "| 4 | Small weapon duration increase | 3 points | 10 gold |" << endl;
cout << "| 5 | Medium weapon duration increase | 6 points | 30 gold |" << endl;
cout << "| 6 | Large weapon duration increase | 20 points | 80 gold |" << endl;
cout << "| 7 | Level Jump | 1 level | 200 gold |" << endl;
cout << "| 8 | Go back to menu | None | None |" << endl;
cout << "+-------------+---------------------------------+------------+----------+" << endl;
cout << "Please enter your choice: " << endl;
cin >> broughtitem;
//If statement to run the functions of the item the user has chosen to buy
if (broughtitem=='1')
{
//run armour increase bronze
if (goldamount>=20)
{
golddecarmourbronze(db);
armourbronze(db);
cout << "Your armour has been increased by 20 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='2')
{
//run armour increase silver
if (goldamount>=40 )
{
golddecarmoursilver(db);
armoursilver(db);
cout << "Your armour has been increased by 60 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='3')
{
//run armour increase gold
if (goldamount>=60)
{
golddecarmourgold(db);
armourgold(db);
cout << "Your armour has been increased by 100 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='4')
{
//run weapon duration increase small
if (goldamount>=10)
{
golddecdurationsmall(db);
durincsmall(db);
cout << "The duration of all your weapons has been increased by 3 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='5')
{
if (goldamount>=30)
{
golddecdurationmedium(db);
durincmedium(db);
cout << "The duration of all your weapons has been increased by 6 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='6')
{
//run weapon duration increase large
if (goldamount>=80)
{
golddecdurationlarge(db);
durinclarge(db);
cout << "The duration of all your weapons has been increased by 20 points!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='7')
{
//run level increase
if (goldamount>=200)
{
leveljump(db);
golddecleveljump(db);
cout << "Your level has been increased by one!!!" << endl;
running=true;
}
else
{
cout << "You don't have enough gold" << endl;
}
}
else if (broughtitem=='8')
{
break;
}
else
{
cout << "something is wrong" << endl;
}
}
return 0;
}