Пример #1
0
        internal override void Run()
        {
            Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
            Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");

            // Initialize the init callback
            InitCallback();

            var runCallback = new SDLMessageLoop.RenderCallback(RunCallback);

            // Run the rendering loop
            try
            {
                SDLMessageLoop.Run(window, () =>
                {
                    if (Exiting)
                    {
                        Destroy();
                        return;
                    }

                    runCallback();
                });
            }
            finally
            {
                ExitCallback?.Invoke();
            }
        }
Пример #2
0
        internal override void Run()
        {
            if (swapChainPanel != null)
            {
                CompositionTarget.Rendering += CompositionTarget_Rendering;
                return;
            }

            // Call InitCallback only first time
            if (InitCallback != null)
            {
                InitCallback();
                InitCallback = null;
            }

            try
            {
                while (true)
                {
                    coreWindow.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
                    if (Exiting)
                    {
                        Destroy();
                        break;
                    }

                    RunCallback();
                }
            }
            finally
            {
                ExitCallback?.Invoke();
            }
        }
Пример #3
0
        internal override void Run()
        {
            Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
            Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");

            // Initialize the init callback
            InitCallback();

            Debug.Assert(GameContext is GameContextWinforms, "There is only one possible descendant of GameContext<Control>.");
            var context = (GameContextWinforms)GameContext;

            if (context.IsUserManagingRun)
            {
                context.RunCallback  = RunCallback;
                context.ExitCallback = ExitCallback;
            }
            else
            {
                var runCallback = new WindowsMessageLoop.RenderCallback(RunCallback);
                // Run the rendering loop
                try
                {
                    WindowsMessageLoop.Run(Control, () =>
                    {
                        if (Exiting)
                        {
                            Destroy();
                            return;
                        }

                        runCallback();
                    });
                }
                finally
                {
                    ExitCallback?.Invoke();
                }
            }
        }
Пример #4
0
        internal override void Run()
        {
            Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
            Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");

            // Initialize the init callback
            InitCallback();

            var context = (GameContextSDL)GameContext;

            if (context.IsUserManagingRun)
            {
                context.RunCallback  = RunCallback;
                context.ExitCallback = ExitCallback;
            }
            else
            {
                var runCallback = new SDLMessageLoop.RenderCallback(RunCallback);
                // Run the rendering loop
                try
                {
                    SDLMessageLoop.Run(window, () =>
                    {
                        if (Exiting)
                        {
                            Destroy();
                            return;
                        }

                        runCallback();
                    });
                }
                finally
                {
                    ExitCallback?.Invoke();
                }
            }
        }
Пример #5
0
        public override void Step(GameBoard board)
        {
            ConsoleUtil.WriteBlanks();
            Console.SetCursorPosition(0, Console.WindowHeight / 2);
            Console.WriteLine(board.WhiteToMove
                ? "White to move! Press any key to continue..."
                : "Black to move! Press any key to continue...");

            Console.ReadKey();
            var  layer      = board.WhiteToMove ? GameBoard.BoardType.WhiteShips : GameBoard.BoardType.BlackShips;
            bool horizontal = true;
            int  length     = board.ShipCounts
                              .Where(s => board.CountShipsWithSize(board.Board[(int)layer], s.Key) < s.Value)
                              .Max(s => s.Key);

            do
            {
                bool choosing = true;
                while (choosing)
                {
                    ConsoleUtil.WriteBlanks();
                    _renderer.RenderShips(board.Board[(int)layer], length, horizontal);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\nUse G to autogenerate board instead!");
                    Console.WriteLine("Use R to revert move");
                    Console.Write("Press Q to quit!");
                    var input = Console.ReadKey();
                    switch (input.Key)
                    {
                    case ConsoleKey.UpArrow:
                        _renderer.HighlightY = Math.Max(0, _renderer.HighlightY - 1);
                        break;

                    case ConsoleKey.DownArrow:
                        _renderer.HighlightY = Math.Min(board.Height - (horizontal ? 1 : length),
                                                        _renderer.HighlightY + 1);
                        break;

                    case ConsoleKey.RightArrow:
                        _renderer.HighlightX = Math.Min(board.Width - (horizontal ? length : 1),
                                                        _renderer.HighlightX + 1);
                        break;

                    case ConsoleKey.LeftArrow:
                        _renderer.HighlightX = Math.Max(0, _renderer.HighlightX - 1);
                        break;

                    case ConsoleKey.Enter:
                        choosing = false;
                        break;

                    case ConsoleKey.Spacebar:
                        horizontal           = !horizontal;
                        _renderer.HighlightX = Math.Min(board.Width - (horizontal ? length : 1),
                                                        _renderer.HighlightX);
                        _renderer.HighlightY = Math.Min(board.Height - (horizontal ? 1 : length),
                                                        _renderer.HighlightY);
                        break;

                    case ConsoleKey.Q:
                        ExitCallback?.Invoke();
                        return;

                    case ConsoleKey.G:
                        int n = 0;
                        while (n < 10 || !board.GenerateBoard())
                        {
                            n++;
                        }
                        return;

                    case ConsoleKey.R:
                        board.RevertMove();
                        return;
                    }
                }
            } while (!PlaceShipCallback?.Invoke(_renderer.HighlightY, _renderer.HighlightX, length, horizontal) ??
                     true);

            _renderer.HighlightX = 0;
            _renderer.HighlightY = 0;
        }
Пример #6
0
 private void Exit()
 {
     Menu.Close();
     ExitCallback?.Invoke();
 }