SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | #include <string> | |
3 | #include <ctime> | |
4 | #include <stdlib.h> | |
5 | using namespace std; | |
6 | //GLOBAL VARIABLES | |
7 | struct inventory { | |
8 | string type; | |
9 | string name; | |
10 | bool equiped; | |
11 | }; | |
12 | struct player { | |
13 | int hp; | |
14 | int hpmax; | |
15 | int agi; | |
16 | int str; | |
17 | string name; | |
18 | string abilities[3]; | |
19 | bool dead; | |
20 | int ct; | |
21 | string ally; | |
22 | int dex; | |
23 | int magicattackmul; | |
24 | int attackmul; | |
25 | string job; | |
26 | int mp; | |
27 | int mpmax; | |
28 | int lvl; | |
29 | int exp; | |
30 | int expmax; | |
31 | int ap; | |
32 | inventory inv[10]; | |
33 | int items; | |
34 | }; | |
35 | int chance = rand() % 100; | |
36 | int ac = 0; | |
37 | int ec = 0; | |
38 | int etarget = rand() % 4; | |
39 | int eability = rand() % 1; | |
40 | int input; | |
41 | int target; | |
42 | int itemin; | |
43 | int gold; | |
44 | bool found = false; | |
45 | int itemfound; | |
46 | //THIS IS JUST FOR TESTING | |
47 | void setup_player(struct player *players) { | |
48 | for(int i = 0; i <= 4; i++) { | |
49 | players[i].dead = false; | |
50 | players[i].hpmax = players[i].hp; | |
51 | players[i].ct = 0; | |
52 | players[i].ally = "ally"; | |
53 | } | |
54 | players[3].ally = "enemy"; | |
55 | players[4].ally = "enemy"; | |
56 | for(int i = 0; i <= 4; i++) { | |
57 | if(players[i].ally == "ally") { | |
58 | ac += 1; | |
59 | } | |
60 | if(players[i].ally == "enemy") { | |
61 | ec += 1; | |
62 | } | |
63 | } | |
64 | for(int i = 0; i <= 4; i++) { | |
65 | cout << players[i].ally << i << " Name: "; | |
66 | cin >> players[i].name; | |
67 | cout << i << " Agility"; | |
68 | cin >> players[i].agi; | |
69 | cout << players[i].ally << i << " Strenght: "; | |
70 | cin >> players[i].str; | |
71 | cout << players[i].ally << i << " Hit Points: "; | |
72 | players[i].attackmul = 4; | |
73 | cin >> players[i].hp; | |
74 | players[i].hpmax = players[i].hp; | |
75 | players[i].abilities[0] = "Attack"; | |
76 | players[i].dex = 77; | |
77 | players[0].abilities[1] = "Steal"; | |
78 | players[1].abilities[1] = "Cura"; | |
79 | players[2].abilities[1] = "Blaze"; | |
80 | players[i].abilities[2] = "Item"; | |
81 | players[i].inv[0].name = "Grenade"; | |
82 | players[i].inv[1].name = "Grenade"; | |
83 | players[i].inv[2].name = "Grenade"; | |
84 | } | |
85 | for(int i = 3; i < 10; i++) { | |
86 | players[0].inv[i].name = " "; | |
87 | players[1].inv[i].name = " "; | |
88 | players[2].inv[i].name = " "; | |
89 | } | |
90 | for(int i = 0; i < 10; i++) { | |
91 | players[i].items = 3; | |
92 | } | |
93 | for(int i = 0; i <= 4; i++) { | |
94 | players[i].mp = 999; | |
95 | players[i].mpmax = 999; | |
96 | } | |
97 | for(int i = 3; i <= 4; i++) { | |
98 | players[i].abilities[1] = "Blaze"; | |
99 | } | |
100 | } | |
101 | //ABILITY LIST; all the abilities are utterly useless due to attackmul. | |
102 | void checkabi(struct player *players, int i, int target, int input) { | |
103 | if(players[target].hp+players[i].str <= players[target].hpmax) { | |
104 | if(players[i].abilities[input] == "Attack") { | |
105 | if(chance <= players[i].dex) { | |
106 | cout << "Critical Hit!"; | |
107 | cout << players[i].name << " attacks " << players[target].name << " with " << players[i].str*players[i].attackmul*2 << " dmg" << endl; | |
108 | players[target].hp += players[i].str*players[i].attackmul*2; | |
109 | srand(150); | |
110 | chance = rand() % 100; | |
111 | } else { | |
112 | cout << players[i].name << " attacks " << players[target].name << " with " << players[i].str*players[i].attackmul << " dmg" << endl; | |
113 | players[target].hp += players[i].str*players[i].attackmul; | |
114 | } | |
115 | } | |
116 | if(players[i].mp <= 0) { | |
117 | cout << "Out of MP"; | |
118 | } else { | |
119 | if(players[i].abilities[input] == "Cure") { | |
120 | cout << players[i].name << " heals " << " with " << "500"<< " restored hp " << endl; | |
121 | players[target].hp += 500; | |
122 | } | |
123 | if(players[i].abilities[input] == "Blaze") { | |
124 | cout << players[i].name << " Casts Blaze" << " with " << players[i].str*2 << " dmg" << endl; | |
125 | players[target].hp += players[i].str*2*players[i].attackmul; | |
126 | players[i].mp -= 4; | |
127 | } | |
128 | if(players[i].abilities[input] == "Cura") { | |
129 | cout << players[i].name << " Heals " << " with " << "1000" << " restored hp" << endl; | |
130 | players[target].hp += 1000; | |
131 | } | |
132 | if(players[i].abilities[input] == "Blaza") { | |
133 | cout << players[i].name << " Casts Blaze " << " with " << players[i].str << " hp" << endl; | |
134 | players[target].hp += players[i].str*3*players[i].attackmul; | |
135 | players[i].mp -= 8; | |
136 | } | |
137 | } | |
138 | if(players[i].abilities[input] == "Steal") { | |
139 | for(int v = 0; v < 10; v++) { | |
140 | if(players[target].inv[v].name != " ") { | |
141 | found = true; | |
142 | itemfound = v; | |
143 | break; | |
144 | } | |
145 | } | |
146 | cout << "Stole " << players[target].inv[itemfound].name << "!\n"; | |
147 | - | players[i].inv[items].name = players[target].inv[itemfound].name; |
147 | + | players[i].inv[players[i].items].name = players[target].inv[itemfound].name; |
148 | players[i].items++; | |
149 | } | |
150 | if(players[i].abilities[input] == "Item") { | |
151 | for(int v = 0; v < 10; v++) { | |
152 | cout << v << " " << players[i].inv[v].name << endl; | |
153 | } | |
154 | cin >> itemin; | |
155 | if(players[i].inv[itemin].name == "Potion") { | |
156 | cout << players[i].name << " Throws a Potion\n"; | |
157 | players[target].hp += 100; | |
158 | } | |
159 | if(players[i].inv[itemin].name == "HiPotion") { | |
160 | cout << players[i].name << " Throws a HiPotion\n"; | |
161 | players[target].hp += 500; | |
162 | } | |
163 | if(players[i].inv[itemin].name == "XPotion") { | |
164 | cout << players[i].name << " Throws a XPotion\n"; | |
165 | players[target].hp = players[target].hpmax; | |
166 | } | |
167 | if(players[i].inv[itemin].name == "Grenade") { | |
168 | cout << players[i].name << " Throws a grenade\n"; | |
169 | players[target].hp += -300; | |
170 | } | |
171 | if(players[i].inv[itemin].name == " ") { | |
172 | cout << "Empty slot!"; | |
173 | } | |
174 | players[i].inv[itemin].name = " "; | |
175 | players[i].items--; | |
176 | } | |
177 | players[i].ct = 0; | |
178 | } else { | |
179 | players[i].ct = 0; | |
180 | players[target].hp = players[target].hpmax; | |
181 | } | |
182 | } | |
183 | //BATTLE FUNCTION | |
184 | void battle(struct player *players) { | |
185 | while(true) { | |
186 | for(int i = 0; i <= 4; i++) { | |
187 | if(players[i].hp <= 0 && players[i].ally == "ally" && !players[i].dead) { | |
188 | players[i].dead = true; | |
189 | ac -= 1; | |
190 | break; | |
191 | } | |
192 | if(players[i].hp <= 0 && players[i].ally == "enemy" && !players[i].dead) { | |
193 | ec -= 1; | |
194 | players[i].dead = true; | |
195 | break; | |
196 | ||
197 | } | |
198 | if(ac <= 0) { | |
199 | cout << "\nLost\n"; | |
200 | cin.get(); | |
201 | cin.get(); | |
202 | exit(0); | |
203 | } | |
204 | if(ec <= 0) { | |
205 | cout << "\nwon\n"; | |
206 | cin.get(); | |
207 | cin.get(); | |
208 | exit(0); | |
209 | } | |
210 | } | |
211 | for(int i = 0; i <= 4; i++) { | |
212 | if(players[i].ct >= 100) { | |
213 | if(players[i].ally == "ally") { | |
214 | cout << players[i].name << endl; | |
215 | for(int c = 0; c <= 2; c++) { | |
216 | cout << c << " - " << players[i].abilities[c] << endl; | |
217 | } | |
218 | cin >> input; | |
219 | cout << "Who do you want to target?\n"; | |
220 | for(int j = 0; j <= 4; j++) { | |
221 | cout << j << " - " << players[j].name << " Hp: " << players[j].hp << endl; | |
222 | } | |
223 | cin >> target; | |
224 | if(players[target].dead) { | |
225 | cout << "\nAlready dead\n"; | |
226 | players[i].ct = 0; | |
227 | break; | |
228 | } | |
229 | checkabi(players, i, target, input); break; | |
230 | } | |
231 | if(players[i].ally == "enemy") { | |
232 | while(true) { | |
233 | if(players[etarget].dead || players[etarget].ally == "enemy") { | |
234 | if(ac <= 0) break; | |
235 | etarget = rand() % 4; | |
236 | } | |
237 | if(!players[etarget].dead || players[etarget].ally == "ally") break; | |
238 | } | |
239 | checkabi(players, i, etarget, eability); | |
240 | players[i].ct = 0; | |
241 | etarget = rand() % 4; | |
242 | eability = rand() % 2; | |
243 | } | |
244 | } | |
245 | players[i].ct += players[i].agi; | |
246 | if(players[i].dead) players[i].ct = 0; | |
247 | } | |
248 | } | |
249 | } | |
250 | main() { | |
251 | //SIMPLY CHANGE VARIABLES TO CHANGE THE BATTLE SETTINGS :) However, you will need to change a LOT of variables for one player.. | |
252 | player players[6]; | |
253 | srand(time(0)); | |
254 | setup_player(players); | |
255 | battle(players); | |
256 | } |