-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combatmoreeffective.cpp
347 lines (335 loc) · 9.84 KB
/
combatmoreeffective.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
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
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <ctime>
#include <map>
#include <string>
#include <fstream>
#include <io.h>
#include <fcntl.h>
#include <limits>
using namespace std;
bool isfighting = false, isdefeated = false, attackstate = true, keyPressed = false, displaystats = true, gu = true, tobreak = false;
int enemydmg, lastphp, lastenemyhp, ecooldown, timeleft, maxdmg, blockbonus, easeofuse, tickspeed, x, i, z, level, xp, blocked=0, fhit=0;
float cooldown, hp, currenthp, enemyhp, enemyrage, enemyskill, dmgdealt, edmgdealt, plvlbonusdmg, wlvlbonusdmg, enemyblock;
string lastAttack, lastblock, attacker;
map<int, string> attack_map {
{1, "O--|---"},
{2, "-O-|---"},
{3, "--O|---"},
{4, "---I---"},
{5, "---|O--"},
{6, "---|-O-"},
{7, "---|--O"},
{8, "O--|"},
{9, "-O-|"},
{10, "--O|"},
{11, "---I"},
{12, "---X"}
};
int checktime(){
if(timeleft <= 0){
timeleft = ecooldown;
attackstate = false;
system("CLS");
tobreak = true;
}
}
int savingspace(){
string currentattack = attack_map[z];
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << currentattack;
lastAttack = currentattack;
Sleep(tickspeed);
timeleft -= tickspeed;
if(z==7) gu = false;
if(z==1) gu = true;
if(_kbhit()){
char key = _getch();
if(key == 'a'){
gu = false;
tobreak = true;
}
}
checktime();
}
int isattackinge(){
if(attackstate){
tobreak = false;
while(true){
for(z = 0; z<=7 && gu && attackstate && !tobreak; z++) savingspace();
for(z = 6; z>=1 && !gu && attackstate && !tobreak; z--) savingspace();
if(tobreak) break;
}
}
}
int savingspace1(){
string currentdef = attack_map[z];
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << ""+attacker+" is attacking you." << endl;
cout << currentdef;
lastblock = currentdef;
Sleep(tickspeed);
if(_kbhit()){
char key = _getch();
if(key == 'b'){
tobreak = true;
}
}
}
int isdefendinge(){
tobreak = false;
if(!attackstate){
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "Attack incoming...";
Sleep(500);
for(z=7; z<13 && !tobreak; z++) savingspace1();
}
}
int dodisatk(){
for(cooldown=15; cooldown >= 0 && attackstate; cooldown-=1){
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "Last attack: " << lastAttack << endl;
if(x==1){
enemyblock = i;
cout << "\n"+attacker+" blocked " << enemyblock << "% of your dmg";
}
else{
enemyblock = 0;
cout << "\n"+attacker+" didn't dodge your attack.";
}
cout << "\nDamage dealt: " << dmgdealt;
cout << "\nCooldown: " << cooldown/10. << "s";
Sleep(100);
timeleft -= 100;
checktime();
}
}
int checkdef(){
if(lastblock=="O--|"){
edmgdealt = enemydmg*0.75-(enemydmg*0.75*blockbonus/100);
cout << "You blocked 25% of the damage. "+attacker+" dealt " << endl << edmgdealt << " dmg.";
}
else if(lastblock=="-O-|"){
edmgdealt = enemydmg*0.50-(enemydmg*0.50*blockbonus/100);
cout << "You blocked 50% of the damage. "+attacker+" dealt " << endl << edmgdealt << " dmg.";
}
else if(lastblock=="--O|"){
edmgdealt = enemydmg*0.25-(enemydmg*0.25*blockbonus/100);
cout << "You blocked 75% of the damage. "+attacker+" dealt " << endl << edmgdealt << " dmg.";
}
else if(lastblock=="---I"){
edmgdealt = enemydmg*0.;
cout << "You blocked 100% of the damage.";
blocked++;
}
else{
edmgdealt = enemydmg*1.-(enemydmg*1.*blockbonus/100);
cout << "You didn't block any of the damage. "+attacker+" dealt " << endl << edmgdealt << "dmg.";
}
}
int dodisdef(){
for(cooldown=4; cooldown>=0 && !attackstate; cooldown-=1){
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "Last block: " << lastblock << endl;
checkdef();
cout << "\nCooldown: " << cooldown/10. << "s";
Sleep(100);
}
}
int loop(){
while(true){
Sleep(100);
timeleft-=100;
if(timeleft <= 0){
timeleft = ecooldown;
attackstate = false;
break;
}
if(_kbhit()){
char key = _getch();
if(key=='a'){
attackstate = true;
break;
}
}
}
}
bool CheckSave() {
const wstring folderPath = L"save";
DWORD folderAttributes = GetFileAttributesW(folderPath.c_str());
if (folderAttributes == INVALID_FILE_ATTRIBUTES || !(folderAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
if (CreateDirectoryW(folderPath.c_str(), nullptr) == 0 && GetLastError() != ERROR_ALREADY_EXISTS) {
cerr << "[!] Save File Cannot be created!" << endl;
return false;
}
return false;
}
return true;
}
void UlozitInfo(const string& data, const string& fileName) {
const string folderPath = "save";
const string filePath = folderPath + "\\" + fileName;
ofstream file(filePath);
if (file.is_open()) {
file << data;
file.close();
}
else {
cout << "[!] vyskytol sa nejaky problem";
}
}
string PrecitatInfo(const string& fileName) {
const string folderPath = "save";
const string filePath = folderPath + "\\" + fileName;
ifstream file(filePath);
if (file.is_open()) {
string data;
getline(file, data);
file.close();
return data;
}
else {
cout << "[!] vyskytol sa nejaky problem" << endl;
return "";
}
}
void load() {
string strLevel = PrecitatInfo("PlayerLevel.txt");
string strXp = PrecitatInfo("PlayerXp.txt");
string strHp = PrecitatInfo("PlayerHp.txt");
string strCurrenthp = PrecitatInfo("PlayerCurrentHp.txt");
string strMaxdmg = PrecitatInfo("PlayerMaxDmg.txt");
attacker = PrecitatInfo("attacker.txt");
level = stoi(strLevel);
xp = stoi(strXp);
hp = stoi(strHp);
currenthp = stoi(strCurrenthp);
maxdmg = stoi(strMaxdmg);
}
int main(){
load();
if(attacker=="Wolves"){
enemyhp = 20;
enemyrage = 1;
enemydmg = 3;
enemyskill = 1;
}
ofstream outputFile("testsave.txt");
if (!outputFile.is_open()) {
cerr << "Error opening file for writing!" << endl;
return 1;
}
outputFile << "1" << endl;
outputFile.close();
srand((unsigned)time(0));
cout << "Blocking bonus: ";
cin >> blockbonus;
cout << "Ease of Use: ";
cin >> easeofuse;
if(easeofuse<1) easeofuse = 1;
cout << "Player level dmg bonus: ";
cin >> plvlbonusdmg;
cout << "Weapon level dmg bonus: ";
cin >> wlvlbonusdmg;
tickspeed = easeofuse*25;
isfighting = true;
ecooldown = 5000/enemyrage;
timeleft = ecooldown;
while(isfighting){
if(displaystats){
cout << "\nYour stats \n---------------------------- \nYour hp: " << hp << endl << "Your dmg: " << maxdmg << endl << "Ease of use: " << easeofuse << endl << "Dmg bonus from player level: " << plvlbonusdmg << endl << "Dmg bonus from weapon level: " << wlvlbonusdmg << endl << "\n"+attacker+" stats \n---------------------------- \n"+attacker+" hp: " << enemyhp << endl << ""+attacker+" dmg: " << enemydmg << endl;
Sleep(3000);
cout << "\nPress a to begin the fight.";
while(true){
if(_kbhit()){
char key1 = _getch();
if(key1 == 'a') break;
}
}
cout << "\nFight begins...";
Sleep(500);
cout << "\n\nYou are attacking... ";
Sleep(250);
displaystats = false;
}
isattackinge();
isdefendinge();
if(attackstate){
system("CLS");
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "Last attack: " << lastAttack;
if(lastAttack == "O--|---" || lastAttack == "---|--O") dmgdealt = maxdmg*0.5;
else if(lastAttack == "-O-|---" || lastAttack == "---|-O-") dmgdealt = maxdmg*0.75;
else if(lastAttack == "--O|---" || lastAttack == "---|O--") dmgdealt = maxdmg;
else{
dmgdealt = maxdmg+wlvlbonusdmg+plvlbonusdmg;
fhit++;
}
x = (rand()%2)+1;
i = (rand()%15*enemyskill)+1;
if(x==1){
enemyblock = i;
dmgdealt -= dmgdealt*enemyblock/100;
}
enemyhp -= dmgdealt;
if(enemyhp<=0){
system("CLS");
enemyhp = 0;
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "\nDamage dealt: " << dmgdealt << "\n"+attacker+" defeated.";
Sleep(3500);
break;
}
dodisatk();
if(!attackstate) continue;
enemyblock = 0;
i = 0;
x = 0;
dmgdealt = 0;
loop();
}
else{
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "Last block: " << lastblock << endl;
checkdef();
cout << "\nCooldown: 0.5s";
hp -= edmgdealt;
edmgdealt = 0;
if(hp<=0){
hp = 0;
cout << "Your HP: " << hp << " <-> "+attacker+" HP: " << enemyhp << "\n-------------------------------"<< endl << endl;
cout << "You have been defeated. ";
isfighting = false;
isdefeated = true;
Sleep(1500);
break;
}
dodisdef();
timeleft = ecooldown-500;
loop();
}
}
if(!isdefeated){
system("CLS");
cout << "Gained xp and enemy items.";
xp+=10+(lastenemyhp*enemyrage*enemyskill*enemydmg)/(10/(1+(1+blocked)*(1+fhit)));
}
else{
system("CLS");
cout << "Press [placeholder] to load the last save.";
}
outputFile.open("testsave.txt");
if (!outputFile.is_open()) {
cerr << "Error opening file for writing!" << endl;
return 1;
}
outputFile << "0" << endl;
outputFile << xp << endl;
outputFile.close();
}