Okay, I'll see what I can do with classes once I learn about them.
If you're interested, here's the updated code:
Code:
//Program: Role-Playing Game
//Programmer: Jeremy Hansen
//Programming Date: 9/10/09
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int gold = 500, workHours = 0, pay = 0;
int choice = 0, upgradeChoice = 0, trainingChoice = 0;
int attack = 10, defense = 10, hitPoints = 0, magic = 0, accuracy = 0;
int combatExperience = 0, defenseExperience = 0, accuracyExperience = 0, magicExperience = 0;
int swordLevel = 1, combatTraining = 0;
int shieldLevel = 1, defenseTraining = 0;
int bowLevel = 1, staffLevel = 1;
int accuracyTraining = 0, magicTraining = 0;
int swordCost = 0, shieldCost = 0, bowCost = 0, staffCost = 0;
int combatCost = 0, defenseCost = 0, accuracyCost = 0, magicCost = 0;
int combatPtsNeeded = 0;
int defensePtsNeeded = 0;
int accuracyPtsNeeded = 0;
int magicPtsNeeded = 0;
int charClass = 0;
char recreate = 'n';
string charName = "";
int charCreation()
{
srand(time(0));
while (recreate == 'n')
{
cout << "\n\nName Thyself: ";
cin >> charName;
cout << "Choose a class: Press '1' for Warrior, '2' for Ranger, or '3' for Mage.\n";
cin >> charClass;
switch (charClass)
{
case 1:
hitPoints = rand() % 50 + 50;
attack = rand() % 15 + 5;
defense = rand() % 15 + 5;
magic = rand() % 5 + 5;
accuracy = rand() % 5 + 10;
cout << "Name: " << charName << endl;
cout << "Class: Warrior\n";
cout << "HP: " << hitPoints << endl;
cout << "ATK: " << attack << endl;
cout << "DEF: " << defense << endl;
cout << "MGK: " << magic << endl;
cout << "ACC: " << accuracy << endl;
cout << "\nIs this information correct? (y/n) ";
cin >> recreate;
if (recreate != 'n' && recreate != 'y')
{
cout << "\nYou have entered an invalid character.";
recreate = 'n';
}
break;
case 2:
hitPoints = rand() % 50 + 50;
attack = rand() % 15 + 5;
defense = rand() % 15 + 5;
magic = rand() % 5 + 5;
accuracy = rand() % 20 + 20;
cout << "Name: " << charName << endl;
cout << "Class: Ranger\n";
cout << "HP: " << hitPoints << endl;
cout << "ATK: " << attack << endl;
cout << "DEF: " << defense << endl;
cout << "MGK: " << magic << endl;
cout << "ACC: " << accuracy << endl;
cout << "\nIs this information correct? (y/n) ";
cin >> recreate;
if (recreate != 'n' && recreate != 'y')
{
cout << "\nYou have entered an invalid character.";
recreate = 'n';
}
break;
case 3:
hitPoints = rand() % 20 + 30;
attack = rand() % 5 + 5;
defense = rand() % 5 + 5;
magic = rand() % 50 + 50;
accuracy = rand() % 20 + 20;
cout << "Name: " << charName << endl;
cout << "Class: Mage\n";
cout << "HP: " << hitPoints << endl;
cout << "ATK: " << attack << endl;
cout << "DEF: " << defense << endl;
cout << "MGK: " << magic << endl;
cout << "ACC: " << accuracy << endl;
cout << "\nIs this information correct? (y/n) ";
cin >> recreate;
if (recreate != 'n' && recreate != 'y')
{
cout << "\nYou have entered an invalid character.";
recreate = 'n';
}
break;
default:
cout << "You have entered an invalid number.\n\n";
system("pause");
return 0;
}
}
}
void work()
{
cout << "\n\nHow long would you like to work? (eight-hour maximum) ";
cin >> workHours;
pay = workHours * 100;
if (workHours > 8)
{
workHours = 8;
}
if (workHours >= 1)
{
cout << "\n\nYou worked for " << workHours
<< " hour(s) and earned " << pay << " gold piece(s)!\n\n";
gold += pay;
}
else
{
cout << "You did not work.\n\n";
}
}
void shop()
{
swordCost = swordLevel * 100;
shieldCost = shieldLevel * 100;
bowCost = bowLevel * 100;
staffCost = staffLevel * 1000;
cout << "\nWelcome to the Shop!\n";
cout << "What would you like to upgrade?\n\n1 - Sword\n2 - Shield\n3 - Bow\n4 - Staff\n\n";
cin >> upgradeChoice;
if (upgradeChoice == 1 && gold >= swordCost)
{
swordLevel++;
cout << "You paid the blacksmith " << swordCost
<< " gold pieces.\nYour sword has been upgraded to level "
<< swordLevel << "!\n\n";
gold -= swordCost;
}
else if (upgradeChoice == 2 && gold >= shieldCost)
{
shieldLevel++;
cout << "You paid the blacksmith " << shieldCost
<< " gold pieces.\nYour shield has been upgraded to level "
<< shieldLevel << "!\n\n";
gold -= shieldCost;
}
else if (upgradeChoice == 3 && gold >= bowCost)
{
bowLevel++;
cout << "You paid the blacksmith " << bowCost
<< " gold pieces.\nYour bow has been upgraded to level "
<< bowLevel << "!\n\n";
gold -= bowCost;
}
else if (upgradeChoice == 4 && gold >= staffCost)
{
staffLevel++;
cout << "You paid the blacksmith " << staffCost
<< " gold pieces.\nYour staff has been upgraded to level "
<< staffLevel << "!\n\n";
gold -= staffCost;
}
else if (upgradeChoice < 1 || upgradeChoice > 4
|| gold < swordCost || gold < shieldCost
|| gold < bowCost || gold < staffCost)
{
cout << "You have entered an illegal value, or you do not have enough money.\n\n";
}
}
void train()
{
combatCost = attack * 10;
defenseCost = defense * 10;
accuracyCost = accuracy * 10;
magicCost = magic * 10;
combatTraining = swordLevel * 5;
defenseTraining = shieldLevel * 5;
accuracyTraining = bowLevel * 5;
magicTraining = staffLevel * 5;
cout << "\nWelcome to the dojo!\nHow would you like to train?\n\n";
cout << "1 - Combat\n2 - Defense\n3 - Accuracy\n4 - Magic\n\n";
cin >> trainingChoice;
if (trainingChoice == 1 && gold >= combatCost)
{
combatExperience += combatTraining;
combatPtsNeeded = attack * 10 - combatExperience;
cout << "You pay your trainer " << combatCost
<< " gold pieces and train with him.\nYou have earned "
<< combatTraining << " experience points.\n";
cout << "You still need " << combatPtsNeeded
<< " point(s) in order to level up.\n\n";
gold -= combatCost;
if (combatPtsNeeded <= 0)
{
cout << "Congratulations! You have gained an attack level!";
combatExperience = 0;
++attack;
}
}
else if (trainingChoice == 2 && gold >= defenseCost)
{
defenseExperience += defenseTraining;
defensePtsNeeded = defense * 10 - defenseExperience;
cout << "You pay your trainer " << defenseCost
<< " gold pieces and train with him.\nYou have earned "
<< defenseTraining << " experience points.\n";
cout << "You still need " << defensePtsNeeded
<< " point(s) in order to level up.\n\n";
gold -= defenseCost;
if (defensePtsNeeded <= 0)
{
cout << "Congratulations! You have gained a defense level!";
defenseExperience = 0;
++defense;
}
}
else if (trainingChoice == 3 && gold >= accuracyCost)
{
accuracyExperience += accuracyTraining;
accuracyPtsNeeded = accuracy * 10 - accuracyExperience;
cout << "You pay your trainer " << accuracyCost
<< " gold pieces and train with him.\nYou have earned "
<< accuracyTraining << " experience points.\n";
cout << "You still need " << accuracyPtsNeeded
<< " point(s) in order to level up.\n\n";
gold -= accuracyCost;
if (accuracyPtsNeeded <= 0)
{
cout << "Congratulations! You have gained an accuracy level!";
accuracyExperience = 0;
++accuracy;
}
}
else if (trainingChoice == 4 && gold >= magicCost)
{
magicExperience += magicTraining;
magicPtsNeeded = magic * 10 - magicExperience;
cout << "You pay your trainer " << magicCost
<< " gold pieces and train with him.\nYou have earned "
<< magicTraining << " experience points.\n";
cout << "You still need " << magicPtsNeeded
<< " point(s) in order to level up.\n\n";
gold -= magicCost;
if (magicPtsNeeded <= 0)
{
cout << "Congratulations! You have gained a magic level!";
magicExperience = 0;
++magic;
}
}
else if (trainingChoice < 1 || trainingChoice > 4
|| gold < combatCost || gold < defenseCost
|| gold < accuracyCost || gold < magicCost)
{
cout << "You have entered an illegal value, or you do not have enough money.\n\n";
}
}
int main()
{
cout << "\t\t\tWelcome to Role-Playing Game!";
charCreation();
while(true)
{
cout << "\n\nHitpoints: " <<"\nAttack: " << attack << "\nDefense: "
<< defense << "\nAccuracy: " << accuracy << "\nMagic: " << magic
<< "\nGold: " << gold << "\n\n";
cout << "\n\nWhat would you like to do?\n\n";
cout << "1 - Work\n2 - Shop\n3 - Train\n4 - Quit\n\n";
cin >> choice;
switch (choice)
{
case 1:
work();
break;
case 2:
shop();
break;
case 3:
train();
break;
case 4:
cout << "\nGoodbye!\n\n";
system("pause");
return 0;
break;
default:
cout << "You have entered an illegal value.\n\n";
system("pause");
return 0;
}
}
}