Write your question here.
Hey. Im working on a text adventure game and Im not sure if the way Im doing it is the best. Basically in the beginning you can choose to be 2 sides, either evil or good and the story for both of them are different. so I have 2 classes. one for the story and the options you can pick in good, and one for the same reason in evil. And then in main I just have the switch case and stuff like that, but I got one problem for some odd reason. My switch case does not recognize a function that I wrote in my header file. You will first see my Main.cpp, then my header and then my class.pp. Thank you :)
#include "GoodSide.h"
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
cout << "\tWelcome to my text adventure game\n" << endl;
cout << "Please enter your characters Name: ";
string name;
cin >> name;
cout << "\nWelcome " << name << endl;
GoodSide GoodSideObject;
GoodSideObject.SideChoice();
int answer;
do
{
cin >> answer;
if (answer != 1 && answer != 2)
cout << "That is not a valid Number.\n " << endl;
}
while (answer != 1 && answer != 2);
switch(answer){
case 1:
PartOneStory();
break;
}
Header:
#ifndef GOODSIDE_H
#define GOODSIDE_H
#include <iostream>
usingnamespace std;
class GoodSide
{
public:
GoodSide();
void SideChoice();
void PartOneStory();
};
#endif
Class.cpp:
#include "GoodSide.h"
#include <iostream>
usingnamespace std;
GoodSide::GoodSide()
{
cout << "\n\n*Use Numbers To Pick An Option* " << endl;
}
void GoodSide::SideChoice(){
cout << "\nPlease choose the side you would like to play in - ";
cout << "\n[1] The Good\n\n[2] The Evil" << endl;
}
void PartOneStory(){
cout << "You chose the good side. Let the game begin\n " << endl;
cout << "You are located in a city named after the warrior who saved it from the evil\nmany years ago. The city of Redshore. " << endl;
cout << "You are no ordinary man in the City of Redshore. You are the king who rules it\nYou are seen as King of Justice, a good king.\nOne who only want what is best for his people" << endl;
cout << "but also a troubled man. You experienced something traumatizing when you\nwere a just a little boy, but no one knows about it,\nno one but yourself that is " << endl;
}
PartOneStory() is a member function, not a global function. You need to have an instance of your class to call it from.
By the way, just a heads up: this design will not work very well. I would consider a design that uses polymorphism and which does not need a different function for each part of the story.
I know that this structure is not the best, but I started learning c++ less than a week ago, I dont think I can handle the polymorphism? I mean, isnt it okay for a beginner to do it like this and then when done take it to the next level?
Also thank you very much everyone who wrote, it worked <3
Then I will take your warning to heart, and after Im done with this one use polymorphism or whatever :D thank you very much <33
(just a question, is it okay if I like add you on skype or something, just incase Something goes horrible wrong? I would love to be able to have someone to ask, would help alot)