This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
190 lines (155 loc) · 4.61 KB
/
Copy pathmain.cpp
File metadata and controls
190 lines (155 loc) · 4.61 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
#include <iostream>
#include <chrono>
#include <thread>
#include "src/actions/Attack.h"
#include "src/entities/Battler.h"
#include "src/actions/Heal.h"
#include "src/actions/Recover.h"
using namespace std;
bool battleActive = true;
Battler player("PLAYER", 100, 100);
Battler enemy("ENEMY", 100, 100);
Attack melee("PUNCH", 5, 12, 0, 90);
Attack magic("MAGIC", 15, 20, 15, 70);
Attack darkMelee("BITE", 8, 14, 0, 80);
Attack darkMagic("DARK MAGIC", 17, 22, 15, 60);
Heal heal("HEAL", 15, 25, 20);
Heal bigHeal("BIG HEAL", 30, 50, 35);
Heal maxHeal("SUPER HEAL", 70, 100, 50);
Recover recover("MEDITATE", 10, 15);
Recover zenZone("ZEN ZONE", 20, 30);
//------------------------//
// Basic Battle Functions //
//------------------------//
// Cause the battle to cease and provide a message depending on the victor
void EndBattle(Battler& winner)
{
cout << winner.getName() << " wins!";
battleActive = false;
}
//-----------------------//
// Enemy action selector // //TODO: Clear this fucking shit up oh my god
//-----------------------//
void EnemyTurn()
{
int enemyActions[] = {1,2,3,4};
// Enemy avoids magic if they don't have enough MP
if (enemy.getMp() < darkMagic.getMpCost())
enemyActions[1] = 0;
if (enemy.getMp() < heal.getMpCost())
enemyActions[2] = 0;
// Avoids healing if high HP
if (enemy.getHp() > 70)
enemyActions[2] = 0;
// Avoids meditating if high MP
if (enemy.getMp() > 20)
enemyActions[3] = 0;
int enemyAction = 0;
while (enemyAction == 0)
{
if (int rng = enemyActions[rand() % size(enemyActions)]; rng != 0)
{
enemyAction = rng;
break;
}
}
switch (enemyAction)
{
case 1: darkMelee.use(enemy, player);
break;
case 2: darkMagic.use(enemy, player);
break;
case 3: heal.use(enemy);
break;
case 4: recover.use(enemy);
break;
default:
cout << "Enemy action failed! (" << enemyAction << ")" << endl << endl;
}
}
//-----------//
// Menu area //
//-----------//
void BattleMenu()
{
while (battleActive)
{
cout << "----------" << endl;
cout << player.getName() << endl;
cout << "HP: " << player.getHp() << endl;
cout << "MP: " << player.getMp() << endl;
cout << "----------" << endl << endl;
cout << "----------" << endl;
cout << enemy.getName() << endl;
cout << "HP: " << enemy.getHp() << endl;
cout << "MP: " << enemy.getMp() << endl;
cout << "----------" << endl << endl;
this_thread::sleep_for(chrono::seconds(1));
cout << "1. Attack" << endl;
cout << "2. Magic (Cost: 15MP)" << endl;
cout << "3. Heal (Cost: 20MP)" << endl;
cout << "4. Recover" << endl << endl;
cout << "Your choice: ";
int action;
while (!(cin >> action))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid input! Please enter a number: ";
}
system("cls");
switch (action)
{
case 1:
melee.use(player, enemy);
break;
case 2:
magic.use(player, enemy);
break;
case 3:
heal.use(player);
break;
case 4:
recover.use(player);
break;
case 69420: // Secret amazing attack
cout << "YOU used LIGHT THAT BURNS MY EYES!" << endl;
this_thread::sleep_for(chrono::seconds(2));
cout << ".";
this_thread::sleep_for(chrono::seconds(1));
cout << ".";
this_thread::sleep_for(chrono::seconds(1));
cout << ".";
this_thread::sleep_for(chrono::seconds(1));
cout << "!";
this_thread::sleep_for(chrono::seconds(1));
for (int i = 0; i < 100; i++) {
cout << endl;
for (int j = 0; j < 100; j++)
cout << "#####";
}
exit(-1);
default:
cout << "Invalid Action!" << endl;
continue;
}
if (!enemy.isAlive())
EndBattle(player);
this_thread::sleep_for(chrono::seconds(1));
if (battleActive)
EnemyTurn();
this_thread::sleep_for(chrono::seconds(1));
if (!player.isAlive())
EndBattle(enemy);
}
}
//------------------//
// Game start & end //
//------------------//
int main()
{
srand(time(nullptr));
BattleMenu();
system("pause");
return 0;
}