Source Code For Text-based Game

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.


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace 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;
            }else if (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;

        }else if(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;

        }else if(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;

        }else if(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 () ;
        }else if (randStr == 1) {
        so.scenario_b ();

        }else if (randStr == 2) {
        so.scenario_c ();

        }else if (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.
OH NO! my computer and/or 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.
It's not weird..It is because you have no error checking with your input. And asdf is not a char..
Topic archived. No new replies allowed.