Me and a friend are writing our first text based game in C++, and we've recently started to code the save/load functions which work as we want them too.
The problem is saving the current progress of the story. We planned on using goto checkpoint[int] to go straight to your saved story progress, but realised that goto couldn't be used with variables. Are there any alternatives to creating a "Checkpoint", that can then be recalled from a variable from load.
Well, I will be completely guessing as to how you designed the game, but assuming you have a player object, lets say you give them a checkpoint data member and each time they reach a certain checkpoint in the game you update that checkpoint to say, checkpoint 2 or whatever, signifying their progress in the game. When the game is saved and you write out the data, you would simply write out the checkpoint number and when the game was loaded you would read in the checkpoint number. If each checkpoint starts at a specific function, then during initializing the game you would determine which function to call based on the check point number, say:
But the game is like: You start in the story, then the main function home(); can be placed anywhere in the story to return home, when you leave your house you continue your story again.
Would there be any other way? Without having to specify each checkpoint?
You start in the story, then the main function home(); can be placed anywhere in the story to return home, when you leave your house you continue your story again.
So the checkpoints are not predefined? Hmm... How are you placing the function home() anywhere in the story? I need a little more info. How does a player save their game and quit? Considering its text based, at certain points in the game you probably will need to ask if the user wants to continue, unless you plan on using an API to handle a close event. Are you hardcoding all the dialogue, story, etc... in your source code or are you reading in text files?
Sorry if I am unclear, here is a little piece of it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//---------------- THIEF ADVENURE --------------------------------//
thief:
getch();
cout << "Walki1ng the streets of Suno you see your brother from a distance, you wave for him but he doesn't notice you. You track his steps to see where he's travelling.\n\nA gang of men begin pushing Peter around the alley asking him to drop what he's got.\n\n";
getch();
cout << "A descision needs to be made...\n - 1, Leave your brother in hope that he escapes. He didn't know you were there to help anyway.\n - 2, Pull your blade on one of the men urging them to stop before you cut his penis off.\n\n";
cout << "Choice number : "; cin >> Choice;
switch(Choice){
case 1:
cout << "You flee the scene, he didn't even share his fruit pastels with you last week anyway.\n\n";
break;
case 2:
cout << "The men slowly back away smiling. 'I didn't need your help', Peter laughs. He gives you some fruit pastels for your good deed.\n\n";
give(1); //Fruities
break;
}
home();
home() is predefined in the source, so the player cannot just g home untill it is called, when you "leave home", the function ends and you return to the point in the story where it was called.
I guess I'm still not understanding. I see a theif: label so you must be using gotos, which is bad. Can I see the contents of the home() function since that is the origin of everything right, you have to leave home each time to continue the story?