Help with random text adventure game c++
Posted: Thu Nov 11, 2010 6:52 am
I wanted to see what i can make what i could make with c++ however i did not want to make a game design so i just based it off of the book eragon
heres my code:
every time i make the if statement with {} over characterSelection() and i type new game it just skips it and goes to logout and when i dont put the {} it just skips all the cins and goes to logout please help if you have anymore questions regarding this just ask
Edited by mod: Please use
heres my code:
Code: Select all
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std; // using namespace STD
void characterSelection();
void enemies();
void humans();
void elves();
void dwarves();
void explore();
void save();
void open();
void mainMenu();
vector<string> mMenu;
string race; //global variable for chosing a race in characterSelection()
vector<string> Inventory;
string menuChoose;
int main () // main function
{
mainMenu();
if(menuChoose == "new game")
{
characterSelection();
}
if(menuChoose == "quit")
{
return 0;
}
return 0;
}
void characterSelection()// character selection
{
vector<string> raceSelection;
raceSelection.push_back ("human");
raceSelection.push_back ("elf");
raceSelection.push_back ("dwarf");
cout << "What would you like to be:\n";
for (int i = 0; i < raceSelection.size(); ++i) //displaying the races you can choose from
cout << raceSelection[i] << endl;
cout << "Now type in the name of the race you want to choose and dont use capitals\n";
cin >> race;
cout << "Good choice\n";
cout << "And now to begin\n\n";
save();
if ( race == "human")
{
Inventory.push_back ("worn dagger");
Inventory.push_back ("tatered shirt");
}
if ( race == "dwarf" )
{
Inventory.push_back ("Worn battle axe");
Inventory.push_back ("worn sheild");
Inventory.push_back ("riped pants");
}
cout << "Displaying your inventory\n\n";
for ( int i = 0; i < Inventory.size() ; ++i )
cout << Inventory[i] << endl;
}
void save()// saving game
{
ofstream fout("save.docx");
fout << race << endl;
}
void mainMenu()
{
mMenu.push_back ("New Game");
mMenu.push_back ("Load game");
mMenu.push_back ("quit");
cout << "ERAGON ADVENTURE\n\n\n\n";
cout << "Main Menu\n\n";
for (int i = 0; i < mMenu.size(); ++i)
cout << mMenu[i] << endl;
cout << "What would you like to do (dont use capitals):\n";
cin >> menuChoose;
}
Edited by mod: Please use
Code: Select all
tags.