How to set locations in a simple game

Hey Guys

I don't think the title explains it properly but here it goes

In my code I want there to be locations like in this game code: http://www.penguinprogrammer.co.uk/c-rpg-tutorial/moving-around
I have done what they said in the tutorial but ITS NOT WORKING!!! Please help!

(Not working as in after the first section or completing your gender and type the game ends)

Code:

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
#include <iostream>
#include <string>


using namespace std;

bool running = 1;

int userInput = 0;

int playerInfo[2];

void titleFunc();

int playerLocation = 0;

int main()
{
    void titleFunc(); {
    cout << "\t\t\t\t---Xeon---\n\n\n";
    cout << "\t\t\t\t   1: Play\n";

    cin >> userInput;
    if(userInput == 1) {
            void newGameFunc(); {
            cout << "Welcome to Xeon!\nAn unexlored world full of adventurous paths and dangerous creatures!\n\n\n";
            cout << "I am Zolo... The DragonBorn!\n\n\n";
            cout << "Since you are a new comer to Xeon...\nCould you please tell me a little about yourself?\n\n";
            cout << "Are you a boy or a girl?\n 1: Boy\n 2: Girl\n";
            cin >> userInput;
            playerInfo[0] = userInput;

            cout << "And what kind of person are you?\n 1: Warrior\n 2: Archer\n 3: Thief\n 4: Scout\n 5: Mist\n";

    cin >> userInput;

    playerInfo[1] = userInput;

    cout << "You suddenly feel a gentle breeze pushing you but you ignore it\n\n\n";

    cout << "I thought I senced that in you! So now... Wait... Where are you going... What is happening!!\n\n\n";


    cout << "You suddenly feel the breeze turning into a violent wind.\nYou look down at your hands but they start disapearing...\nEverything around you is becoming blury...\nYou suddenly feel very dizzy and your vision starts to fade...\nAnd then... Everything turns Black!\n\n\n";

    playerLocation = 1;


            }

    }
    else {
        running = 0;
    }
     return 0;
}

    while (running) {
            if(playerLocation == 1) {

    cout << "You look around and you are in a wild jungle.\n You walk for a bit and you find yourself at the edge of a cliff.\n Eveything looks amazing and tropical around you!\n You look down and there is a sky blue lake.\n";
    cout << "Do you jump down or turn back?\n 1: Jump\n 2: Turn around and walk away\n";

    cin >> userInput;

    if(userInput == 1) playerLocation = 2;

    else if(userInput == 2) playerLocation = 3;

}
  if(playerLocation == 2) {

    cout << "You jumped down and landed with a big splash in the crystal water\n While you are in the water you see a small cave\n";
    cout << "Do you enter the cave or do rise to the top of the water and walk away?\n 1: Enter the cave\n 2: Rise out of the water and walk away";

    cin >> userInput;

    if(userInput == 1) playerLocation = 4;

    else if(userInput == 2) playerLocation = 5;

}
  if(playerLocation == 3) {

    cout << "You walk away from the cliff and find yourself walking down a hill.\nYou suddenly stop and look behind you where you see a lion starting to chase you\nTo your right there is a shallow hole you could jump down that the lion couldnt fit\n OR you could run straight ahead to some vines hanging down infront of another cliff\n\n";
    cout << "Do you go and hide in the hole or do you jump and swing on the vines?";

    cin >> userInput;

    if(userInput == 1) playerLocation = 6;

    else if(userInput == 2) playerLocation = 5;

}

    }
    return 0;
}

Please Help Me
This code is complete and utter shit for a game because it doesn't have any error checking at all really and the logic is also broken. Please find a better tutorial.

I fixed your user input so it won't break. If you want to get fancy with your error statements then you will want to add some extra if statements or use while loops.

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
	do
	{
	   	cout << "\t\t\t\t---Xeon---\n\n\n";
		cout << "\t\t\t\t   1: Play\n";
		cin >> userInput;	
	}
	while (userInput != 1);
	
	do
	{
		cout << "Welcome to Xeon!\nAn unexlored world full of adventurous paths and dangerous creatures!\n\n\n";
		cout << "I am Zolo... The DragonBorn!\n\n\n";
		cout << "Since you are a new comer to Xeon...\nCould you please tell me a little about yourself?\n\n";

		cout << "Are you a boy or a girl?\n 1: Boy\n 2: Girl\n";
		cin >> userInput;
	}
	while(userInput != 1 and userInput != 2);
	
	playerInfo[0] = userInput;
	
	do 
	{
		cout << "And what kind of person are you?\n 1: Warrior\n 2: Archer\n 3: Thief\n 4: Scout\n 5: Mist\n";
		cin >> userInput;
	}	
	while(userInput < 1 or userInput > 5);
Topic archived. No new replies allowed.