Beispiel #1
0
        private static void GetPlayerShot(Game game)
        {
            Player activePlayer;
            Player enemyPlayer;

            if (game.Player1Turn)
            {
                activePlayer = game.Player1;
                enemyPlayer  = game.Player2;
            }
            else
            {
                activePlayer = game.Player2;
                enemyPlayer  = game.Player1;
            }
            FireShotResponse shot = new FireShotResponse()
            {
                ShotStatus = ShotStatus.Invalid
            };

            while (shot.ShotStatus == ShotStatus.Invalid || shot.ShotStatus == ShotStatus.Duplicate)
            {
                shot = enemyPlayer.PlayerBoard.FireShot(CoordinateWorkflow.GetCoordinate(game, "take your shot"));

                ReportShot(shot, activePlayer, enemyPlayer);
                if (shot.ShotStatus == ShotStatus.Victory)
                {
                    game.GameOver = true;
                }
            }
        }
Beispiel #2
0
        private static void SetShips(Game game, Player player)
        {
            if (game.Player1Turn)
            {
                player = game.Player1;
            }
            else
            {
                player = game.Player2;
            }

            foreach (ShipType ship in Enum.GetValues(typeof(ShipType)))
            {
                ShipPlacement result = ShipPlacement.NotEnoughSpace;
                while (result != ShipPlacement.Ok)
                {
                    PlaceShipRequest request = new PlaceShipRequest()
                    {
                        ShipType   = ship,
                        Coordinate = CoordinateWorkflow.GetCoordinate(game, $"time to place your {ship}"),
                        Direction  = GetDirectionChoice(player, ship)
                    };

                    result = player.PlayerBoard.PlaceShip(request);
                    ShipPlacementResponse(result, ship);
                }
            }
            Console.Clear();
            ConsoleIO.WriteInColor(player.Name, ConsoleColor.Green);
            Console.Write(", all ships placed successfully! Press any key to continue...");
            Console.ReadKey();
        }