-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (87 loc) · 2.42 KB
/
main.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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int playerHP[4] = {100, 100, 100, 100};
int round = 1;
bool notSuicide;
bool done = false;
int attackWho;
while (!done)
{
//Menu for each round
cout << endl << "Round " << round << ": FIGHT!" << endl << endl;
for (int i = 0; i < 4; i++)
{
//Extra: HP bar
string hpBar;
for (int h = 0; h < playerHP[i]; h += 2)
{
hpBar += "#";
}
string npcOrYou;
if (i == 0)
{
npcOrYou = "(You!)";
}
else
{
npcOrYou = "(NPC) ";
}
cout << "Player " << i << " " << npcOrYou << " HP: " << playerHP[i] << "\t" << hpBar << endl;
}
notSuicide = false;
while (!notSuicide)
{
cout << endl << "Who do you want to attack? ";
cin >> attackWho;
if (attackWho != 0)
{
playerHP[attackWho] -= 5;
cout << endl << "You attack player " << attackWho << " for 5 damage." << endl;
notSuicide = true;
}
else
{
cout << "You can't attack yourself. Pick again!" << endl;
}
}
//NPC's turn
for (int i = 1; i < 4; i++)
{
//Extra: Don't attack self? Theoretical infinite loop?
notSuicide = false;
while (!notSuicide)
{
attackWho = rand() % 4;
if (i != attackWho)
{
notSuicide = true;
}
}
if (playerHP[i] > 0 && playerHP[attackWho] > 0)
{
playerHP[attackWho] -= 5;
cout << "Player " << i << " attacks player " << attackWho << " for 5 damage!" << endl;
}
}
//Check if user is dead or all npcs are dead.
if (playerHP[1] <= 0 && playerHP[2] <= 0 && playerHP[3] <= 0)
{
cout << "ALL NPCs are dead!" << endl;
done = true;
}
else if (playerHP[0] <= 0)
{
cout << "You died!" << endl;
done = true;
}
round++;
cout << endl << "---------------------------------------------------------------------" << endl;
}
return 0;
}