In my C# code (I am currently trying to learn it), I am trying to make a text - console based adventure game. The first 'Section' works, and I copy pasted it over to and changed the name of the variables etc. (Its a repetitive code), but it just wont work.
Here is the code:
using System;
namespace LearningC
{
class MainClass
{
public static void Main (string[] args)
{
lvl_1_start: //LEVEL ONE
Console.WriteLine ("Welcome to AlexAdventureLand.\nPlease press the enter key to start.");
Console.ReadKey ();
Console.WriteLine ("You are a rabbit in a burrow. There is a badger outside. \nPress 1 to leave the burrow. \nPress 2 to wait.");
int lvl_1 = Convert.ToInt32 (Console.ReadLine ());
if (lvl_1 == 1) {
Console.WriteLine ("The badger sees you and eats you. \nYou fail. \n\nPress enter to try again.");
Console.ReadKey ();
goto lvl_1_start;
} else if (lvl_1 == 2) {
Console.WriteLine ("The badger scurries away!");
goto lvl_2_start;
} else {
Console.WriteLine ("You pressed the wrong button. Start again.");
goto lvl_1_start;
}
lvl_2_start: //LEVEL TWO
Console.WriteLine ("Now what do you want to do? \nPress 1 to leave burrow. \nPress 2 to wait.");
Console.ReadKey ();
int lvl_2 = Convert.ToInt32 (Console.Read ());
if (lvl_2 == 1) {
Console.WriteLine ("You leave the burrow and look around.");
Console.ReadKey ();
goto lvl_3_prt_a_start;
} else if (lvl_2 == 2) {
Console.WriteLine ("You wait a little longer. \nYou can hear footsteps around your burrow. You wonder whether it's your friend - troy - or the badger still.");
goto lvl_3_prt_b_start;
} else {
Console.WriteLine ("You pressed the wrong button. Start again.");
goto lvl_2_start;
}
lvl_3_prt_a_start: //LEVEL THREE PART A
Console.WriteLine ("PlaceHolder");
Console.ReadKey ();
lvl_3_prt_b_start:
Console.WriteLine ("PlaceHolder");
Console.ReadKey ();
}
}
}
The problem occurs when running it. The first section works fine, and pressing '1', '2' or any other number works - but on section two, it always comes up with the else section, none of the if or if else clauses. Any quick help would be great. Thanks!