简体   繁体   中英

How do I start over my code after a command?

I need to make 3 zones in a game I am making and I need to reset my code so you could move between the zones is there a command or a code that can do it?

It need to be done on one window just after you want to leave the zone

if (choice == 2)
{
    Console.WriteLine("you live");
}

Console.WriteLine("you left the temple and went towards the forest");
// the code starts over form the beginning

I want it to just restart the code after the end of a zone.

I would recommend using a switch case inside of a while loop but below I have added a possible solution with a simple if statement (or else if , if you prefer).

while (true) 
{
if (choice == 2) 
{
    Console.WriteLine("you live");
}
//Have a specific number for the user to input when they want to exit the program
if (choice == 3) 
{
    //break from the while loop
    break;
}
Console.WriteLine("you left the temple and went towards the forest");
// the code starts over form the beginning
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM