-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLast_Samurai.cpp
77 lines (61 loc) · 1.63 KB
/
Last_Samurai.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
#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
int PlayerDamage() {
int playerAttack = (rand() % 22) + 1;
if (playerAttack > 10) {
cout << "Enemy got hit : -" << playerAttack << '\n';
return playerAttack;
}
else {
cout << "You missed the attack\n";
return 0;
}
}
int EnemyDamage() {
int enemyAttack = (rand() % 30) + 1;
if (enemyAttack > 10) {
cout << "You got hit : -" << enemyAttack;
return enemyAttack;
}
else {
cout << "Enemy Missed the attack.";
return 0;
}
}
void DecideWinner(int yourHealth) {
if (yourHealth < 0) {
cout << "You Lose, better luck next time!\n";
}
else {
cout << "Congratulations, You Win!\n";
}
}
int main() {
srand(time(0));
int choice = 0;
int yourHealth = 100,enemyHealth = 100;
cout << "~~~~~~⚔ Last Samurai ⚔~~~~~~\n\n";
do {
cout << "Your Health : " << yourHealth;
cout << "\nEnemy Health : " << enemyHealth;
cout << "\n\n1 - Attack\n2 - Defend\n";
cout << "Enter : ";
cin >> choice;
cout << '\n';
if (choice == 1) {
enemyHealth -= PlayerDamage();
yourHealth -= EnemyDamage();
}
else if (choice == 2) {
cout << "Enemy attacked you.\nBut you defended yourself :)";
}
else {
continue;;
}
cout << "\n\n-----------------------------\n\n";
} while (yourHealth > 0 && enemyHealth > 0);
DecideWinner(yourHealth);
return 0;
}