Adventure Game With Classes and Arrays

For my class project, I'm writing a choose-you-own-adventure game. It uses two classes (so I can show that I know how classes work): Scene and Option.

It was working as intended, until I gave each scene an array of options (rather than just a list. Now, it runs but doesn't cout anything, and terminates.

I could also use some tips on having the player/user select a member of an array.

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

class option {  //An action you can take in a scene
    public:
    string text;    //The game's description of the option
    string outcome; //What the game says when you choose the option
    void act (option o);    //Makes the option go
};

class scene {   //An individual "page" in the game
    public:
    string text;    //The game's description of the scene
    option opt [];  //The array of option which can be chosen in the scene
    void run(scene s);  //Makes the scene go
};

void act (option o) {
    cout << o.text << endl;
}

void run (scene s) {
        cout << s.text << endl;
        cout << "(Type a number to take that action)" << endl;
        cout << "1: " << s.opt[0].text << endl;
        cout << "2: " << s.opt[1].text << endl;
        act (s.opt[0]);
}

int main () {
    scene a;
    a.text="Forest";
    a.opt[0].text= "1: Kiss the elf.";
    a.opt[1].text= "2: Don't kiss the elf.";
    a.opt[0].outcome= "You kiss the elf.";
    a.opt[1].outcome= "You don't kiss the elf.";
    scene b;
    b.text="Forest containing an affronted elf.";
    run(a);
    return 0;
}


Thank you!
Topic archived. No new replies allowed.