Ejemplo n.º 1
0
        private void StartGame()
        {
            Console.Clear();
            _gameDrawer.DrawPicture(_game);

            while (true)
            {
                if (_game.CurrentTurn)
                {
                    ConsoleKey pressedKey;
                    do
                    {
                        switch (pressedKey = Console.ReadKey(true).Key)
                        {
                        case ConsoleKey.UpArrow:
                            if (_game.HumanPlayer.CurrentPosition.X != 1)
                            {
                                _game.HumanPlayer.CurrentPosition.X--;
                            }
                            break;


                        case ConsoleKey.DownArrow:
                            if (_game.HumanPlayer.CurrentPosition.X != 10)
                            {
                                _game.HumanPlayer.CurrentPosition.X++;
                            }
                            break;


                        case ConsoleKey.LeftArrow:
                            if (_game.HumanPlayer.CurrentPosition.Y != 1)
                            {
                                _game.HumanPlayer.CurrentPosition.Y--;
                            }
                            break;


                        case ConsoleKey.RightArrow:
                            if (_game.HumanPlayer.CurrentPosition.Y != 10)
                            {
                                _game.HumanPlayer.CurrentPosition.Y++;
                            }
                            break;

                        case ConsoleKey.F12:
                            _game.Hack = !_game.Hack;
                            Console.Clear();
                            break;

                        case ConsoleKey.Escape:
                            MenuItems();
                            return;
                        }

                        _gameDrawer.DrawPicture(_game);
                    } while (pressedKey != ConsoleKey.Spacebar);
                }
                _game.Turn();
                _gameDrawer.DrawPicture(_game);
                //Check for winner
                if (_game.HumanPlayer.MyBoard.Ships.Count(s => s.Health > 0) == 0)
                {
                    Console.WriteLine("You lose!");
                    //delay
                    Console.ReadKey(true);
                    _game = null;
                    return;
                }
                if (_game.ComputerPlayer.MyBoard.Ships.Count(s => s.Health > 0) == 0)
                {
                    Console.WriteLine("You win");
                    //delay
                    Console.ReadKey(true);
                    _game = null;
                    return;
                }
            }
        }