Пример #1
0
        private Board BuildBoard(string playerName)
        {
            Board board = new Board();

            for (ShipType s = ShipType.Destroyer; s <= ShipType.Carrier; s++)
            {
                bool isValidPlacement = false;
                do
                {
                    PlaceShipRequest request = new PlaceShipRequest();
                    request.Coordinate = ConsoleInput.GetCoord(playerName, s);
                    request.Direction  = ConsoleInput.GetDir(playerName, s);
                    request.ShipType   = s;

                    var result = board.PlaceShip(request);
                    if (result == ShipPlacement.Overlap)
                    {
                        ConsoleOutput.ShipOverlap(playerName);
                    }
                    else if (result == ShipPlacement.NotEnoughSpace)
                    {
                        ConsoleOutput.NotEnoughSpace(playerName);
                    }
                    else
                    {
                        ConsoleOutput.ShipPlaceOk(playerName);
                        isValidPlacement = true;
                    }
                } while (!isValidPlacement);
            }
            return(board);
        }