Beispiel #1
0
        public static Board BoardCreated(string PlayerName)
        {
            Board toReturn = new Board();

            for (ShipType s = ShipType.Carrier; s >= ShipType.Destroyer; s--)
            {
                bool IsShipSpotValid = false;
                do
                {
                    PlaceShipRequest request = new PlaceShipRequest();
                    request.Coordinate = ConsoleInput.GetCoordinate(PlayerName);
                    request.Direction  = ConsoleInput.GetDirection(PlayerName, s);
                    request.ShipType   = s;

                    var result = toReturn.PlaceShip(request);

                    if (result == ShipPlacement.NotEnoughSpace)
                    {
                        ConsoleOutput.TooFar();
                    }
                    if (result == ShipPlacement.Overlap)
                    {
                        ConsoleOutput.Overlap();
                    }
                    if (result == ShipPlacement.Ok)
                    {
                        ConsoleOutput.PlaceSuccess();
                        IsShipSpotValid = true;
                    }
                }while (!IsShipSpotValid);
            }
            return(toReturn);
        }
Beispiel #2
0
        //each player place their ships
        public static void PlaceShips(Player player, int i)
        {
            PlaceShipRequest placeShipRequest = new PlaceShipRequest();
            string           shipName;
            ShipPlacement    placement;

            shipName = player.PlayerBoard.Ships[i].ShipName;
            do
            {
                ConsoleOutput.ShowBoard(player.PlayerBoard.DisplayBoard);

                Console.WriteLine($"{player.Name}, enter a starting coordinate for your {shipName}: (Ex. A2) ");

                placeShipRequest.Coordinate = ConsoleInput.GetCoordinate();
                placeShipRequest.Direction  = ConsoleInput.GetDirection();
                placeShipRequest.ShipType   = player.PlayerBoard.Ships[i].ShipType;
                placement = player.PlayerBoard.PlaceShip(placeShipRequest);
                if (placement != ShipPlacement.Ok)
                {
                    Console.WriteLine($"{placement}.\nPlease press enter to try a new coordinate for your {shipName}.");
                    Console.ReadKey();
                    Console.Clear();
                }
            } while (placement != ShipPlacement.Ok);

            Console.WriteLine($"Your {shipName} has been placed. Press enter to continue.");
            Console.ReadKey();
        }
        private Board BuildBoard(string name)
        {
            Board gameBoard = new Board();

            for (ShipType s = ShipType.Carrier; s >= ShipType.Destroyer; s--)
            {
                PlaceShipRequest shipRequest = new PlaceShipRequest();
                shipRequest.ShipType = s;
                ConsoleOutput.ShipToPlace(shipRequest.ShipType);
                shipRequest.Coordinate = ConsoleInput.GetCoordinate();
                shipRequest.Direction  = ConsoleInput.GetDirection();
                ShipPlacement shipPlaced = gameBoard.PlaceShip(shipRequest);

                switch (shipPlaced)
                {
                case ShipPlacement.Overlap:
                    ConsoleOutput.ShipOverlappedAlert(shipRequest.ShipType);
                    s++;
                    break;

                case ShipPlacement.NotEnoughSpace:
                    ConsoleOutput.ShipNoSpaceAlert(shipRequest.ShipType);
                    s++;
                    break;
                }
            }
            Console.Clear();
            return(gameBoard);
            //ConsoleInput.GetCoordinate();
        }
Beispiel #4
0
        public void InvalidDirection()
        {
            string        userDirection = "d";
            ShipDirection actual        = ConsoleInput.GetDirection(userDirection);
            ShipDirection direction     = ShipDirection.Down;

            Assert.AreEqual(direction, actual);
        }
Beispiel #5
0
        public void PlayerData(Board board)
        {
            int x = 0;
            int y = 0;
            PlaceShipRequest request    = new PlaceShipRequest();
            Coordinate       Coordinate = new Coordinate(x, y);

            for (int currentShipIndex = 0; currentShipIndex < 5;)
            {
                while (true)
                {
                    request.ShipType = ConsoleInput.ProcessType(currentShipIndex);

                    _strCoordinate = ConsoleInput.GetCoor(Coordinate);

                    ConsoleInput.ProcessCoor(Coordinate, x, y, _strCoordinate);

                    request.Coordinate = Coordinate;

                    _direction = ConsoleInput.GetDirection(_direction);

                    request.Direction = ConsoleInput.ProcessDirection(_direction);

                    var shipPlaced = board.PlaceShip(request);

                    if (shipPlaced == ShipPlacement.NotEnoughSpace)
                    {
                        Console.WriteLine("There's not enough space for that ship. Try again");
                    }
                    else if (shipPlaced == ShipPlacement.Overlap)
                    {
                        Console.WriteLine("Ships are overlapping. Try again.");
                    }
                    else
                    {
                        break;
                    }
                }
                currentShipIndex++;
                Console.Clear();
            }
        }