Feel free to add any features onto it. It is just code for text based game and it has been tested just compile it in the GCC compiler and it should work.
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
class scenario;
class scenario {
public:
//Scenario 1
int scenario_a () {
cout << "\n 1";
char a;
cout << "Moving on to next scenario! Enter any key to continue or q to quit and r to retry the last scenario\n.";
cin >> a;
if(a == 'q'){
return 0;
}elseif (a == 'r'){
scenario_a();
}else{
scenario_b ();
}
}
//scenario 2
int scenario_b () {
cout <<"\n 2";
char a;
cout << "Moving on to next scenario! Enter any key to continue or q to quit and r to retry the last scenario\n.";
cin >> a;
if(a == 'q'){
return 0;
}elseif(a == 'r') {
scenario_b();
}else{
scenario_c ();
}
};
//scenario 3
int scenario_c () {
//print scenario out
cout << "\n 3";
char a;
cout << "Moving on to next scenario! Enter any key to continue or q to quit and r to retry the last scenario\n.";
cin >> a;
if(a == 'q'){
return 0;
}elseif(a == 'r') {
scenario_c();
}else{
scenario_d ();
}
}
//scenario 4
int scenario_d () {
//print scenario out
cout << "\n 4";
char a;
cout << "Moving on to next scenario! Enter any key to continue or q to quit and r to retry the last scenario\n.";
cin >> a;
if(a == 'q'){
return 0;
}elseif(a == 'r') {
scenario_d();
}else{
scenario_a ();
}
}
};
int main () {
scenario so;
cout << "Welcome to imagi-ventures! Please use 1, 2, 3, or 4 to select a choice \n Enter q to quit. \n" <<endl;
srand(time(NULL));
int randStr = rand() % 4;
char choice;
cout <<"Pick a scenario: \n 1. ? \n 2. ? \n 3. ? \n 4. ? \n";
cin >> choice;
if (choice == 'q'){
return 0;
}
//When the user enters something it will automatically pick random scenario
if (randStr == 0) {
so.scenario_a () ;
}elseif (randStr == 1) {
so.scenario_b ();
}elseif (randStr == 2) {
so.scenario_c ();
}elseif (randStr == 3) {
so.scenario_d ();
}
}
DISCLAIMER: I am not responsible for any damage that somehow would ever happen to your computer or it's software.
Nice code so far, would love to give it a shot when you get the scenarios filled in. You may want to add in an exception for entries, right now if you put asdf into scenario selection it will open up all four of the scenarios.
Really? Wow that's weird I'll look at it. And I just didn't put any scenarios because I wanted anybody who downloaded it to get creative and add their own stuff and more features. I mainly made it for people new to c++ to get familiar with it and practice. Thanks for the feedback.