I'm a beginner and I am creating a text adventure game. I am trying to make an option where you can go back (eg. you enter a room and can type go back to go to the previous room and repeat the code on the last room).

Here is my code:

// Decision 2
Console.WriteLine("in front of you there are three paths, which path do you take? \n 1 \n 2 \n 3 ");
      
string decision2 = Console.ReadLine();

if (decision2 == "1")
{
    Console.WriteLine("You have chosen the first path.");
}
else if (decision2 == "2")
{
    Console.WriteLine("You have chosen the second path ");  
}

{
    Console.WriteLine("you have chosen the third  path ");
}
     
// Decision 3
if (decision2 == "1")
{
    Console.WriteLine("At the end of the first path there is a chest, do you want to open it? \n yes\n no");
    string decision3 = Console.ReadLine();

    if (decision3 == "yes")
    {
        Console.WriteLine("You open the chest and see a bomb, you take the bomb and put it in your inventory, what do you do next? \n check the room \n check inventory \n or go back ");
        string decision4 = Console.ReadLine();

I want to repeat the part in which you decide which path to take if the player types 'go back' in the last part.

0

There are 0 best solutions below