Beispiel #1
0
        public Game(Random rand, Ladder ladder)
        {
            Labyrinth labyrinth = new Labyrinth(rand);

            UserInputAndOutput.PrintWelcomeMessage();
            int movesCount = 0;

            string input = "";

            while (!IsGameOver(labyrinth) && input != "restart")
            {
                UserInputAndOutput.PrinyLabyrinth(labyrinth);
                input = UserInputAndOutput.GetInput();
                ProccessInput(input, labyrinth, ref movesCount, ladder);
            }

            if (input != "restart")
            {
                Console.WriteLine("Congratulations! You escaped in {0} moves.",
                    movesCount);
                if (ladder.ResultQualifiesInLadder(movesCount))
                {
                    Console.WriteLine(
                        UserInputAndOutput.ENTER_NAME_FOR_SCOREBOARD_MSG);

                    string name = Console.ReadLine();
                    ladder.AddResultInLadder(movesCount, name);
                }
            }
            Console.WriteLine();
        }
Beispiel #2
0
 private void ProccessInput(string input, Labyrinth labyrinth,
     ref int movesCount, Ladder ladder)
 {
     string inputToLower = input.ToLower();
     switch (inputToLower)
     {
         case "u":
         case "d":
         case "l":
         case "r":
             //fallthrough
             bool moveDone =
                 TryMove(inputToLower, labyrinth);
             if (moveDone == true)
             {
                 movesCount++;
             }
             break;
         case "top":
             ladder.PrintLadder();
             break;
         case "exit":
             Console.WriteLine(UserInputAndOutput.GOODBYE_MSG);
             Environment.Exit(0);
             break;
         case "restart":
             break;
         default:
             string errorMessage = UserInputAndOutput.INVALID_COMMAND_MSG;
             Console.WriteLine(errorMessage);
             break;
     }
 }
        static void Main()
        {
            Ladder ladder = new Ladder();
            Random rand = new Random();
            while (1 == 1)
            {

                Game game = new Game(rand, ladder);
            }
        }
 public void Initialize()
 {
     ladder = new Ladder();
 }