Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- void showTitle(), letsPlay(), pauseOutput();
- int whichSide(int charType), weaponDmgFunction(int weaponDmg), armorGivenFunction(int totalHealth);
- int playorQuit = 0, charType, weaponDmg = 0, charArmor, totalHealth, enemyHealth = 100, userChoice, enemyAttack, deathCounter = 0;
- int battleMenu(int userChoice), i, k = 0, userRemainingHP, continueFight(int j), j, a, b, gameOver(), defendAttack, defendRand;
- int attackOption(int enemyRemainingHP), enemyRemainingHP, attackUser(int userRemainingHP), attackFunctionHealth(int userRemainingHP);
- int main()
- {
- do
- {
- showTitle();
- } while (playorQuit != 2);
- cin.get();
- return 0;
- }
- void letsPlay()
- {
- int remainingHealth = totalHealth;
- string playerName;
- cout << "\nHello! What is your name? \n";
- cin >> playerName;
- cout << "\nWelcome to the fight " << playerName << "! Let's get started. \n";
- charType = whichSide(charType);
- weaponDmg = weaponDmgFunction(weaponDmg);
- if (charType == 1) //berserker
- {
- cout << "\nYou have chosen to be a Berserker!\n";
- cout << "You notice a greatsword stuck in the ground. You pull with all your strength.\n"
- "It slides out easily. The earth quakes.\n"
- "You have been bestowed with the legendary Greatsword of Cuyamaca.\n"
- "It has an attack damage of " << weaponDmg << ".\n";
- }
- if (charType == 2) //tank
- {
- cout << "\nYou have chosen to be a Tank!\n";
- cout << "You notice a dusty chest in the middle of the darky-lit room. You advance.\n"
- "Inside of the chest lies an ancient crossbow.\n"
- "It has an attack damage of " << weaponDmg << ".\n";
- }
- totalHealth = armorGivenFunction(totalHealth);
- if (charType == 1)
- {
- cin.clear();
- pauseOutput();
- cout << "\Cuyamaca smiles upon you today. You are gifted with the royal armor of the family of Cuyamaca.\n"
- "May you prove yourself to the royal family.\n"
- "You fit in easily into the armor. It's lightweight, which allows you to handle the greatsword with ease.\n"
- "Your total health & armor points is " << totalHealth << ".\n";
- }
- if (charType == 2)
- {
- cin.clear();
- pauseOutput();
- cout << "\nYou find that the 'traitorous' family of Grossmont have left you very advanced, heavy armor.\n"
- "You struggle to put it on, but get acclimated to the weight very quickly. \n"
- "Your total health & armor points is " << totalHealth << ".\n";
- }
- cin.clear();
- pauseOutput();
- cout << "You find a hidden trap door. You're feeling adventurous. You slowly descend down the ladder.\n"
- "You can barely see. However, you see a faint light off in the distance. You start to make your way towards it.\n"
- "You start to hear creatures squirming around.\n"
- "Suddenly...\n";
- cin.clear();
- pauseOutput();
- cout << "\nA STRANGE CREATURE APPEARS. It lunges forward at you! You barely dodge its attack.\n";
- userRemainingHP = attackUser(userRemainingHP);
- do
- {
- userChoice = battleMenu(userChoice);
- } while (enemyRemainingHP > 0 && userRemainingHP >0);
- do
- {
- j = continueFight(j);
- } while (j == 1 && userRemainingHP > 0);
- if (j != 1)
- {
- int gold = deathCounter * 10;
- cout << "\nCongratulations on your victories today! You've been awarded " << gold << " pieces of gold!\n";
- }
- }
- int continueFight(int j)
- {
- ++deathCounter;
- cout << "\nNice job! So far you've destroyed " << deathCounter << " enemies!\n"
- "Would you like to continue fighting?\n1. Yes\n2. No\n\n";
- cin.clear();
- cin >> j;
- if (j == 1)
- {
- k = 0;
- enemyHealth += enemyHealth + (enemyHealth*.15);
- cout << "\nYou make your way down the pitch-dark cave. The light in the distance doesn't seem to be getting any closer.\n"
- "A STRANGER CREATURE APPEARS. It tries to bite you! You dodge its bite attack.\n";
- do {
- do
- {
- userChoice = battleMenu(userChoice);
- } while (enemyRemainingHP > 0 & userRemainingHP > 0);
- break;
- } while (j == 1);
- }
- return j;
- }
- int whichSide(int charType)
- {
- cout << "\nFirst things first. What type of character would you like?\n1. Berserker\n2. Tank\n3. More info\n\n";
- cin >> charType;
- switch (charType)
- {
- case 1: //berserker
- break;
- case 2: //tank chosen
- break;
- case 3: //more info
- cout << "\n1. Berserkers have high attack damage, but low health.\n2. Tanks have very high health & armor, but low on damage.\nWhich would you like to choose?\n";
- cin >> charType;
- break;
- default: cout << "Please choose one of the available options\n";
- break;
- } //end of switch
- return charType;
- }
- int weaponDmgFunction(int weaponDmg)
- {
- if (charType == 1) //berserker
- {
- srand(time(0));
- int weaponDmg = 50 + (rand() * (80 - 50) / RAND_MAX);
- return weaponDmg;
- }
- if (charType == 2) //tank
- {
- srand(time(0));
- int weaponDmg = 25 + (rand() * (45 - 25) / RAND_MAX);
- return weaponDmg;
- }
- }
- int armorGivenFunction(int totalHealth)
- {
- if (charType == 1)
- {
- srand(time(0));
- int totalHealth = 150 + (rand() * (200 - 150) / RAND_MAX);
- return totalHealth;
- }
- if (charType == 2)
- {
- srand(time(0));
- int totalHealth = 250 + (rand() * (300 - 250) / RAND_MAX);
- return totalHealth;
- }
- }
- int enemyAttackFunction(int enemyAttack)
- {
- if (a == 0)
- {
- enemyAttack = 25;
- ++a;
- return enemyAttack;
- }
- if (a > 0)
- {
- enemyAttack = enemyAttack + (enemyAttack*.07);
- ++a;
- return enemyAttack;
- }
- }
- int battleMenu(int userChoice)
- {
- cout << "\nWhat would you like to do?\n1. Attack\n2. Defend\n3. Drink Potion\n\n";
- cin >> userChoice;
- switch (userChoice)
- {
- case 1://attack
- userRemainingHP = attackFunctionHealth(userRemainingHP);
- break;
- case 2://defend
- srand(time(0));
- defendRand = rand() & 11 + 1;
- userRemainingHP = attackUser(userRemainingHP);
- int blockedAttack;
- blockedAttack = userRemainingHP - defendAttack;
- enemyAttack = enemyAttackFunction(enemyAttack);
- if (defendRand >= 8)
- {
- defendAttack = enemyAttack - (enemyAttack*.75);
- cout << "\nYou grab your shield and manage to withstand most of the blow.\n"
- "You only get hit with " << defendAttack << " damage.\n"
- "Your remaining health is " << blockedAttack << ".\n";
- }
- if (defendRand == 7)
- {
- defendAttack = enemyAttack * 0;
- cout << "\nYou manage to dodge their attack entirely!\n"
- "Your remaining health is " << blockedAttack << ".\n";
- }
- if (defendRand >= 1 && defendRand < 7)
- {
- defendAttack = enemyAttack - (enemyAttack*.25);
- cout << "\nYou were too slow. However you still somewhat protected yourself\n"
- "You take total damage of " << defendAttack << ".\nYour remaining health is " << blockedAttack << ".\n";
- }
- if (userRemainingHP <= 0)
- {
- gameOver();
- }
- break;
- case 3://potion
- if (userRemainingHP > (totalHealth - (totalHealth*.15)))
- {
- cout << userRemainingHP;
- cout << totalHealth;
- int drinkPotion = (totalHealth*.15);
- userRemainingHP = attackUser(userRemainingHP);
- cout << "\nYou take a sip of a health-regenerating potion.\n"
- "\nYou gain " << drinkPotion << " healthpoints.\n"
- "\nYour total health is now " << userRemainingHP + drinkPotion << ".\n";
- }
- else
- {
- cout << userRemainingHP;
- cout << totalHealth;
- cout << "\nYour health is not low enough to drink a potion!\n";
- }
- break;
- }
- return userChoice;
- }
- int attackFunctionHealth(int userRemainingHP)
- {
- enemyRemainingHP = attackOption(enemyRemainingHP);
- cout << "\nYou decide to attack the creature! You manage to to successfuly land an attack.\n"
- "You hit them for a total of " << weaponDmg << " hitpoints!\n";
- cout << "\nThe enemy has " << enemyRemainingHP << "/" << enemyHealth << " hitpoints left.\n";
- enemyAttack = enemyAttackFunction(enemyAttack);
- userRemainingHP = attackUser(userRemainingHP);
- cout << "\nThe enemy attacks you for a total of " << enemyAttack << " hitpoints. Your remaining health is " << userRemainingHP << ".\n";
- if (userRemainingHP <= 0)
- {
- gameOver();
- }
- return userRemainingHP;
- }
- int gameOver()
- {
- cout << "\n\nOH NO YOU'VE DIED!\n";
- return EXIT_SUCCESS;
- }
- int attackUser(int userRemainingHP)
- {
- if (b == 0)
- {
- userRemainingHP = totalHealth - enemyAttack;
- ++b;
- return userRemainingHP;
- }
- if (b > 0)
- {
- userRemainingHP = userRemainingHP - enemyAttack;
- ++b;
- return userRemainingHP;
- }
- }
- int attackOption(int enemyRemainingHP)
- {
- if (k == 0)
- {
- enemyRemainingHP = enemyHealth - weaponDmg;
- ++k;
- return enemyRemainingHP;
- }
- if (k > 0)
- {
- enemyRemainingHP = enemyRemainingHP - weaponDmg;
- ++k;
- return enemyRemainingHP;
- }
- }
- void pauseOutput()
- {
- cout << "\nPress enter to continue.\n";
- cin.ignore();
- cin.clear();
- cin.get();
- }
- void showTitle()
- {
- int runDebugger;
- cout << "\n -------- WELCOME TO CODE DUNGEON -------- "
- "\n Press enter to continue \n";
- cin.get();
- cout << "\nPlease choose one of the following options \n";
- cout << "1. Play \n2. Quit \n";
- cin >> playorQuit;
- switch (playorQuit)
- {
- case 1:
- letsPlay();
- break;
- case 2: cout << "\nGoodbye!\n";
- cin.get();
- break;
- case 99: //run secret test
- cout << "Would you like to run the debugger?\n1. Yes\n2. No\n";
- cin >> runDebugger;
- if (runDebugger == 1)
- {
- cout << "Running debugger...\n";
- cin.get();
- }
- break;
- default: cout << "Please choose one of the available options. \n";
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement