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
|
#include <iostream>
#include <cstdlib>
#include <limits>
using namespace std;
struct fighters {
string name;
int health;
int health_max;
int mana;
int mana_max;
int level;
int xp;
int strength;
int endurance;
int agility;
int intelligence;
int dmg_max;
int dmg_min;
} player, nonplayer;
int damageroll (int min, int max) {
srand(time(NULL));
int random_int = -1;
while ( random_int < min ) {
random_int = (rand()%max);
}
return (random_int);
}
fighters post_fight(fighters a) {
if (a.xp > 10 ) {
cout << "Congrats on leveling up! You are now level "<< a.level++ << "!\n";
a.mana = a.mana + 5;
a.mana_max = a.mana_max + 5;
a.xp = a.xp - 10;
a.strength = a.strength + 1;
a.endurance = a.endurance + 1;
a.agility = a.agility + 1;
a.intelligence = a.intelligence + 1;
a.dmg_min = a.strength;
a.dmg_max = a.strength * 2;
a.health = a.health + 10;
a.health_max = a.endurance * 10;
}
int rest;
rest = damageroll(1,10);
cout << "You rest for a bit and gain " << rest << " HP and MP\n";
a.mana = a.mana + rest;
if (a.health > a.health_max ) { a.health = a.health_max; }
if (a.mana > a.mana_max ) { a.mana = a.mana_max; }
a.health = a.health + rest;
cout << "\nCurrent stats: "
<< "\nHealth: " << a.health << "/" << a.health_max << "\tMana: "<< a.mana << "/" << a.mana_max
<< "\nStrength: " << a.strength << "\t\tMax damage: " << player.dmg_max
<< "\nAgility: " << a.agility << "\t\tMin damage: " << player.dmg_min
<< "\nIntelligence: " << a.intelligence ;
return (a);
}
int combat_move() {
cout << "\nWhat would you like to do?\n"
<< "1. Attack\t\t3. Rest\n"
<< "2. Magic\t\t4. Retreat\n";
int move;
cin >> move;
return (move);
}
fighters fight(fighters a, fighters b) {
int move;
int dmg;
cout << b.name << " comes into view, it is level " << b.level;
while (a.health > 0 && b.health >0 ) {
cout << "\nYou have "<< a.health <<" health left, and " << a.mana <<" mana left.";
cout << "\n" << b.name << " has " << b.health << " health remaning.";
move = combat_move();
switch (move) {
case 1:
dmg = damageroll(a.dmg_min, a.dmg_max);
b.health = b.health - dmg;
cout << "You hit the " << b.name << " for "<< dmg <<"!\n";
break;
case 2:
dmg = damageroll((a.dmg_min - a.dmg_min) , a.dmg_max + 2);
if (a.mana > 0) {
b.health = b.health - dmg;
a.mana--;
cout << "You cast magic! for " << dmg << "!\n";
}
else { cout << "You're out of mana!\n";}
break;
case 3:
post_fight(a);
break;
case 4:
cout << "\n"<< b.name << " snorts and lets you leave.\n";
return(a);
}
dmg = damageroll(b.dmg_min, b.dmg_max);
a.health = a.health - dmg;
cout << b.name << " hits you for " <<dmg <<"!\n";
}
if ( a.health > 0 ) {
cout << "\n" << b.name << " has been defeated.\nHero " << a.name
<<" You have " << a.health << " health left.\n" << endl;
a.xp = a.xp + b.xp;
cout << "You have gained " << b.xp <<" experience.\n";
}
else { cout << "\n You have died... \n"; }
return(a);
}
fighters generateenemy (int difficulty) {
string namepool[10] = { "Goat", "Wolf", "Lion", "Kobold", "Bear", "Angry Rob", "Big Goat", "Hard to see Mosquito", "Slime" ,"Ogre"};
nonplayer.name = namepool[difficulty - 1];
nonplayer.health = difficulty * 10;
nonplayer.mana = difficulty * 10;
nonplayer.level = difficulty;
nonplayer.xp = difficulty * 2;
nonplayer.dmg_min = difficulty + 1;
nonplayer.dmg_max = (difficulty * 2) + 1;
return nonplayer;
}
int main () {
int difficulty;
cout << "Welcome to the battlegame, Cause stuff\n"
<< "by John 4/29/12 - First attempt at a game\n\n";
cout << "Please enter your name: ";
getline (cin, player.name);
player.mana = 10;
player.mana_max = 10;
player.level = 1;
player.xp = 1;
player.strength = 5;
player.endurance = 5;
player.agility = 5;
player.intelligence = 5;
player.dmg_min = player.strength;
player.dmg_max = player.strength * 2;
player.health = player.endurance * 10;
player.health_max = player.endurance * 10;
do {
cout << "\n\nEnter difficulty (1-10) or 0 to exit: ";
cin >> difficulty;
player = fight(player, generateenemy(difficulty));
player = post_fight(player);
} while ( difficulty > 0 && player.health > 0 );
cout << "\n\nThanks for playing \n";
return 0;
}
|