Created
August 10, 2015 12:13
-
-
Save kiliankoe/644780a57e1cbb9fc85c to your computer and use it in GitHub Desktop.
Monster Hunter - My first program ever. A game, written by a 14 year old me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Monster Hunter | |
Kilian Koeltzsch | |
started 07.02.2006 | |
Changelog: | |
v1 Entire game written and compiled, works like a charm | |
v1.1 Added the Build Village function. Fixed a few typos and one bug. | |
v1.2 Added magic attacks (more will come) and the shop to buy items (only health refills for now) | |
v1.3 Bug fixes and mana potions available at shop | |
v1.4 Monsters drop money (1-20), magic books in shop, bugfix (magicLevel added up after every fight) | |
v1.4.1 Shop Code rewritten to use switch instead of an if statement. Therefore it can be located in its own function (doesn't need to call on main() anymore) | |
*/ | |
#include <iostream> | |
#include <ctime> | |
#include <string> | |
using namespace std; //What is this?? | |
//Declaring the global variables | |
int money = 100, playerHealth, strength, vitality, agility, level = 1, villageAmount = 0, mana = 50, magicLevel = 2; | |
int monHealth, monStrength, monLevel; | |
string monName; | |
int skillPoints = 100, extraDamage = 0; | |
//The introduction text | |
void introduction() | |
{ | |
cout << "Welcome to Monster Hunter" << endl; | |
cout << "---------------------------" << endl; | |
cout << "This is a simple, but fun game" << endl; | |
cout << "in which you are trying to" << endl; | |
cout << "become the most powerful" << endl; | |
cout << "warrior in the world." << endl << endl; | |
cout << "I strongly suggest that you" << endl; | |
cout << "read the readme.txt! Thanks!" <<endl << endl; | |
cout << "v1.41" << endl; | |
} | |
//A pause function | |
void game_pause() | |
{ | |
string input = ""; | |
getline(cin, input); | |
} | |
//A function to clear the screen | |
void clear() | |
{ | |
system("clear"); | |
} | |
//The function containing the entire shop | |
void shop() | |
{ | |
shop: | |
cout << "Welcome to the shop!" << endl; | |
cout << "Here you can buy things that aid you on your quest." << endl; | |
cout << "Just select from the menu below." << endl; | |
cout << "Press anything else to leave the shop." << endl << endl; | |
cout << "Your money: " << money << endl << endl << endl; | |
int shopSelect; | |
cout << "1. Health Potion (cost: 50)" << endl; | |
cout << "2. Mana Potion (cost: 50)" << endl; | |
cout << "3. Magic Book (cost: 125)" << endl; | |
cout << "4. SOLD OUT FOR NOW " << endl; | |
cout << "5. Steel Sword (cost: 300)" << endl; | |
cout << "\n"; | |
string input = ""; | |
getline(cin, input); | |
shopSelect = atoi(input.c_str()); | |
switch (shopSelect) { | |
case '1': | |
if (money < 50) { | |
cout << "Sorry, you don't have enough money for that." << endl; | |
pause(); | |
clear(); | |
goto shop; | |
} | |
money -= 50; | |
playerHealth = 100 * vitality * 2; | |
cout << "Your health has been refilled." << endl; | |
pause(); | |
clear(); | |
break; | |
case '2': | |
if (money < 50) { | |
cout << "Sorry, you don't have enough money for that." << endl; | |
pause(); | |
clear(); | |
goto shop; | |
} | |
money -= 50; | |
mana += 50; | |
cout << "You have gained 50 mana points."; | |
pause(); | |
clear(); | |
break; | |
case '3': | |
if (money < 125) { | |
cout << "Sorry, you don't have enough money for that." << endl; | |
pause(); | |
clear(); | |
goto shop; | |
} | |
money -= 125; | |
magicLevel += 1; | |
cout << "Your magic level is now " << magicLevel << endl; | |
pause(); | |
clear(); | |
break; | |
case '4': | |
cout << "Sorry, that item is currently sold out."; | |
pause(); | |
clear(); | |
break; | |
case '5': | |
if (money < 300) { | |
cout << "Sorry, you don't have enough money for that." << endl; | |
pause(); | |
clear(); | |
goto shop; | |
} | |
money -= 300; | |
extraDamage += 50; | |
cout << "You will now deal 50 extra damage with every sword attack." << endl; | |
pause(); | |
clear(); | |
break; | |
} | |
} | |
int main() | |
{ | |
bool exit = false; | |
//Get a random seed for the random number | |
srand(time(0)); | |
introduction(); | |
game_pause(); | |
//This loop is for the skillPoints menu | |
do { | |
clear(); | |
cout << "You have " << skillPoints << " points that you can put in either strength, vitality and agility."; | |
cout << "\n" << skillPoints << " points left. How many points do you want to put in strength?"; | |
cin >> strength; | |
/* | |
if (strength = 1337) { | |
cout << "Your points have been spent as the game sees fit." << endl; | |
strength = 65; | |
vitality = 30; | |
agility = 5; | |
pause(); | |
goto done; | |
} | |
*/ | |
cout << "\n" << (skillPoints - strength) << " points left. How many points do you want to put into vitality?"; | |
cin >> vitality; | |
cout << "\n" << (skillPoints - strength - vitality) << " points left. How many points do you want to put into agility?"; | |
cin >> agility; | |
} while ((strength + vitality + agility) != skillPoints); //All skillPoints have to be spent | |
//A check for negative or too many points has to be implemented here! | |
done: | |
playerHealth = 100 + vitality * 2; | |
//This loop does it all | |
while (!exit) { | |
string choice; | |
main: | |
clear(); | |
cout << "***MENU***" << endl << endl; | |
cout << "[L]ook at my stats" << endl; | |
cout << "[F]ight a monster" << endl; | |
cout << "[B]uild a village" << endl; | |
cout << "[S]hop" << endl; | |
cout << "[E]xit the game" << endl << endl; | |
getline(cin, choice); | |
cout << choice; | |
clear(); | |
//Evaluating the main menu | |
if (choice == "L" || choice == "l") { | |
cout << "These are your stats" << endl << endl; | |
cout << "Level: " << level << endl; | |
cout << "Health: " << playerHealth << "/" << ( 100 + vitality * 2 ) << endl; | |
cout << "Mana: " << mana << endl; | |
cout << "Magic Level: " << magicLevel << endl; | |
cout << "Strength: " << strength << endl; | |
cout << "Vitality: " << vitality << endl; | |
cout << "Agility: " << agility << endl << endl; | |
cout << "Money: " << money << endl; | |
cout << "Villages: " << villageAmount << endl << endl; | |
cout << "Damage you can deal:" << endl; | |
cout << "Slash: " << strength << "-" << ( strength * 2 ) << " damage" << endl; | |
cout << "Stab: " << ( strength + 1 ) << " damage and a " << agility << "% chance of dealing a critical hit" << endl; | |
cout << "Fireball: " << ( mana * ( magicLevel / 2 ) ) << " damage" << endl; | |
pause(); | |
} | |
if (choice == "F" || choice == "f") { | |
monLevel = rand()%100+1; | |
if (monLevel <= 55) { | |
monName = "Imp"; | |
monHealth = 50; | |
monStrength = 5; | |
} | |
else if (monLevel > 55 && monLevel <= 85) { | |
monName = "Werewolf"; | |
monHealth = 120; | |
monStrength = 15; | |
} | |
else { | |
monName = "Dragon"; | |
monHealth = 200; | |
monStrength = 25; | |
} | |
monHealth += level * 5; | |
monStrength += level * 2; | |
while (playerHealth > 0 && monHealth > 0) | |
{ | |
fight: | |
clear(); | |
cout << monLevel << endl << endl; | |
int damage; | |
string fightChoice = ""; | |
cout << "Your health: " << playerHealth << endl; | |
cout << "Your mana: " << mana << endl; | |
cout << "Monster: " << monName << endl; | |
cout << "Monster Level: " << monLevel << endl; | |
cout << "Monster Health: " << monHealth << endl; | |
cout << "Monster Damage: " << monStrength << "-" << ( monStrength * 2 ) << endl << endl; | |
cout << "Which attack do you choose?" << endl; | |
cout << "1. Slash (" << strength << "-" << ( strength * 2 ) << " damage)" << endl; | |
cout << "2. Stab (" << agility << "% chance of dealing a critical hit)" << endl; | |
cout << "3. Fireball (Cost: 25 Mana; " << ( mana * ( magicLevel / 2 ) ) << " damage)" << endl; | |
getline(cin, fightChoice); | |
clear(); | |
if (fightChoice == "1") { | |
damage = rand()%strength + 1; | |
damage += strength; | |
damage += extraDamage; | |
} else if (fightChoice == "2") { | |
damage = strength + 1; | |
int random = rand()%100 + 1; | |
if (random <= agility) { | |
damage *= 5; | |
cout << "Critical Hit!" << endl; | |
} | |
damage += extraDamage; | |
} else if (fightChoice == "3") { | |
damage = mana * (magicLevel / 2); | |
if (mana < 25) { | |
cout << "Sorry, you don't have enough mana for that." << endl; | |
pause(); | |
clear(); | |
goto fight; | |
} | |
mana -= 25; | |
} else { | |
continue; | |
} | |
monHealth -= damage; | |
cout << "You dealt " << damage << " damage to the " << monName << "." << endl; | |
if (monHealth > 0) { | |
damage = rand()%monStrength + 1; | |
damage += monStrength; | |
playerHealth -= damage; | |
cout << "The " << monName << " dealt " << damage << " damage to you."; | |
pause(); | |
clear(); | |
} | |
//Anybody dead? | |
if (playerHealth <= 0) { | |
cout << "Sorry, but you have died." << endl; | |
cout << "You died at level " << level << "." << endl; | |
exit = true; | |
pause(); | |
} else if (monHealth <= 0) { | |
cout << "Good job! You have defeated the " << monName << "!" << endl; | |
cout << "You are now at level " << ++level << "!" << endl << endl; | |
int droppedMoney; | |
droppedMoney = rand()%20 + 1; | |
money += droppedMoney; | |
cout << "The monster seems to have dropped " << droppedMoney << " money." << endl; | |
//Heal the player every 5 levels | |
if ((level % 5) == 0) { | |
playerHealth = 100 * vitality * 2; | |
mana += 50; | |
cout << "\n\nYour health has been restored and you have received 50 mana points!"; | |
} | |
strength++; | |
vitality++; | |
agility++; | |
playerHealth++; | |
pause(); | |
} | |
} | |
} else if (choice == "B" || choice == "b") { | |
playerHealth -= 20; | |
strength += 5; | |
villageAmount++; | |
cout << "You now have " << villageAmount << " villages."; | |
game_pause; | |
} else if (choice == "S" || choice == "s") { | |
shop(); | |
} else if (choice == "E" || choice == "e") { | |
exit = true; | |
} else { | |
cout << "That wasn't a legal choice, please try again."; | |
pause(); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment