Exemple #1
0
        public override async Task Display()
        {
            // Used to control exiting the main loop.
            Boolean run = true;

            do
            {
                Console.WriteLine("--- Game of Life ---");
                Console.WriteLine("1. Create Template");
                Console.WriteLine("2. Play Game");
                Console.WriteLine("3. Exit\r\n");
                Console.Write("Enter and Option: ");

                try
                {
                    // Invalid input will result in an ArgumentException.
                    int option = GetValidInput(1, 3, false);
                    Console.WriteLine();

                    switch (option)
                    {
                    case 1:
                        await templateUI.Display();

                        break;

                    case 2:
                        await playGameMenu.Display();

                        break;

                    case 3:
                        Console.WriteLine("Goodbye.");
                        run = false;
                        break;
                    }
                } catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            } while (run);
        }
Exemple #2
0
        public override async Task Display()
        {
            Console.WriteLine("--- Play Game --- \r\n");
            Console.WriteLine("1. New Game");
            Console.WriteLine("2. Resume Game\r\n");
            Console.Write("Enter and Option: ");

            try
            {
                // Invalid input throws an ArgumentException.
                int option = GetValidInput(1, 2, false);

                switch (option)
                {
                case 1:
                    await newGameUI.Display();

                    break;

                case 2:
                    Console.WriteLine("--- Resume Game ---\r\n");

                    // If no game loaded exit method.
                    if (!Model.Instance.LoadGame())
                    {
                        return;
                    }

                    break;
                }

                // Start game loop.
                await Model.Instance.PlayGame();

                // Once the game has been interrupted, save to the database.
                await Model.Instance.SaveGame();
            } catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }