C++ text based adventure game using SDL

Hello, I've recently taken a class to learn c++. We have a project and I'm doing a choose your own adventure text based game. I have the code for the game already but what I'm hoping to do is to display the text with an image for each page in a separate window besides the command prompt. I'm using SDL2 and have managed to get an image to display but what I want is for every page to display it's own picture and the text at the bottom. I was wondering if there were a way to do this with SDL2 or if I should be using something else.
Last edited on
#include <iostream>
#include <string>
using namespace std;

struct Page
{
string text;
int options, nextpage[10];
};

const Page gamePages[] = {
// Intro Page 0
{
"Welcome to SilverMoon. Please select your class.\n"
"(1 for Hunter, 2 for Wizard.)\n",
2,
{ 1,4 }
},

// Intro to game(Hunter) 1
{
"welcome to Transylvania, Hunter.\n"
"You have been hired by the local Lord to deal with the towns Werewolf infestation.\n"
"It is almost dawn as you walk towards town, you come to a fork in the road. The left leads into town, the right goes to the lake in the forest.\n"
"Which do you choose? (1 for Left, 2 for Right)\n",
2,
{ 0,2 }
},

//Having chosen the Lake 2
{
"It is first light as you come to a clearing in the forest and see a cobble stone path to the edge of the lake and another that snakes its way to a small cabin.\n"
"The cabin has smoke billowing out and light peeks out from the curtains, a dull sound and a thunderous crack exudes from the cabin.\n"
"The lake reflects a dull orange of the suns early light. In the water you see a gorgeous woman swimming near the waters edge who almost immediately matches your gaze and waves to you.\n"
"Where will our adventurer find himself? (1 for the Cabin, 2 for the Lake) .\n",
2,
{ 5,3 }
},

//Having chosen the Lake 3
{
"You quickly come upon the waters edge, never wavering your attention to the woman.\n"
"The womans hair is a dull red that drapes her head and shoulders, her skin bears the resemblance of that to heavy cream, with eyes so blue that they match the very water she is in, and her features could have been crafted by Michelangelo himself.\n"
"The Lady of the Lake beckons to you to come closer and join her. Your mind clears and are reminded of the cabin and your purpose for being here.\n"
"Do you wish to join the woman in the water or do you want to head towards the Cabin?(1 for the Woman, 2 for the Cabin).\n",
2,
{ 4,5 }
},

//Having chosen the Woman 4
{
"You wade into the icy waters. You quickly approach the woman and you hold each other in a tight embrace.\n"
"You look into her eyes and see that they have turned into jet black portals holding no emotion, only oblivion.\n"
"You're quickly pulled under the water by the woman. Your body is sapped of all strength by the chilled waters and that's when you notice it.\n"
"A large serpent that portudes from the woman and quickly strikes. You are quickly ripped apart by razor sharp teeth and your remnants swallowed by the beast.\n"
" YOU ARE DEAD.\n",
0,
{}
},

//Having chosen the Cabin 5
{
"You come upon the cabin and are immediately assaulted by the smell of bacon, fried eggs, and oranges. Your vision is obstructed by the curtains, but you do see a door.\n"
"You can also clearly tell that the sounds are coming from behind the cabin.\n"
"Do you wish to intrude upon the cabin or to investigate the source of the sound?(1 for the Door, 2 for the Sounds).\n",
2,
{ 6,11 }
},

//Having chosen the Door 6
{
"You come through the door and walk through the entrance. Before you is a table set for breakfast, your sense of smell has not betrayed you as you see a welcoming sight of breakfast.\n"
"As your hungry eyes take in the feast set before you, you also notice a wolfs pelt hanging from the rack of coats."
"This pelt is not like any you have seen."
"Does our brave adventurer investigate Breakfast or The Wolf Pelt?(1 for Breakfast, 2 for Pelt)",
2,
{7,9}
},

//Having chosen Breakfast 7
{
"You can't help but be entranced by the powerful smell of breakfast set upon you."
"The food itself seems to still be quite hot, your stomach lets out a large rumble to indicate your hunger."
"You notice there are no plates set at the table, so you go to search for them.",
1,
{8}
},

//Breakfast Death 8
{
"As you turn to look for the cutlery, you realize that the sounds have stopped entirely."
"You are then assaulted by a large blow to your your chest and stagger to the ground."
"As your vision begins to fade you see old man holding a bloody axe."
"The last thing you hear are dull thuds as the old man rains blows upon blows on your body."
" YOU ARE DEAD ",
0,
{}
},


};

/*
This is the CODE / LOGIC
Now that I have the data set up for the most park, this will be how the code can use that data to actually drive the game
*/
int doPage(int page) // the 'doPage' function will do the logic for the given 'page' parameter. It will return the next page that the user will go to or return -1 if the user died or got Game Over
{// Page logic is pretty simple: output the flavor text
cout << gamePages[page].text;

if (gamePages[page].options <= 0)//if the user got game over, no options
return -1;// -1 to indicate game over

int selection;//if they didnt die then this'll get their selection
cin >> selection;
while (selection < 1 || selection > gamePages[page].options)//this will make sure that the selections are valid; invalid selections are -1 or are greater than the available options
{
cout << "This is an invalid option, Please try again.\n";
cin >> selection;
}
return gamePages[page].nextpage[selection - 1];// we have to subtract 1 here since our selection ID starts at 1 but array indexes start at 0
}

/*
Main
since doPage does all the logic, main will be very simple. It'll just keep calling doPage until the player get Game Over.
*/
int main()
{
int currentPage = 0;// start at page 0

while (currentPage >= 0)//as long as they don't have a game over
{
currentPage = doPage(currentPage);//doPage
}
return 0;
}
Shouldn't your page have a reference to a bitmap or the filename of a bitmap ?
Topic archived. No new replies allowed.