Still working on it

Still trying to get this game to work, sorry if it's getting old.
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <string>
using namespace std;
int Awakening();
int CenterClearing();
int NorthernClearing();
int SouthernClearing();
int WesternClearing();
int EasternClearing();
int Tent();
int FirePit();
int checkpoint = 0;
int checkpoint1;

int main()
{
    if (checkpoint == 7)
    {
        EasternClearing();
        return 0;
    }
    
    else if (checkpoint < 7)
    {
        int choice1;
        cout << "You are standing in a clearing in the middle of some woods. There is a tent, a fire pit, and a sign nearby.
There are three paths leading away from the clearing: a northern path, a southern path, and a western path.
You feel as though there should be another way to go, but no other path exists.
Contemplating this, you stare off into the east for a few seconds before shaking your head.
You decide that the most important thing right now is to get out of the woods; you can figure out the rest later.\n
What do you do?\n1:Go North\n2:Go West\n3:Go South\n4:Go inside the Tent\n5:Look at the fire pit\n6:Look at the sign\n" << endl;
        cout << checkpoint << endl;
        cin >> choice1;
        if (choice1 == 1)
            NorthernClearing();
        else if (choice1 == 2)
            WesternClearing();
        else if (choice1 == 3)
            SouthernClearing();
        else if (choice1 == 4)
            Tent();
        else if (choice1 == 5)
            FirePit();
        else if (choice1 == 6)
            {
                cout << "The sign is mostly unreadable, most of the map and wording worn by time.
The only readable part is a clearing in the middle of the map, with a campground symbol.
You groan is frustration, as this is the spot you are currently in.\n\n" << endl;
                checkpoint += 1;
                main();
                return checkpoint;
            }
        while (choice1 != 1 && choice1 != 2 && choice1 != 3 && choice1 != 4 && choice1 != 5)
        {
            cout << "That is not an option." << endl;
            cin >> choice1;
            if (choice1 == 1)
                NorthernClearing();
            else if (choice1 == 2)
                WesternClearing();
            else if (choice1 == 3)
                SouthernClearing();
            else if (choice1 == 4)
                Tent();
            else if (choice1 == 5)
                FirePit();
            else if (choice1 == 6)
            {
                cout << "The sign is mostly unreadable, most of the map and wording worn by time.
The only readable part is a clearing in the middle of the map, with a campground symbol.
You groan is frustration, as this is the spot you are currently in.\n\n" << endl;
                checkpoint += 1;
                main();
                return checkpoint;
            }
        }
        
    }
    
}


int Awakening()
{
    cout << "You awaken in a wooded clearing. You don't remember anything before waking up, and decide to look around before going anywhere. You see a tent, fire pit, and a nearby sign.
The are also paths to the north, west, and south.\n What do you do?\n 1: Go north\n 2: Go west\n 3: Go south\n 4: Look at tent\n 5: look at fire pit\n 6: Look at sign\n" << endl;
    checkpoint += 1;
    main();
    return checkpoint;
}

int NorthernClearing()
{
    int choice1;
    cout << "The clearing is surrounded on every side except the one you came from by thick woods. There's a well nearby, and the post for what you guess used to be a sign when this place was still in use.
The path to the well is marred by rends in the dirt, all pointed at the well.\n What do you do?\n 1: Go back\n 2: Look inside the well\n 3: Look at sign\n" << endl;
    cin >> choice1;
    if (choice1 == 1)
        {
            cout << "Deciding against approaching the well for the moment, you decide to go back to the center clearing and try to figure out what to do." << endl;
            main();
            return checkpoint;
        }
    else if (choice1 == 2)
        {
            cout << "You approach the well, which is old, judging by the state of the stones. The wooden beam is splintered, and the rope hanging down frayed with age.
You can hear the sounds of water deep inside the well, along with what you think may be faint splashing noises. You lean in a little more to see what could be making the noise, and start to fall in.
You manage to catch yourself, but something rises from the water and shoots out, grabbing your arm. You grab at the tentacle with your other arm, but reel when you feel the rubbery, slimy skin.
As you pull your arm away, some slime sticks to your hand. You try to shake it off, and another tentacle grabs your second arm.
Before you can react, you are pulled into the well, hitting your head on the bucket as you are pulled into the water.
More tentacles wrap around your torso and start squeezing. Unable to breathe, and feeling your ribs starting to crack, you struggle to get free and swim up, but whatever has you pulls you down lower.
As you begin to lose consciousness, you black out and feel lighter, as if the crushing pressure of the monster has left.
The black turns into white, and you realize that you've been here before as\n\n" << endl;
            checkpoint += 1;
            main();
            return checkpoint;
        }
    else if (choice1 == 3)
        {
            cout << "What sign?" << endl;
            NorthernClearing();
            return checkpoint;
        }
    return checkpoint;
}


int SouthernClearing()
{
    int choice1;
    cout << "The clearing is surrounded on all sides by woods, save the path that led here.
The trees are too close together to pass through, and the way their branches twist towards you makes you feel as though getting too close would be a bad idea.
Aside from the woods, there is little of note.\n What do you do?\n1: Go back\n2: Go towards trees\n\n" << endl;
    cin >> choice1;
    if (choice1 == 1)
        {
            cout << "After scratching your head for several minutes trying to figure out what this area is for, you decide to head back to the center clearing and decide what to do next." << endl;
            main();
            return checkpoint;
        }
    else if (choice1 == 2)
        {
            cout << "Walking towards the trees, you notice that they seem to sway, even though there's no wind blowing.
Shrugging, you decide to go through the trees to try to find a way out. As you approach, the limbs of the trees lean towards you, branches snagging your clothes.
You start running, and you hear a howling noise, like a fierce wind blowing through the woods.
Roots start tripping you, and branches move into your path, hitting your face and arms.
You start to turn left and right, panicking and trying to get away from the trees. As you run deeper into the woods, more roots erupt from the ground, making you fall to the ground.
As you try to get up, roots cover your body, pulling you into the dirt. Sinking fast, you lose consciousness and everything goes black.
You feel like you are swimming inside your head, black turns to white, and you realize you've been here before as\n\n" << endl;
            checkpoint += 1;
            main();
            return checkpoint;
        }
    return checkpoint;
}
Last edited on
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
int WesternClearing()
{
    int choice1;
    cout << "The clearing is surrounded by woods, save for the path you followed to get here. A rundown shack, with its door boarded up, sits in the middle of the clearing.
Deep scratches mar the walls of the shack, getting worse the closer they get to the sides of the shack you can't see from where you are. The window is either blocked or tinted, as you can't see inside.
Benches line one wall of the shack, and there is a backpack at one end of the benches.\nWhat do you do?\n1: Go back\n2: Go around the shack\n3: Look inside backpack\n" << endl;
    cin >> choice1;
    if (choice1 == 1)
        {
            cout << "Deciding that whatever monstrous entity isn't worth whatever might be inside the shop, you turn to head back to the center clearing and decide what to do next." << endl;
            main();
            return checkpoint;
        }
    else if (choice1 == 2)
        {
            cout << "Deciding that whatever made the scratch marks on the shack walls is gone, you start walking towards the other side of the shack, looking for a door or window you can see through.
Looking at the claw marks, you figure that whatever did this is tall, with four claws on each hand, and whatever it is, the beast is unnervingly strong.
Feeling dread creep into your mind like a fog bank on the shore of a lake, you peer around the corner of the shack...\n
and see nothing. Giddy, you laugh at yourself a little and see a door. Going over and turning the knob, you sigh in relief as it opens.
You look inside but see nothing, because the windows are indeed blocked up. Stepping inside and clearing a window, you let in enough light to show that the shack was once a store or an equipment rental station.
Not seeing any giant man-eating bears inside, you decide the creature is gone and start looking around.
You are so preoccupied with looting the store, you do not hear the footsteps of a large, furry, bipedal creature with a snout, fangs the size of a forearm, and four foot-long claws on each paw walk in and spot you.
Turning around, you almost bump into it and it grabs you with one paw, its claws biting into your arm. Lowering its head, it looks at you for several seconds before growling deep in its chest.
It grabs you with the other paw, and starts to squeeze. As its claws dig into your flesh, your bones start creaking under the pressure and you begin to lose consciousness.
Everything goes white, and you realize that you've been here before as\n\n" << endl;
            checkpoint += 1;
            main();
            return checkpoint;
        }
    else if (choice1 == 3)
        {
            cout << "The backpack sits alone on the end of a bench, as if someone put it there expecting to pick it up again soon.
Looking around, you don't see anybody around, and open the backpack. Inside is some standard camping gear, some cans of what probably used to be food, a pack of beef jerky, and a lighter.
The lighter looks new, like someone put it inside the backpack recently after it was left here. You grab the lighter and put it into your pocket, zipping the backpack up and setting it back on the bench." << endl;
            checkpoint += 1;
            WesternClearing();
            return checkpoint;
        }
    return checkpoint;
}


int EasternClearing()
{
    cout << "You wake up in the center clearing just as you have before, but immediately you can feel that there's a difference this time.
Turning to face the east, you stare for a second before realizing that a path has appeared where there was none before.
The pathway opens up, and it seems to call you to it. You can only see a little ways down, as the path is lined with trees on both sides. The trees are thick, blocking your view in either direction.
The path itself is packed dirt, suggesting that it's been here for a long time. Feeling something pull you towards the path, you decide to leave the campgrounds behind and move on.
As you start walking, a cold shiver runs down your back.\n\nTurning around, you see the same path you've been walking down for a while.
Your brow furrows, as you can almost remember something else being there only a short time ago. Shrugging, you continue down the path.
Thinking, you abesntmindedly put your hands in your pockets and feel something inside the left one. Stopping, you pull out a note and a lighter.
The lighter is enscribed with some initials, but they are scratched out and unreadable.
The note looks familiar. As you start to read it, you begin to feel strange, almost as if you remember what the note says happened.
It explains that you have been stuck in the campground for a long time, trying to escape countless times.
Unfortunately, every time you tried to get away, something would happen to stop you. The note does not give you any clue as to who you are, unfortunately, and gives no clues as to where to go next.\n
The only thing the note says is \n
'Congratulations'\n" << endl;
    checkpoint += 1;
    main();
    return checkpoint;
}


int Tent()
{
    cout << "The tent is small, two bedrolls laying in the middle of the floor. A single pack is also in the tent, some of its contents haphazardly strewn on the ground.
There are footprints leading out the door, but they disappear a couple of feet away outside. Seeing nothing of any value, you decide to go back outside." << endl;
    checkpoint += 1;
    main();
    return checkpoint;
}


int FirePit()
{
    cout << "The fire pit in the middle of the clearing is blackened, dark rocks circling the soot left over from fire-lit nights.
The pit emanates warmth, suggesting a fire was recently lit. Several logs sit around the pit, offering a seat for any campers willing to brave the outdoors for comfort." << endl;
    checkpoint += 1;
    main();
    return checkpoint;
}


How can I keep people from going through the same area to get through the game?

Thanks in advance for any help, I really want to get this to work.
Last edited on
All your functions can simply be void... This is because
1. You are ignoring the return value.
2. Are editing a global variable.

Also, in your main() function, have all that code running in a while loop; it will eliminate the need to keep calling main().

And as for your actual problem, I see no way of easily doing it...

Do you know about nodes/linked lists?

- Kyle
Last edited on
and, in my opinion, you shouldn't call main function, if you don't wanna mess with you program, unless your program is very well structured...

CMIIW
The C++ standard actually states "The function main shall not be used within a program."

It's a bad idea to call main.


I agree with them both... I was just trying to be easy on ya'!

- Kyle
How can I keep people from going through the same area to get through the game?


Off the top of my head, main should contain a single loop:

1
2
3
4
5
while (gameNotFinished)
{
  currentRoom->displayText();
  currentRoom->processInput();
}


Have a room class. Have one instance of the class for each room. Have a pointer to the current room, named currentRoom. The pointer is changed depending on the actions of the user. If the user chooses to go to room 3 next, for example, then the pointer is changed to point to the appropriate room object.
The reason they're all ints is because I can't return a void function and when the various functions are voids it keeps opening new paths which causes problems when I try to end the game. As for the recalling main, should I set up another sub-function for that bit and have the main call it?
Okay... That is by far the weirdest thing I've heard in a while... First of all, you don't need to return your variable; it is a global variable thus access able and editable by anything at anytime. If you needed to return the value, you would also have to pass the value to the function, AND it would have to be declared in main(). What do you mean by they keep opening new paths?

- Kyle
By new paths, I mean that the program doesn't close a subfunction when you leave that function, it opens a new function, keeping the old ones open. The functions don't end when you advance in the game, so the end message appears once for every area you go to.

Returning the variable closes the function and keeps the paths in the program from opening several paths and keeping them open after you progress through them.

If that makes sense.
Okay... Whatever you have to do, I guess... Is there still a problem that you're having?

- Kyle
Topic archived. No new replies allowed.