-
Notifications
You must be signed in to change notification settings - Fork 0
/
pawnshop.cpp
160 lines (156 loc) · 6.38 KB
/
pawnshop.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
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
//pawnshop function
#include <iostream>
#include <string>
#include <vector>
#include "Jovian.h"
using namespace std;
void pawnshop(vector<string> &inventory_p, vector<int> &inventory_pvalue, int &health_points)
{
//array with health (first 4) and power (5th to 10th item) increasing items.
string health_power[10] = {"Skele-Gro", "Wiggenweld_Potion", "Pepperup_Potion", "Draught_of_Peace", "Silver_knife",
"guam_potion", "Grimy_guam", "Zamorak_brew", "Saradomin_brew", "Battlemage"};
//array with the values of health and power
int hp_sp_increase[10] = {25, 50, 28, 35, 30, 20, 32, 25, 37, 64};
srand (time(0));
//generating 3 random numbers
int random_option1 = rand() % 10; //random number between 0 and 9.
int random_option2 = rand() % 10;
int random_option3 = rand() % 10;
//giving 3 random options from the pawn shop to choose
cout << "Input " << 1 << " to pick " << health_power[random_option1];
if (random_option1 < 4){
cout << ". This will revive your health points" << endl;
}
else{
cout << ". This will be loaded to your inventory for future monster attacks" << endl;
}
cout << "Input " << 2 << " to pick " << health_power[random_option2];
if (random_option2 < 4){
cout << ". This will revive your health points" << endl;
}
else{
cout << ". This will be loaded to your inventory for future monster attacks" << endl;
}
cout << "Input " << 3 << " to pick " << health_power[random_option3];
if (random_option3 < 4){
cout << ". This will revive your health points" << endl;
}
else{
cout << ". This will be loaded to your inventory for future monster attacks" << endl; //description of what happens with the item
}
int input;
cout << "Choose from 1, 2 or 3 -> ";
cin >> input;
//invalid input criteria
while (input > 3 || input < 1)
{
cout << "Invalid input" << endl;
cin >> input;
}
if (input <= 3 )
{
switch (input)
{
case 1: //if first one is chosen then the health/superpower is increased accordingly.
cout << "You have chosen the first option." << endl;
if (random_option1 < 4)
{
if (health_points >= 120)
{
//if health reaches max, which is defined to be 120, cannot increase further
cout << "Ooooo! Your health is full! Please come back when your health is low" << endl;
}
else
{
cout << "You get " << health_power[random_option1] << " with " << hp_sp_increase[random_option1] << " health points" << endl;
health_points += hp_sp_increase[random_option1];
if (health_points > 120)
health_points = 120; //if health increased beyond over 120, set it to 120.
cout << "Your health is increased to " << health_points << endl;
}
}
else
{
if (inventory_p.size() == 3)
{
cout << "Opps! You inventory is full! Use what you got to hunt some monsters down first!" << endl;
}
else
{
cout << "You get " << health_power[random_option1] << " with attack power of " << hp_sp_increase[random_option1] << endl; //showing what the user gets
inventory_p.push_back(health_power[random_option1]); //adding items to the inventory
inventory_pvalue.push_back(hp_sp_increase[random_option1]); // adding item's value to inventory
cout << health_power[random_option1] << " is added to you inventory." << endl; //confirmation of addition to the inventory
cout << endl;
}
}
break;
case 2: //same as above, but here when second option is chosen
cout << "You have chosen the second option." << endl;
if (random_option2 < 4)
{
if (health_points >= 120)
{
cout << "Ooooo! Your health is full! Please come back when your health is low" << endl;
}
else
{
cout << "You get " << health_power[random_option2] << " with " << hp_sp_increase[random_option2] << " health points" << endl;
health_points += hp_sp_increase[random_option2];
if (health_points > 120)
health_points = 120;
cout << "Your health is increased to " << health_points << endl;
}
}
else
{
if (inventory_p.size() == 3)
{
cout << "Opps! You inventory is full! Use what you got to hunt some monsters down first!" << endl;
}
else
{
cout << "You get " << health_power[random_option2] << " with attack power of " << hp_sp_increase[random_option2] << endl;
inventory_p.push_back(health_power[random_option2]);
inventory_pvalue.push_back(hp_sp_increase[random_option2]);
cout << health_power[random_option2] << " is added to you inventory." << endl;
cout << endl;
}
}
break;
case 3: //same as above, but here is when third option is chosen
cout << "You have chosen the third option." << endl;
if (random_option3 < 4)
{
if (health_points >= 120)
{
cout << "Ooooo! Your health is full! Please come back when your health is low" << endl;
}
else
{
cout << "You get " << health_power[random_option3] << " with " << hp_sp_increase[random_option3] << " health points" << endl;
health_points += hp_sp_increase[random_option3];
if (health_points > 120)
health_points = 120;
cout << "Your health is increased to " << health_points << endl;
}
}
else
{
if (inventory_p.size() == 3)
{
cout << "Opps! You inventory is full! Use what you got to hunt some monsters down first!" << endl;
}
else
{
cout << "You get " << health_power[random_option3] << " with attack power of " << hp_sp_increase[random_option3] << endl;
inventory_p.push_back(health_power[random_option3]);
inventory_pvalue.push_back(hp_sp_increase[random_option3]);
cout << health_power[random_option3] << " is added to you inventory." << endl;
cout << endl;
}
}
break;
}
}
}