Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
So i'm trying to make a text adventure in Visual Studio Express but i'm having some trouble. I'm new to programming so i don't really know what to do.
C#
Console.WriteLine("Welcome to *!");
           Console.WriteLine("What is your name?");
           name = Console.ReadLine();
           Console.WriteLine("Choose your class: Mage, Warrior or Rogue.");
           proffesion = Console.ReadLine();

           if (proffesion.Equals("Mage"))
                   Console.WriteLine("A mage uses the ancient power of magic, that is thought to be long forgotten, to defeat his foes. Are you sure you want to choose this class?");
               mageanswer = Console.ReadLine();
               if (mageanswer.Equals("Yes"))
                   Console.WriteLine("You have chosen to be a mage!");
               else if (mageanswer.Equals("No"))
                   Console.WriteLine("Choose your class: Mage, Warrior or Rogue.");
               proffesion = Console.ReadLine();


               if (proffesion.Equals("Warrior"))
                   Console.WriteLine("A warrior uses brute force and sharp blades to crush his enemies. Are you sure you want to choose this class?");
               warrioranswer = Console.ReadLine();
               if (warrioranswer.Equals("Yes"))
                   Console.WriteLine("You have chosen to be a warrior!");
               else if (warrioranswer.Equals("No"))
                   Console.WriteLine("Choose your class: Mage, Warrior or Rogue.");
               proffesion = Console.ReadLine();


What i'm trying to do is, that instead of saying "Choose your class" all the time, that it just sends you back to the beginning. How does one do that?
Posted
Comments
Richard C Bishop 7-Mar-14 17:16pm    
The beginning of what?
Member 10652281 7-Mar-14 17:20pm    
To the first time it says Choose your class.

1 solution

First of all, congratulations!  Writing your own adventure game is a labor of love (I spent 4 years of grad school and 5 years at my first job hacking Collosal Cave Adventure[^]) from which you could learn a lot of about programming.

Next, sorry but you're going about this the wrong way.
  • For starters, you're missing a few curly braces (that will ensure the player is asked Mage/Warrior specific questions only if they are a Mage or Warrior).

  • More importantly, ditch the idea of a scripted set of questions and logic.  Instead, have an ask/respond loop that handles the game's logic.  And before you can do this, you'll need to design your game (in minute detail on paper - or at least softcopy) before you write a stitch of code.

Play existing text adventure games to get a feel for how the games respond.  Above all, have fun and learn as much as you can.  Writing code can be an immensely fulfilling activity and in some cases (like mine) can take over your life.

/ravi
 
Share this answer
 
Comments
Member 10652281 7-Mar-14 17:33pm    
What exactly do you mean by a ask/respond loop? Otherwise thank you for your advise :D
Ravi Bhavnani 7-Mar-14 17:35pm    
Put simply, your app's logic should look like this:

initializeGame();
do {
determine what to ask;
ask question, get response;
process response;
}
while (!gameOver());

/ravi
phil.o 7-Mar-14 19:17pm    
Wow, this concept could be applied to so many things :)
My 5!
Ravi Bhavnani 7-Mar-14 19:19pm    
I assume you were being sarcastic. :P

/ravi
phil.o 7-Mar-14 19:22pm    
Just a little ^^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900