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
|
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(void);
int main(void){
srand(time(NULL)); //sets the seed of the random number generator to be the system time
int rand1to100 = rand() % 100 + 1; //Random number generator between 1-100
string enemyname = "Bat"; //Will be taken via pointer in future
int player_health = 50; //will be taken via pointer in future
int enemy_health = 10; //Will be taken via pointer
int battle_decision; //Records selcted battle choice
int strong_attack_dmg;
int weak_attack_dmg;
int enemy_attack_dmg = 2;
int temp_attack_dmg;
cout << "You Have Entered a Battle with a " << enemyname << " it has " << enemy_health << "HP" << endl;
cout << "What would you like to do:- \n (1) Strong Attack \n (2) Weak Attack \n (3) Block \n (4) Help \n :-";
while (player_health >= 1){
rand1to100 = rand() % 100 + 1;
cin >> battle_decision;
cout << endl;
if (battle_decision == 4) {
cout << "A strong attack has the potential to inflict significant damage \n on the enemy and can break through if an enemy is blocking, \n however has a higher 'MISS' chance than weak attack.\n \n"; cout << "Weak attack is garunteed a hit but will deal less damage.\n \n"; cout << "Block has a high chance to negate all damage from enemy \n \n";
}
/* Essentially, the strong attack will have a 75% Hit chance,
but deal more damage, based on a random number generator, 7-10 base damage(can be increased depending upon weapon)
(This replaces the need for dice rolls). A Weak attack is a garunteed hit however will deal less damage 3-6 (base attack)
Enemies will be doing either Strong, or Weak attacks also, if the palyer chooses block, then there is a 90% chance it will negate all enemy damage*/
if (battle_decision == 1){
if (rand1to100 <= 75){ //if random number generator above generates a number below 60 then the attack hits and a number between 7-10 is generated, if above 60 the attack misses
rand1to100 = rand() % 100 + 1;
strong_attack_dmg = rand() % 4 + 7; //generates random number between 7-10
cout << "You hit the " << enemyname << " for " << strong_attack_dmg << "HP" << endl;
enemy_health = enemy_health - strong_attack_dmg;
if (enemy_health <= 0){ cout << "You have killed the " << enemyname << endl; system("pause"); return(0); }
cout << "The " << enemyname << " now has " << enemy_health << "HP" << endl;
if (rand1to100 <= 70) {
rand1to100 = rand() % 100 + 1;
player_health = player_health - enemy_attack_dmg;
cout << "The " << enemyname << " hit you for " << enemy_attack_dmg << " HP" << endl;
cout << "You have " << player_health << " HP" << endl;
}
else {
temp_attack_dmg = 1.5*enemy_attack_dmg;
player_health = player_health - temp_attack_dmg;
cout << "The " << enemyname << " hit you for " << temp_attack_dmg << " HP" << endl;
temp_attack_dmg = 0;
cout << "You have " << player_health << " HP" << endl;
}
}
else{
rand1to100 = rand() % 100 + 1;
cout << "You have missed!" << endl;
if (rand1to100 <= 70) {
rand1to100 = rand() % 100 + 1;
player_health = player_health - enemy_attack_dmg;
cout << "The " << enemyname << " hit you for " << enemy_attack_dmg << " HP" << endl;
cout << "You have " << player_health << " HP" << endl;
}
else {
temp_attack_dmg = 1.5*enemy_attack_dmg;
player_health = player_health - temp_attack_dmg;
cout << "The " << enemyname << " hit you for " << temp_attack_dmg << " HP" << endl;
temp_attack_dmg = 0;
cout << "You have " << player_health << " HP" << endl;
}
}
}
if (battle_decision == 2){
weak_attack_dmg = rand() % 4 + 3;
enemy_health = enemy_health - weak_attack_dmg;
cout << "You hit the " << enemyname << " for " << weak_attack_dmg << "HP" << endl;
if (enemy_health <= 0){ cout << "You have killed the " << enemyname << endl; system("pause"); return(0); }
cout << "The " << enemyname << " now has " << enemy_health << "HP" << endl;
if (rand1to100 <= 70) {
rand1to100 = rand() % 100 + 1;
player_health = player_health - enemy_attack_dmg;
cout << "The " << enemyname << " hit you for " << enemy_attack_dmg << " HP" << endl;
cout << "You have " << player_health << " HP" << endl;
}
else {
temp_attack_dmg = 1.5*enemy_attack_dmg;
player_health = player_health - temp_attack_dmg;
cout << "The " << enemyname << " hit you for " << temp_attack_dmg << " HP" << endl;
temp_attack_dmg = 0;
cout << "You have " << player_health << " HP" << endl;
}
}
if (battle_decision == 3){
if (rand1to100 <= 90) {
rand1to100 = rand() % 100 + 1;
cout << "You sucessfully blocked the attack" << endl;
}
else {
if (rand1to100 <= 70) {
rand1to100 = rand() % 100 + 1;
player_health = player_health - enemy_attack_dmg;
cout << "The " << enemyname << " hit you for " << enemy_attack_dmg << " HP" << endl;
cout << "You have " << player_health << " HP" << endl;
}
else {
temp_attack_dmg = 1.5*enemy_attack_dmg;
player_health = player_health - temp_attack_dmg;
cout << "The " << enemyname << " hit you for " << temp_attack_dmg << " HP" << endl;
temp_attack_dmg = 0;
cout << "You have " << player_health << " HP" << endl;
}
}
}
if (battle_decision != 1,2,3,4){
cout << endl << "Choose between the following:- \n (1) Strong Attack \n (2) Weak Attack \n (3) Block \n (4) Help" << ":- " << endl;
}
}
cout << "You have Died" << endl;
system("pause");
return(1);
}
|