Questions about looping

captainawesesome

New member
Joined
Feb 5, 2013
Messages
3
Programming Experience
Beginner
Ok so I'm pretty much a programming noob. I'm going to school for programming right now, and I'm doing some personal projects to try and put myself ahead of my class. Right now I'm working on a text-based RPG. I know pretty much how I'm going to make it, but I need to learn some syntax. I'm trying to figure out how I can loop this:

command = Console.ReadLine();


switch (command)

{

case ("help") :
Console.WriteLine("");
Console.WriteLine("Verbs Nouns");
Console.WriteLine("===================");
Console.WriteLine("go north");
Console.WriteLine("climb south");
Console.WriteLine("attack east");
Console.WriteLine("block west");
Console.WriteLine("read tree");
Console.WriteLine("observe inn");
Console.WriteLine("visit merchant");
Console.WriteLine("run sword");
Console.WriteLine("talk monster");
Console.WriteLine("open chest");
Console.WriteLine("listen door");
break;

case ("start") :
Console.WriteLine("");
Console.WriteLine("You wake up and look around you. You see you are in a bed at an Inn.");
Console.WriteLine("");
break;

}

Also I'm trying to figure out how to send back an error message whenever I type anything but "start" or "help". I'm going to have to learn a lot more before I am able to finish my project, but this should at least get me started.

Any advice would be appreciated.

Oh, also it should be noted, once "start" is typed the adventure will start. So obviously I don't want that to loop back.
 
Last edited:
I figured it out. Here is my solution:



while (command != "start")
{
command = Console.ReadLine();


switch (command)
{

case ("help"):
Console.WriteLine("");
Console.WriteLine("Verbs Nouns");
Console.WriteLine("===================");
Console.WriteLine("go north");
Console.WriteLine("climb south");
Console.WriteLine("attack east");
Console.WriteLine("block west");
Console.WriteLine("read tree");
Console.WriteLine("observe inn");
Console.WriteLine("visit merchant");
Console.WriteLine("run sword");
Console.WriteLine("talk monster");
Console.WriteLine("open chest");
Console.WriteLine("listen door");
Console.WriteLine("");
break;

case ("start"):
Console.WriteLine("");
Console.WriteLine("You wake up and look around you. You see you are in a bed at an Inn.");
Console.WriteLine("");
break;

default:
Console.WriteLine("");
Console.WriteLine("Invalid command or invalid in this instance.");
Console.WriteLine("Please type \"help\" for a list of commands.");
Console.WriteLine("");
break;
}
}
 
Back
Top Bottom