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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
|
#include "stdafx.h"
#include <ctime>
#include <iostream>
#include <string>
using namespace std;
void start();
void stats(int hp, int lvl, int dmg, int exp, int money, int weapon);
void whattodo(int hp, int lvl, int dmg, int exp, int money, int weapon);
int battle(int hp, int lvl, int dmg, int exp, int weapon);
int attack(int dmg, int lvl, int exp, int weapon);
int shop(int hp, int lvl, int dmg, int exp, int money, int weapon);
int main()
{
srand((unsigned)time(0));
start();
return 0;
}
void stats(int hp, int lvl, int dmg, int exp, int money, int weapon)
{
string weaponname;
lvl = exp / (lvl*100);
int dmgmax = 0;
int dmgmin = 0;
if(weapon == 1){
weaponname = "Sword";
for(int i = 0; i < 100; i++){
dmg = lvl * (rand() %35 + 2);
if(dmg < dmgmin){
dmgmin = dmg;
}
else if(dmg > dmgmax){
dmgmax = dmg;
}
}
}
else if(weapon == 2){
weaponname = "Mace";
for(int i = 0; i < 100; i++){
dmg = lvl * (rand() %40 + 2);
if(dmg < dmgmin){
dmgmin = dmg;
}
else if(dmg > dmgmax){
dmgmax = dmg;
}
}
}
else if(weapon == 3){
weaponname = "Axe";
for(int i = 0; i < 100; i++){
dmg = lvl * (rand() %50 + 2);
if(dmg < dmgmin){
dmgmin = dmg;
}
else if(dmg > dmgmax){
dmgmax = dmg;
}
}
}
else{
weaponname = "None";
for(int i = 0; i < 100; i++){
dmg = lvl * (rand() %30 + 2);
if(dmg < dmgmin){
dmgmin = dmg;
}
else if(dmg > dmgmax){
dmgmax = dmg;
}
}
}
cout << "Your LVL is: " << lvl << endl;
cout << "Your EXP is: " << exp - lvl*100 << endl;
cout << "Your money is: " << money << endl;
cout << "Your HP is: " << hp << endl;
cout << "Your DMG is between: " << dmgmin << " - " << dmgmax << endl;
cout << "Your weapon is: " << weaponname << endl << endl;
whattodo(hp, lvl, dmg, exp, money, weapon);
}
void whattodo(int hp, int lvl, int dmg, int exp, int money, int weapon)
{
int moneynexp;
int what;
start:
what = 0;
cout << "What would you like to do?\n";
cout << "1 = 'Show stats.'\n";
cout << "2 = 'Battle.'\n";
cout << "3 = 'Shop.'\n";
cout << "4 = 'Quit.'\n";
cin >> what;
cout << endl;
if(what != 1 && what != 2 && what != 3 && what != 4){
cout << "Not a valid answer!\n\n";
goto start;
}
switch(what){
case 1:
stats(hp, lvl, dmg, exp, money, weapon);
break;
case 2:
moneynexp = battle(hp, lvl, dmg, exp, weapon);
exp += moneynexp;
money += moneynexp;
whattodo(hp, lvl, dmg, exp, money, weapon);
break;
case 3:
weapon = shop(hp, lvl, dmg, exp, money, weapon);
whattodo(hp, lvl, dmg, exp, money, weapon);
break;
case 4:
goto end;
break;
default:
cout << "Not a valid answer!\n\n";
goto start;
}
end:
cout << "\nGood bye!\n";
exit(1);
}
int battle(int hp, int lvl, int dmg, int exp, int weapon)
{
int expgaind;
int monster = rand() %4 + 1;
int mhp, mdmg, mlvl;
string monstername;
mlvl = lvl + (rand() %2 + 1) - (rand() %2 + 1);
mhp = mlvl*20;
mdmg = mlvl * (2 + rand() %10);
switch(monster){
case 1:
cout << "A Ogre attacks you...\n";
monstername = "Ogre";
break;
case 2:
cout << "A Goblin attacks you...\n";
monstername = "Goblin";
break;
case 3:
cout << "A Murloc attacks you...\n";
monstername = "Murloc";
break;
case 4:
cout << "A Troll attacks you...\n";
monstername = "Troll";
break;
default:
cout << "Programm fel!\n";
system("pause");
}
attack:
mdmg = mlvl * (2 + rand() %10);
hp -= mdmg;
cout << monstername << " did " << mdmg << " damage to you\n";
cout << "You have " << hp << " HP left\n\n";
if(hp <= 0){
cout << "You died! Game over!\n\n";
expgaind = 0;
start();
}
dmg = attack(dmg, lvl, exp, weapon);
mhp -= dmg;
cout << endl << "You did " << dmg << " damage to " << monstername << endl;
if(mhp <= 0){
cout << "You won!\n\n";
expgaind = 20;
}
else{
cout << monstername << " now has " << mhp << " hp left!\n\n";
goto attack;
}
return expgaind;
}
int attack(int dmg, int lvl, int exp, int weapon)
{
int flee = 0;
int choise;
start:
choise = 0;
cout << "What would you like to do?\n";
cout << "1 = 'Attack'\n";
cout << "2 = 'Try to flee'\n";
cin >> choise;
if(choise != 1 && choise != 2){
cout << "Not a valid answer!\n\n";
goto start;
}
else if(choise == 2){
flee = rand() %100 + 1;
if(flee > 65){
cout << "You did'nt make it..\n\n";
dmg = 0;
}
}
else{
if(weapon == 1){
dmg = lvl * (2 + rand() %35);
}
else if(weapon == 2){
dmg = lvl * (2 + rand() %40);
}
else if(weapon == 3){
dmg = lvl * (2 + rand() %50);
}
else{
dmg = lvl * (2 + rand() %30);
}
}
return dmg;
}
void start()
{
signed int hp, dmg, lvl, money, weapon;
int exp = 100;
string name;
lvl = 1;
lvl = exp / (lvl*100);
hp = lvl*40;
dmg = lvl * (2 + rand() %30);
money = 0;
weapon = 0;
cout << "What do you want your characters name to be? ";
cin >> name;
cout << endl << "Hi " << name << "!\n";
whattodo(hp, lvl, dmg, exp, money, weapon);
}
int shop(int hp, int lvl, int dmg, int exp, int money, int weapon)
{
start:
int sell = 0;
if(weapon != 0){
cout << "\nYou already got a weapon.\n";
cout << "Do you want to sell it?\n";
cout << "1 = 'Yes'\n";
cout << "2 = 'no'\n";
cin >> sell;
if(sell == 1){
if(weapon == 1){
money += 150;
}
else if(weapon == 2){
money += 250;
}
else{
money += 400;
}
weapon = 0;
}
else if(sell == 2){
whattodo(hp, lvl, dmg, exp, money, weapon);
}
else{
cout << "Not a valid answer!\n";
goto start;
}
}
cout << endl << "What would you like to buy?";
cout << endl << "1 = 'Sword'. Cost 200.";
cout << endl << "2 = 'Mace'. Cost 300";
cout << endl << "3 = 'Axe'. Cost 500";
cout << endl << "4 = 'Nothing'.\n";
cin >> weapon;
if(weapon == 1){
if(money < 200){
cout << "\nYou don't have that much money..\n\n";
weapon = 0;
goto start;
}
money -= 200;
}
else if(weapon == 2){
if(money < 300){
cout << "\nYou don't have that much money..\n\n";
weapon = 0;
goto start;
}
money -= 300;
}
else if(weapon == 3){
if(money < 500){
cout << "\nYou don't have that much money..\n\n";
weapon = 0;
goto start;
}
money -= 500;
}
else if(weapon == 4){
cout << endl << "\nFine, dont buy anything and die then!\n\n";
weapon = 0;
}
else{
cout << "\nThat's not a valid answer! Try again.\n";
weapon = 0;
goto start;
}
return weapon;
}
|