I started reading up on C++ yesterday, and I am a person who learns best by doing rather than just reading theory, so I wanted to create a small game where you are presented with dialogue, and thereafter have 3 options which each will lead you to another piece of dialogue, and thereby create an adventure for yourself that way.
I came across an RPS game which I modified as practice. It turned out like this:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int choice;
cout << "The number adventure!.";
cout << " Type 0 for 0.";
cout << " Type 1 for 1";
cout << " Type 2 for 2";
cin >> choice;

// Option 0
if (choice == 0)
{
cout << "You chose 0";
}
// Option 1
if (choice == 1)
{
cout << "You chose 1";
}
// Option 2
if (choice == 2)
{
cout << "You chose 2!";
}
return main();
}

Which works how I wanted in theory. I just can't figure out how to expand the dialogue options, so they each lead to three new, unique dialogue options and keep the ball rolling from there. So if anybody would be so kind to forward me in the right direction.
And please don't tell me to read up more theory, until I get a good enough understanding of C++ so that I can figure it out myself. I like toying with stuff like this to supplement my reading. And looking at working code while trying to figure out how everything plays together is something I enjoy, and I learn a lot from it in my experience.
So thank you if anybody wants to help me.

Recommended Answers

All 2 Replies

I threw in some ideas quickly so its not just option 1 option 1-a and stuff like that. Most of it is pretty lame but not too much thought went into it.

The main things that are being used in here are functions and the switch statement. You can try to look at my code and add more options in and see how stuff works by playing around with it.

I recommend this website for learning the basics and reference to the standard libraries.

I also like to learn by reading a bit of theory then making my own small program outlining concepts I just went over in the tutorials.

#include <iostream>

using namespace std;

//function prototypes
void Farm();
void Town();
void Cave();
void Options();

int main()
{
	Options();
	system("PAUSE"); //only works on windows comment out if you are using linux
    return 0;
}

void Options() //starting options
{
	cout << "Pick an area to go to:" << endl;
	cout << "1 - Farm" << endl;
	cout << "2 - Town" << endl;
	cout << "3 - Cave" << endl;
	int input;
	cin >> input;
	switch(input)
	{
		case 1:
			Farm();
			break;
		case 2:
			Town();
			break;
		case 3:
			Cave();
			break;
	}
}

void Farm() //farm area
{
	cout << endl << "You are at the farm." << endl;
	cout << "Pick an area to go to:" << endl;
	cout << "1 - Barn" << endl;
	cout << "2 - Corn Field" << endl;
	cout << "3 - Farmer's House" << endl;
	int input;
	cin >> input;

	switch(input)
	{
		case 1:
			cout << "You are in the barn." << endl;
			break;
		case 2:
			cout << "You are at the corn field." << endl;
			break;
		case 3:
			cout << "You are in the farmer's house." << endl;
			break;
	}
}

void Town() //town area
{
	cout << endl << "You are in the town." << endl;
	cout << "Pick an area to go to:" << endl;
	cout << "1 - Mall" << endl;
	cout << "2 - Town Centre" << endl;
	cout << "3 - Jail" << endl;
	int input;
	cin >> input;

	switch(input)
	{
		case 1:
			cout << "You are in the mall." << endl;
			break;
		case 2:
			cout << "You are at the town centre." << endl;
			break;
		case 3:
			cout << "You are in the jail." << endl;
			break;
	}
}

void Cave() //cave area
{
	cout << endl << "You are in the cave." << endl;
	cout << "Pick an area to go to:" << endl;
	cout << "1 - Human Remains" << endl;
	cout << "2 - Chilling Pool" << endl;
	cout << "3 - Large Crystal Formation" << endl;
	int input;
	cin >> input;

	switch(input)
	{
		case 1:
			cout << "You are at the human remains." << endl;
			break;
		case 2:
			cout << "You are in the chilling pool." << endl;
			break;
		case 3:
			cout << "You are at the large crystal formation." << endl;
			break;
	}
}

Thank you! This is a lot more than I was hoping for, I really appreciate you taking the time to do this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.