Ejemplo n.º 1
0
        private static void HandleKey(ConsoleKeyInfo key)
        {
            var CB     = Boards.CurrentBoard;
            var coords = new Utils.Utils.Point(CB.SelectedTile.Coords);

            switch (key.Key)
            {
            case (ConsoleKey.UpArrow):
                coords.Y--;
                goto SelectTile;

            case (ConsoleKey.DownArrow):
                coords.Y++;
                goto SelectTile;

            case (ConsoleKey.LeftArrow):
                coords.X--;
                goto SelectTile;

            case (ConsoleKey.RightArrow):
                coords.X++;
                goto SelectTile;
SelectTile:
                CB.SelectTile(coords);
                break;

            case (ConsoleKey.Spacebar):
                Players.CurrentPlayer.ShowEnemyBoard = !Players.CurrentPlayer.ShowEnemyBoard;
                break;

            case (ConsoleKey.Enter):
                if (State.Turn == 0)
                {
                    ShipPlacerController.Select();
                }
                else
                {
                    CB.SelectedTile.OnEnter();
                }
                break;

            case (ConsoleKey.Escape):
                if (State.Turn == 0 && ShipPlacerController.Start != null)
                {
                    ShipPlacerController.Start = null;
                }
                else
                {
                    Menu.CurrentNode = PauseMenu.GetPauseMenu();
                    Menu.Run();
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            Stop = false;
            State.ResetGame();
            while (!Stop)
            {
                if (State.Win)
                {
                    GameWinScreen();
                    break;
                }
                if (State.TurnEnded)
                {
                    HandleTurnEnd();
                }
                if (State.Turn == 0)
                {
                    ShipPlacerController.Prepare();
                }
                else if (Players.CurrentPlayer.IsAI)
                {
                    AIUI.MoveAI(Players.CurrentPlayer.AI);
                }
                if (State.TurnEnded)
                {
                    HandleTurnEnd();
                }

                ShowGame();

                if (!Players.CurrentPlayer.IsAI)
                {
                    var key = Console.ReadKey(false);
                    HandleKey(key);
                }
            }
        }