Beispiel #1
0
        public GameController()
        {
            Console.WriteLine("Please wait. The computer board is being created...");
            try
            {
                computer = new ComputerPlayer();
                player   = new Player();
            }
            catch (Exception e) when(e is System.Xml.XmlException || e is System.Xml.Schema.XmlSchemaException || e is BoardIsFullException)
            {
                if (e is System.Xml.XmlException)
                {
                    ConsoleGrapher.WriteInColor("Error reading BoardOptions.xml file: " + e.Message, ConsoleColor.Red, ConsoleColor.White);
                }
                else
                {
                    ConsoleGrapher.WriteInColor(e.Message, ConsoleColor.Red, ConsoleColor.White);
                }
                Console.WriteLine("\n\nWhat would you like to do next?");
                SimpleActionConsoleMenu badOptionsMenu = new SimpleActionConsoleMenu();

                badOptionsMenu.AddOption("Rebuild the default game options file", Board.Options.RebuildDefaultBoardOptionsFile);
                badOptionsMenu.AddOption("Change game options", delegate
                {
                    Board.Options.CreateDefaultBoardOptionsFileIfDoesNotExist();
                    Process.Start(Board.Options.PATH_TO_OPTIONS);
                });
                badOptionsMenu.AddOption("Exit", delegate { Environment.Exit(0); });
                badOptionsMenu.ShowAndDoAction();
                Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                Environment.Exit(1);
            }
        }
Beispiel #2
0
        private static void TestSimpleActionConsoleMenuHide()
        {
            SimpleActionConsoleMenu menu = new SimpleActionConsoleMenu("Choose an option with an action:");

            menu.AddOption("Write 'Hello!'", () => Console.WriteLine("Hello!"));
            menu.AddOption("Show another menu", TestSimpleConsoleMenu1);
            menu.AddOption("Exit", () => Environment.Exit(0));
            menu.ShowHideAndDoAction();
        }
        private static void ShowStartMenu()
        {
            SimpleActionConsoleMenu startMenu = new SimpleActionConsoleMenu("What would you like to do?");

            startMenu.AddOption("Play", StartGame);
            startMenu.AddOption("Change game options", delegate
            {
                Board.Options.CreateDefaultBoardOptionsFileIfDoesNotExist();
                System.Diagnostics.Process.Start(Board.Options.PATH_TO_OPTIONS);
            });
            startMenu.AddOption("Exit", () => Environment.Exit(0));
            startMenu.ShowAndDoAction();
        }