Jump to content


Game Help


2 replies to this topic

#1 Felthorn

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 December 2012 - 05:43 AM

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;
do
{
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[i] << endl;

choice1 = yesno (1, 2);

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

if (choice1 == 2)
do
{
begin ();

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

return (choice1);
}

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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 24 December 2012 - 07:01 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1589 posts

Posted 24 December 2012 - 09:12 PM

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

int characterChoice = 0;
bool characterChosen = false;

while(!characterChosen){
showDefaultCharacter();
getCharacterChoice();
} 
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.
Currently using Blender and Unity.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users