So I'm writing a text based RPG using OOP in C++ for a University project. I've designed a class for dealing with the user being in a generic room and taking the relevant input to say, talk to a specific NPC contained in that room. The get_menu_info() function outputs a string of choices, numbered 0 to leave the area, and all other numerical choices in this case would be to talk to NPCs, which are contained in the class for the specific area. I am testing these features with a derived area class, a village in this case.
The village function available_interactions_for_area takes 3 arguments, an integer, an area (base class of village) and a character(base class of player).
In the code below, it is the available_interactions_for_area function that is skipped over, restarting the do - while loop without interacting with anything in the room.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
//file = inputoutput.cpp
int inputoutputhandler::interact_with_area(player& p) {
const area a = p.get_current_area();
cout << a.get_description() <<"\n"<<endl;
bool still_in_area(true);
do {
cout << a.get_menu_info() << endl;
bool check = false;
int answer;
int b = a.get_number_of_room_options();
while (!check)
{
check = true;
cin >> answer;
if (cin.fail()||answer>b)
{
cin.clear();
cin.ignore();
cout << "Please enter one of the given options" << endl;
check = false;
}
}
if (answer == 0) { still_in_area = false; }
else {
//this function doesn't work, and is skipped over
a.available_interactions_for_area(answer, a, p);
}
} while (still_in_area);
return 0;
}
| |
I'm not sure if it's needed, but I will post the function skipped in question also below, just know the talk_to function is an overloaded function from the charcter class and has had no issues in simpler tests. I have outputted a string at the top of the function which does not output when I run the program suggesting to me the function doesn't even initiate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void village::available_interactions_for_area(int i, const area &a, character &p)const {
//checking this function starts
cout << "checking user is inside available interaction function"<<endl;
switch (i) {
case 1:
p.talk_to(p, a.getNPC(0));
break;
case 2:
cout << "another npc would go here but keeping things simple for testing" << endl;
break;
default:
p.talk_to(p, a.getNPC(i-1));
}
};
| |
Any suggestions would be greatly appreciated, cheers.