Does anyone think this would be a decent system for a text-based RPG? I'm just starting to learn C++ so any constructive criticism is welcome. :)
Please note that I am planning to add a variable to hold the player's name, and to randomly generate the player's stats.Code://Program: Role-Playing Game
//Programmer: MartinThatcher
//Programming Date: 9/10/09
#include <iostream>
#include <string>
using namespace std;
int main()
{
int choice = 0, workHours = 0, upgradeChoice = 0, trainingChoice = 0;
int attack = 10, defense = 10, gold = 500, pay = 0;
int combatExperience = 0, defenseExperience = 0;
int swordLevel = 1, combatTraining = 0;
int shieldLevel = 1, defenseTraining = 0;
int swordCost = 0, shieldCost = 0;
int combatCost = 0, defenseCost = 0;
int combatPtsNeeded = 0;
int defensePtsNeeded = 0;
cout << "\t\t\tWelcome to Role-Playing Game!";
while(true)
{
cout << "\n\nAttack: " << attack << "\nDefense: " << defense
<< "\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:
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";
}
break;
case 2:
swordCost = swordLevel * 100;
shieldCost = shieldLevel * 100;
cout << "Welcome to the Shop!\n";
cout << "What would you like to upgrade?\n\n1 - Sword\n2 - Shield\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 != 1 && upgradeChoice != 2
|| gold < swordCost || gold < shieldCost)
{
cout << "You have entered an illegal value, or you do not have enough money.\n\n";
}
break;
case 3:
combatCost = attack * 10;
defenseCost = defense * 10;
combatTraining = swordLevel * 5;
defenseTraining = shieldLevel * 5;
cout << "Welcome to the dojo!\nHow would you like to train?\n\n";
cout << "1 - Combat\n2 - Defense\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 < 1 || trainingChoice > 2
|| gold < combatCost || gold < defenseCost)
{
cout << "You have entered an illegal value, or you do not have enough money.\n\n";
}
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;
}
}
}
I apologize if this isn't in the right section. It seemed like a sensible section to place it in, though.