// RPG Style C++
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
// Setting up Classes
vector<string> class1;
class1.push_back("Sword");
class1.push_back("Breastplate");
class1.push_back("Sheild");
vector<string>::iterator myIterator;
vector<string>:: const_iterator iter;
vector<string> class2;
class2.push_back("Bow & Arrow");
class2.push_back("Leather Chaps");
class2.push_back("Daggger");
vector<string>::iterator myIterator2;
vector<string>:: const_iterator iter2;
vector<string> class3;
class3.push_back("Staff");
class3.push_back("Cloak");
class3.push_back("Book of Spells");
vector<string>::iterator myIterator3;
vector<string>:: const_iterator iter3;
//Output Classes
cout << "Please choose a Class.\n";
cout << "\n\nClass1:\n";
for(iter = class1.begin(); iter != class1.end(); ++iter)
cout << *iter << endl;
cout << "\nClass2:\n";
for(iter2 = class2.begin(); iter2 != class2.end(); ++iter2)
cout << *iter2 << endl;
cout << "\nClass3:\n";
for(iter3 = class3.begin(); iter3 != class3.end(); ++iter3)
cout << *iter3 << endl;
// Selecting Class
string choice;
cout << "\n\nWhich class would you like to use?\n";
cin >> choice;
if(choice == "Class1")
{
cout << "You've selected Swordsmans.\n";
}
if(choice == "Class2")
{
cout << "You've selected Specialist.\n";
}
if(choice == "Class3")
{
cout << "You've selected Mage.\n";
}
// User's Name
string name;
cout << "Enter you Name:\n";
cin >> name;
// Storyboard
// Brother
cout << "\n\nIt is now time to begin your journey";
cout << "\n\nHey, " << name << " come down quick!";
cout << "Check out the televison.\n";
cout << "The king is looking for a warrior. " << endl;
cout << "He said he'll give a reward to the best." << endl;
cout << "Your a great warrior\n";
cout << "You should go.";
//Narration
// Inventory Given
cout << "\nOn your way out, Your brother gave you\n";
if(choice == "Class1")
for(iter = class1.begin(); iter != class1.end(); ++iter)
cout << *iter << endl;
if(choice == "Class2")
for(iter2 = class2.begin(); iter != class2.end(); ++iter2)
cout << *iter2 << endl;
if(choice == "Class3")
for(iter3 = class3.begin(); iter != class3.end(); ++iter3)
cout << *iter3 << endl;
// Stadium Entry
cout << "\n\nYou make it to the Arena, and there are over 100 warriors\n";
cout << "*Bump*\n";
cout << "Stranger: HEY WATCH!!";
cout << "What is that? Are you in the competition.\n";
cout << "You?!? You can't win! Some of the best are here.\n";
cout << "Kid, let me save you the trouble, just go home.\n";
cout << "You ignore him and put your name in the entry.\n";
cout << "As the tournement continues,";
cout << "You see that this isn't a place for boys.\n";
cout << "Your name is Drawn and your fighting Lancelot.\n";
cout << "The rules are simple, last one staning....WINS.\n";
// Given the Directions to fight
cout << "\n\nTo fight your are given 3 moves based on your class.\n";
cout << "Both you are the enemy have 100 hitpoints.\n";
cout << "First one to zero, loses.\n";
srand(time(0));
// Class1
int slash = rand();
int stab = rand();
int lunge = rand();
// Class2
int shortrange = rand();
int longrange = rand();
int dart = rand();
// Class3
int fireball;
int freeze;
int heal;
int hit = rand();
int hitpoints = 100;
int life = 100;
// Attack
if(choice == "Class1")
{
while(hitpoints > 1)
{
char move;
cout << "Would you like to Slash(s) Strike(t) or Lunge(l)\n";
cin >> move;
if(move == 's' || move == 'S')
{
int slash =rand() % 30 + 1;
life = (life - slash);
cout << "You hit a " << slash << endl;
cout << "Lancelot has " << life << " hitpoints left." << endl;
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
if(move == 't')
{
int stab = rand() % 15 + 1;
life = (life - stab);
cout << "You hit a " << stab << endl;
cout << "Lancelot has " << life << " hitpoints left." << endl;
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
if(move == 'l' || move == 'L')
{
int lunge =rand() % 25 + 1;
life = (life - lunge);
cout << "You hit a " << lunge << endl;
cout << "Lancelot has " << life << " hitpoints left." << endl;
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
}
}
if(choice == "Class2")
{
while(hitpoints > 1)
{
char move1;
cout << "What would you like to do Fireball(f) Heal (h) Freeze (r)";
cin >> move1;
if (move1 == 'f' || move1 == 'F')
{
int fireball = rand() % 20 + 1;
life = (life - fireball);
cout << "You hit a " << fireball << endl;
cout << "Lancelot has " << life << "hitpoints left.\n";
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
if (move1 == 'h' || move1 == 'H')
{
int heal = (rand() % 10) + 5;
hitpoints = (hitpoints + heal);
cout << "You healed your self, you have " << hitpoints << "hitpoints\n";
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
if(move1 == 'r' || move1 == 'R')
{
int freeze = rand() % 35 + 1;
life = (life - freeze);
cout << "You hit " << freeze << endl;
cout << "Lancelot has " << life << "hitpoints left.\n";
int hit = rand() % 40 + 1;
hitpoints = (hitpoints - hit);
cout << "Lancelot has hit " << hit << endl;
cout << "You have " << hitpoints << "hitpoints left." << endl;
}
}
}
system("pause");
return 0;
}
The program keeps crashing everytime, I use Class2
Full disclosure; even when valgrind pointed out the bad line to me and informed me that it was trying to read uninitialised memory, it still took me bloody ages :)