For once, when posting in this forum, I have a problem that I actually know how to code around, in fact I might be able to think of two ways to code around it, I'm just not sure which one would be better in the long run and if there's an easier way to do what I'm thinking about.
Some background is in order, I've been trying to learn C++ by writing a text adventure. I've recently finished up the "tutorial level" part of the text adventure that all players go through in my main function and now my plan is to write a series of interlinked functions for each of the separate rooms encased within a while loop until the game ends when the player selects an option in one of the functions that shifts the variable "int chapter_over" from zero to one. The start of what I'm building is below:
Code:
player_choices.chapter_over = 0;
location_reference = 2;
int& chapter_over_reference = player_choices.chapter_over;
while (player_choices.chapter_over != 1)
{
if (location_reference = 2)
{
game_rooms.training_room(game_rooms.hard_knock_conversation_choice_one, game_rooms.examine_locker, game_rooms.spiked_horse_shoes, game_rooms.first_visit, game_rooms.group_conversation_choice_one, game_rooms.group_conversation_choice_two, player_name_reference);
}
}
All well and good so far, though I'm certain I'll have kinks to iron out once I start asking the program to swap between rooms using the reference variable, but that's all just background, I'll get to the point.
I created a class to house all of the room functions like so:
Code:
class rooms
{
public:
rooms();
~rooms();
int examine_locker, spiked_horse_shoes;
int mushroom;
int letter_opener;
int sharp_letter_opener;
int first_visit;
int group_conversation_choice;
void clinic (int wind_conversation_choice_two);
void training_room (int& player_race_reference, int hard_knock_conversation_choice_one, int examine_locker, int spiked_horse_shoes, int first_visit, int group_conversation_choice_one, int group_conversation_choice_two, int* player_name_reference);
void lab (int mushroom, int ura_conversation_choice_one, int spiked_horse_shoes, int letter_opener, int sharp_letter_opener);
void bed_room (int blueblood_conversation_choice, int letter_opener, int sharp_letter_opener);
};
//destructor, constructor and contained functions not shown.
Earlier, I had created a separate class to house all of the functions associated with the various characters in the rooms who the players can ask questions and have conversations with like so:
Code:
class characters
{
public:
characters();
~characters();
int wind_choice_one;
int wind_conversation_choice_one;
int wind_conversation_choice_two;
int wind_opinion;
int ura_conversation_choice_one;
int ura_conversation_choice_two;
int ura_opinion;
int blueblood_conversation_choice_one;
int blueblood_conversation_choice_two;
int blueblood_opinion;
int hard_knock_conversation_choice_one;
int hard_knock_conversation_choice_two;
int hard_knock_opinion;
int wind_actions (int wind_opinion); // okay, so the idea here is that as Wind's oppinion increases, new dialogue options are opened up.
void wind_conversation_one (int wind_conversation_choice_one);
};
//destructor, constructor and contained functions not shown.
Now the problem I've run into is that it's very clear that the way I've got it set up now, all of the variables from the character functions (and now that I really think of it, all of the character functions themselves, because players would be asking the characters questions while they were in the room with them) would have to also appear in the room class.
Now, the separate classes provide an easy more modular way of organizing the functions in my code, but it seems like I'm either going to have to define a metric ton of references in main and then write them into the classes (which now that I'm really thinking about it, probably wouldn't work, because the last time I tried to define a reference in a class my compiler screamed bloody murder at me), but the only other way I can think to solve the problem is to merge the two classes into one super class, which would make my program much harder to edit later on.
I get the sense that a post like this would make many an experienced programmer ram their faces into their desks out of frustration at my stupidity, but I just can't figure out how to do this without making a mega class or tying the two classes together somehow in a really long series of definitions with pointers or references.
So I humbly ask the wise programmers of these forums what they think I should do. Is there a way around making such a mad amalgamation that I just don't know about yet?
I would be very grateful for any advice.