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
|
#include <iostream>
#include <vector>
#include <cstdlib>
int offenseStats(int offense) {
int offensePoints = rand() % 50 + 50;
return offensePoints;
}
int defenseStats(int defense) {
int defensePoints = rand() % 50 + 50;
return defensePoints;
}
int healthStats(int health) {
int healthPoints = rand() % 50 + 50;
return healthPoints;
}
void computerName() {
std::vector<std::string> computerNames = {"Neloth", "Cicero", "Hamelyn", "Wylandriah", "Knjakr", "Sheogorath", "Paarthurnax", "Hadvar", "Brynjolf", "Brenuin"};;
std::cout<<computerNames[rand() % 10];
}
void computerAttribute() {
std::vector<std::string> attributes = {"strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"};;
std::cout<<attributes[rand() % 10];
}
void characterInfo() {
int userOffense = offenseStats(userOffense);
int userDefense = defenseStats(userDefense);
int userHealth = healthStats(userHealth);
int computerOffense = offenseStats(computerOffense);
int computerDefense = defenseStats(computerDefense);
int computerHealth = healthStats(computerHealth);
if (userHealth < computerHealth) {
std::cout << "\nI would just give up hope now.\n";
}
std::cout << "\nUser offense = " << userOffense << "\n";
std::cout << "User defense = " << userDefense << "\n";
std::cout << "User health = " << userHealth << "\n";
std::cout << "Computer offense = " << computerOffense << "\n";
std::cout << "Computer defense = " << computerDefense << "\n";
std::cout << "Computer health = " << computerHealth << "\n";
}
void userQuestion() {
characterInfo();
std::cout << "\nWhat would you like to do?\n"
" [G]ive up.\n"
" [C]arry on.\n";
std::string userChoice;
std::cin >> userChoice;
while (userChoice != "G" && userChoice != "g" && userChoice != "C" && userChoice != "c") {
std::cout << "Please choose C or G.";
}
if (userChoice == "G") {
std::cout << "\nUnderstandable, have a good day.";
exit(0);
}
else if (userChoice == "g") {
std::cout << "\nUnderstandable, have a good day.";
exit(0);
}
}
int main() {
srand (time(NULL));
int userOffense = offenseStats(userOffense);
int userDefense = defenseStats(userDefense);
int userHealth = healthStats(userHealth);
int computerOffense = offenseStats(computerOffense);
int computerDefense = defenseStats(computerDefense);
int computerHealth = healthStats(computerHealth);
int userHurtHealth = (userHealth - rand() % 30);
int userHurtDefense = (userDefense - rand() % 10);
int userHurtOffense = (userOffense - rand() % 10);
std::string userCharacterName;
std::string userAttribute;
std::string mystr;
std::cout << "Hello, Player, what is your name?\n";
getline (std::cin, mystr);
std::cout << "\nHello, " << mystr << ".\n";
std::cout << "It is pretty sad that your talking to a computer. Is it not "<< mystr <<"?\n ";
std::cout << "Give yourself an attribute.\n"
"(strength, dexterity, constitution, intelligence, wisdom, charisma).\n";
std::cin >> userAttribute;
userQuestion();
while (userHealth > 0 && computerHealth > 0) {
std::cout << "\nYou quickly lunge at your opponent, managing to knock their health down to " << (computerHealth = computerHealth - rand() % 10) << ".\nYou also lowered your offense to " << (userOffense = userOffense - rand() % 10) << ", and your rival's defense to " << (computerDefense = computerDefense - rand() % 10) << "\n";
std::cout << "Your enemy darts at you and knocks your health down to " << (userHealth = userHealth - rand() % 10) << ", while lowering their offense to " << (computerOffense = computerOffense - rand() % 10) << ", and your defense to " << (userDefense = userDefense - rand() % 10) << ".\n";
}
if (userHealth <= 0) {
std::cout << "\nYour opponent has won. Try again next time";
}
else if (computerHealth <= 0) {
std::cout << "\nCongratulations, you won!";
}
else if (userHealth == computerHealth) {
std::cout << "There was a tie!";
}
else {
std::cout << "There was an error!";
}
}
|