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.
#include <iostream>
#include <string>
usingnamespace 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;
}