Adventure style text based game

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
#include <string>
#include <iostream>
int main()
{
    std::string response;

    std::cout<<"Your flashlight begins to flicker, would you like to continue or go back?"<<std::endl;
    getline(std::cin, response);

    if (response == "go back")
    {
        std::cout<<"The door you came from is blocked, you must continue..."<<std::endl;
        getline(std::cin, response);
    }

    if (response == "continue")

     {
       std::cout<<"Your walking for some time,until you soon reach a split..."<<std::endl;
       std::cout<<"Will you go left or right?"<<std::endl;
       getline(std::cin, response);
       }

        if (response == "left")

        {
            std::cout<<"You continue to walk to run into a steel door, you hear noises behind it!"<<std::endl;
            std::cout<<"You quickly turn around and run!"<<std::endl;
            std::cout<<"When you get to where the split used to be it has disapeared"<<std::endl;
            std::cout<<"You wake up in a cold sweat, it was a nightmare..."<<std::endl;
            std::cout<<"THE END"<<std::endl;
            getline (std::cin, response) ;
        }


        else if (response == "right")

        {
         std::cout<<"You see a light and the end of the hallway, but hear something approaching from behind you..."<<std::endl;

            std::cout<<"You stop in the middle of the hallway..."<<std::endl;
            std::cout<<"You can either turn around, or continue walking..."<<std::endl;
            getline (std::cin, response);
        }
            if (response == "turn around")

            {
             std::cout<<"You turn around and see a large shadow, you begin to faint and  fall back and hit your head."<<std::endl;
             std::cout<<"You wake up in a cold sweat and realize it was a nightmare..."<<std::endl;
             std::cout<<"The End"<<std::endl;
             getline (std::cin, response);
            }
             else if (response == "Continue Walking")

             {
              std::cout<<"You continue walking a reach a small wooden door."<<std::endl;
              std::cout<<"You are able to kick the door down, and inside is a large room with many doors"<<std::endl;
              getline (std::cin, response);
             }

              {
                  std::cout<<"There are five doors, 1 doors you will survive if you enter. The other 4 door you will die..."<<std::endl;
                  std::cout<<"Pick a one through five and hope you choose the right one"<<std::endl;
                  getline (std::cin, response);
              }
if (response == "one")

{
    std::cout<<"You open the first door, and see a light at the far end of the room..."<<std::endl;
    std::cout<<"You take a step into the room and the ground feels soft."<<std::endl;
    std::cout<<"You try to pull your legs up and soon realize its quick sand"<<std::endl;
    std::cout<<"You wake up in a cold sweat and realize it was a nightmare..."<<std::endl;
    getline (std::cin, response);
}
 else if (response == "two")
{
    std::cout<<"You open the second door theres a large chair in the middle of the room..."<<std::endl;
    std::cout<<"You walk into the second door and inspect the chair, its empty but theres a backpack in the chair."<<std::endl;
    std::cout<<"The bag contains a pistol with 1 bullet"<<std::endl;
    std::cout<<"The room does not contain an exit so you go to check the other rooms."<<std::endl;
    std::cout<<"You enter the fifth room and see a door on the other side of it. You go through the door and see a man."<<std::endl;
    std::cout<<"You can shoot him, or try to get his attention..."<<std::endl;
    getline (std::cin, response);
}
if (response == "shoot him")
{
    std::cout<<"You aim the gun at the back of his head, and shoot."<<std::endl;
    std::cout<<"The bullet passes through his head like a ghost, he turns around and slowly paces towards you."<<std::endl;
    std::cout<<"You try and run but the door you entered has dissapeared, he then continues to kill you."<<std::endl;
    std::cout<<"You wake up in a cold sweat and realize it was a nightmare..."<<std::endl;

}
else if (response == "get his attention")
{
    std::cout<<"He turns around and greets you, and says 'Hello'"<<std::endl;
    std::cout<<"You ask where you are, and he says he dosent know then dissapears."<<std::endl;
}
 if (response == "three")
{
    std::cout<<"The door knob was locked, so you kick in the door."<<std::endl;
    std::cout<<"The floor on the other side of the door is false so you fall through the floor and die."<<std::endl;
    std::cout<<"You wake up in a cold sweat and realize it was a nightmare..."<<std::endl;
}


else if (response == "four")
{
    std::cout<<"The door is already cracked open."<<std::endl;
    std::cout<<"You push the door open with your foot."<<std::endl;
    std::cout<<"Theres a women banging on the door opposite of you, she pulls a knife and stabs you..."<<std::endl;
    std::cout<<"You wake up in a cold sweat and realize it was a nightmare..."<<std::endl;
}

if (response == "five")


{
    std::cout<<"Theres a door, you open it and its an empty room, you walk through it to the other side exiting the room..."<<std::endl;
    std::cout<<"When you go through the second door you see a man, and turn around going back to the room with the five doors..."<<std::endl;
    std::cout<<"You look in the second room, and find the bag with the pistol!"<<std::endl;
    std::cout<<"You return to the fifth room where the man was."<<std::endl;
}




}

Im not finished, but what could i do to improve it, or is what ive done pretty good so far? Thanks for the feedback!
Last edited on
Im not finished, but what could i do to improve it, or is what ive done pretty good so far? Thanks for the feedback!


I don't think there is a way improving this game, because this game only has input string and output "cout", so there is no way to improve it.

You have to only work on a story and to avoid more typing you can use namespace "std"
, so in future, since you will almost always type "std::", you don't have to type std:: anymore...

You have to only work on a story and to avoid more typing you can use namespace "std"
, so in future, since you will almost always type "std::", you don't have to type std:: anymore...


Don't do any of this. Keep using std:: to save yourself massive pain in the future. Soon you'll get used to it and it would be as if you werent writing it at all.
I made a reply to someone who wrote a very similar style game before.

See my response in this thread:

http://www.cplusplus.com/forum/beginner/121532/#msg661754
A way that you can ensure that your program doesn't mess up if a user types it not exactly how you want it (like you say "choose left or right" and they type "Right". Your program will not accept this), is by converting the answers to lower-case, and removing the space.. I'm not sure if you are able to remove spaces in a string, but I'm pretty sure that there's a built-in function or method that can allow you to make the response lower case. You can change it to upper case too.
You know, instead of typing all those std::' statements, you could just write these 4 at the top, next to your #include's

1
2
3
4
using std::cout;
using std::cin;
using std::endl;
using std::string;


by default, i always include all of these in my standard program files. Did you know, i've done a similar project like you before? Except I had task numbers. It was a huge success.
Last edited on
Runner, could you elaborate more on the task number thing? I haven't messed with this code at all I've been busy, but I'm waiting to learn how to make a nicer looking program cause this one is quite messy and frankly not great...
By task numbers I mean This: Suppose after each question, you created a list: labeled through, say one to three, with each number representing a task that could be done at that stage. Instead of using getline for directly writing each task, you could just use cin >> tasknumber; to get input a lot faster. It's a lot more convenient as people make spelling errors, and that may lead to unintentional errors. Hope this helps. :)
Last edited on
Topic archived. No new replies allowed.