Game Help

Felthorn 101 Dec 24, 2012 at 05:43

Hi all, I need a hand with some code for a text based game. I have loved video games for most of my life and I thought maybe I could make one my self but hit a snag. I need a back function to go back a step in my game. For example if the game asks you if you want to make your own character or use a pre made character and you choose to make your own character. Then the game asks you is this your choice and you say nah I’ll use a pre made character, that’s where my problem is. It will not show the pre made character things and so I rewrote the code to this:

#include <iostream>
#include “back.h”
using namespace std;

int yesno (int min, int max)
int choice1;
cout << “Please enter one of the above numbers.\n”;
cin >> choice1;
cout << endl;
while( choice1 < min || choice1 > max);

return( choice1 );

void back ()
int choice1, i;
char *back[3] = {“Is this your choice?”, “1: Yes”, “2: No”};
for (i = 0; i < 3; i++)
cout << back << endl;

choice1 = yesno (1, 2);

if (choice1 == 1)
while () {continue};

if (choice1 == 2)
begin ();

choice = getchoice (1, 2);
cout << endl;
while(choice1 == 2);

return (choice1);

but it will not work either. Please help anyone. Thanks!:)

2 Replies

Please log in or register to post a reply.

Reedbeta 167 Dec 24, 2012 at 19:01

BTW, please use [ code ] … [ /code ] tags when posting code on the forum, to maintain the formatting.

As for your actual question, you could use a flag that indicates whether the player has completed character creation or not. Then write a loop that runs until this flag is true. Inside the loop, call out to the function for creating a character, then ask for confirmation. If the player says yes, set the flag to true; if they say no, leave it at false.

fireside 141 Dec 24, 2012 at 21:12

Also, try to make your code readable by using better function names and variable names:

int characterChoice = 0;
bool characterChosen = false;

if(characterChoice > 0)createCharacter();

//function definitions:

You’ll have to prototype functions in c, but IMO, main loops should only give an overall picture of what the code is doing.