/// <summary>
        ///     Creates new instance of simulation. Complains if instance already exists.
        /// </summary>
        public static void Create()
        {
            if (Instance != null)
                throw new InvalidOperationException(
                    "Unable to create new instance of simulation since it already exists!");

            Instance = new ConsoleSimulationApp();
            Instance.OnPostCreate();
        }
        /// <summary>
        ///     Creates new instance of simulation. Complains if instance already exists.
        /// </summary>
        public static void Create()
        {
            if (Instance != null)
            {
                throw new InvalidOperationException(
                          "Unable to create new instance of simulation since it already exists!");
            }

            Instance = new ConsoleSimulationApp();
            Instance.OnPostCreate();
        }
Esempio n. 3
0
        /// <summary>
        ///     Main entry point for the application being startup.
        /// </summary>
        private static void Main()
        {
            // Create console with title, no cursor, make CTRL-C act as input.
            Console.Title = "WolfCurses Console Application";
            Console.WriteLine("Starting...");
            Console.CursorVisible   = false;
            Console.CancelKeyPress += Console_CancelKeyPress;

            // Entry point for the entire simulation.
            ConsoleSimulationApp.Create();

            // Hook event to know when screen buffer wants to redraw the entire console screen.
            ConsoleSimulationApp.Instance.SceneGraph.ScreenBufferDirtyEvent += Simulation_ScreenBufferDirtyEvent;

            // Prevent console session from closing.
            while (ConsoleSimulationApp.Instance != null)
            {
                // Simulation takes any numbers of pulses to determine seconds elapsed.
                ConsoleSimulationApp.Instance.OnTick(true);

                // Check if a key is being pressed, without blocking thread.
                if (Console.KeyAvailable)
                {
                    // GetModule the key that was pressed, without printing it to console.
                    var key = Console.ReadKey(true);

                    // If enter is pressed, pass whatever we have to simulation.
                    // ReSharper disable once SwitchStatementMissingSomeCases
                    switch (key.Key)
                    {
                    case ConsoleKey.Enter:
                        ConsoleSimulationApp.Instance.InputManager.SendInputBufferAsCommand();
                        break;

                    case ConsoleKey.Backspace:
                        ConsoleSimulationApp.Instance.InputManager.RemoveLastCharOfInputBuffer();
                        break;

                    default:
                        ConsoleSimulationApp.Instance.InputManager.AddCharToInputBuffer(key.KeyChar);
                        break;
                    }
                }

                // Do not consume all of the CPU, allow other messages to occur.
                Thread.Sleep(1);
            }

            // Make user press any key to close out the simulation completely, this way they know it closed without error.
            Console.Clear();
            Console.WriteLine("Goodbye!");
            Console.WriteLine("Press ANY KEY to close this window...");
            Console.ReadKey();
        }