Help with text game please.

Hello, I am trying to code an adventure game for one of my classes, so far I have this. I have a question though. Once i go the main menu how would allow my program to continue with the game where it left off at? Also, I want to make an inventory that will allowed players to pick up certain weapons/armor through the game. Once they've decided to pick up or not how would I allowed them to look at their inventory and equip/look at something? Also there will be at least 1 boss battle, how should i go about a combat system?

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
  


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

string userChoice;



void mainMenu() {

        if(userChoice == "Help" || userChoice == "help") {

            cout << "-------------------------------------------" << endl;
            cout << "                MAIN MENU                  " << endl;
            cout << "To quite the game type 'quit'" << endl;
            cout << "To continue type 'continue'. " << endl;
            cin >> userChoice;

        }
}


void gameFunction() {
    string userName;

        cout << "What is your name?" << endl;
        cin >> userName;
        cout << "Hello " << userName << " welcome to the the game";
        cin >> userChoice;
}

void startMenu() {


        string userStart;
            cout << "--------------------------------------------------------------------" << endl;
            cout << "Hello, welcome to Prison Escape by Brandon Cavendish!" << endl;
            cout << "At any point in the game type 'help' to go to the main menu." << endl;
            cout << "Type 'Begin' to start your adventure!" << endl;
            cin >> userChoice;
        if (userChoice == "Begin" || userChoice == "begin") {

                gameFunction();
        }
}


int main() {

    startMenu();
    mainMenu();
}
I don't know about the saving progress part, but my recommendation for the inventory system I'm imagining something like this:
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
class Item
{
	/* Item Properties */
}

class Weapon: public Item 
{
	/* Additional Properties for Weapons */
}

class Armor: public Item
{
	/* Additional Properties for Armor */
}

/* Other Item Types */

class EquipSlot
{
	char itemType;
	Item equipped;
	/* Etc. */
}

int main()
{
	Array<Item> inventory;
	Array<EquipSlot> equipment;
	
	startMenu();
	mainMenu();
}
Last edited on
Hmm, I'll have to look into that, i'm not familiar with the code you type. I want to also have it so the user can pick up an item and use it. For example a key to unlock a door.
I would suggest that you learn OOP first since this kind of games can become quite complex and without a proper design you will and up with a mess. In addition to @Sh0es code you would also need a player class, a command parser....

My approach would be:
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
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

struct Item
{
  string name;
  string description;
  int weight;
};

class Inventory
{
public:
  void AddItem(Item item);
  void RemoveItem(Item item);
  bool HasItem(Item item);
private:
  vector<Item> items;
};

class Room
{
private:
  map<string, Room> exits;
  string name;
  string description;
  Inventory inventory;
};

class Player
{
private:
  Inventory inventory;
};

struct Action
{
  string command;
  string param;
};

class CommandParser
{
public:
  Action Parse(const string& txt);
private:
  vector<string> commandWords;
};

class Game
{
public:
  Game();
  void Run();
private:
  Room location;
  vector<Room> rooms;
};

int main()
{
  try
  {
    Game game;
    game.Run();
  }
  catch (const exception& ex)
  {
    cerr << "Error: " << ex.what();
    return -1;
  }
  catch (...)
  {
    cerr << "Unknown error: ";
    return -2;
  }
  return 0;
}

Just an idea, not an working example
I second what @Thomas1965 suggests. OOP isn't easy to learn in C++ but it's so much more useful in the long run.
Okay here is what I have now, I still am at a delima though for making my cases, I can't have two case 1's so i don't know what to do. also I decided not to do an inventory because i think it was too much for me at this tie



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
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

string userOption;
int userMainMenu;
int userChoice;
int userChoice2;
void screamForHelpScene1() {
            cout << "You hear someone running towards you as you scream bloody murder. A gaurd comes around the corner and yells 'What the hell is wrong with you" << endl;
            cout << "What would you like to say?" << endl;
            cout << "Why am I here?" << endl;
            cout << "Where am I?" << endl;
            cout << "Ask both" << endl;
            cout << "Remain silent" << endl;
            cin >> userChoice2;


            switch (userChoice2) {
            case 1:
                cout << "The guard looks at you and says 'Ha! How should I know, I'm just the guard doing my job, now shut up or you'll wish you were somewhere else'" << endl;
                cout << "The guard walks away laughing at you." << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again" << endl;
                cout << "2. Look for a way out of the cell." << endl;
                cout << "3. Cry" << endl;
                cin >> userChoice;
                break;
            case 1:
                cout << "";
                break;

            default:
                cout << "That is not an option please try again.";
            }




}

void mainMenu() {

        switch (userChoice) {
        case 0:
            cout << "------------------------------------------------------" << endl;
            cout << "                      MAIN MENU                       " << endl;
            cout << "If you can't figure out what to do keep trying! No one said it was easy to " << endl << "escape prison!" << endl;
            cout << "To quite the game type 'quit'" << endl;
            cout << "To continue type 'continue'. " << endl;
            cin >> userOption;
        break;

        }
}


void gameFunction() { // the actual function of the main game itself.
    string userName;

        cout << "What is your name?" << endl;
        cin >> userName;
        cout << "Hello " << userName << " welcome to the the game" << endl;
        cout << "You wake up feeling dazed, you don't know where you are but after gathering your senses you realize you're in a prison cell. It's small, there's no one around you that you can see." << endl;
        cout << "What would you like to do?" << endl;
        cout << "1. Scream for help" << endl;
        cout << "2. Look for a way out of the cell." << endl;
        cout << "3. Sit there and do nothing." << endl;
        cout << "4. Cry." << endl;
        cin >> userChoice2;

                    switch(userChoice2) {
                    case 1:
                        screamForHelpScene1();
                    }



}

void startMenu() { // the opening menu for the game


        string userStart;
            cout << "--------------------------------------------------------------------" << endl;
            cout << "Hello, welcome to Prison Escape by Brandon Cavendish!" << endl;
            cout << "At any point in the game type 'help' to go to the main menu." << endl;
            cout << "Type '1' to start your adventure!" << endl;
            cin >> userChoice;
       switch (userChoice) {
    case 1:
        screamForHelpScene1();
    break;


       }
}


int main() {

    startMenu();
    mainMenu();
}
Registered users can post here. Sign in or register to post.