Exemplo n.º 1
0
        public static void PlaceShips(Player player)
        {
            for (ShipType s = ShipType.Destroyer; s <= ShipType.Carrier; s++)
            {
                PlaceShipRequest request = new PlaceShipRequest();
                request.ShipType = s;
                Console.WriteLine("Placing " + s);
                request.Coordinate = ConsoleInput.GetCoordinateFromUser();
                request.Direction  = ConsoleInput.GetDirectionFromUser();

                ShipPlacement result = player.board.PlaceShip(request);
                if (result != ShipPlacement.Ok)
                {
                    Console.WriteLine("Could not place " + s + " there because of a(n) " + result);
                    s--;
                }
            }
            Console.Clear();
        }
Exemplo n.º 2
0
        public void PlaceShipOnBoard()
        {
            int           row;
            int           column;
            ShipDirection direction;

            for (int i = 0; i < 5; i++)
            {
                do
                {
                    ShipType currentShip = (ShipType)i;

                    Console.WriteLine($"{_name} let's place the " + currentShip);
                    row       = ConsoleInput.GetRowCoordinateFromUser();
                    column    = ConsoleInput.ColumnCoordinateFromUser();
                    direction = ConsoleInput.GetDirectionFromUser();


                    PlaceShipRequest request = new PlaceShipRequest()
                    {
                        Coordinate = new Coordinate(row, column),
                        Direction  = direction,
                        ShipType   = currentShip,
                    };

                    var response = board.PlaceShip(request);

                    if (response == ShipPlacement.NotEnoughSpace)
                    {
                        Console.WriteLine("There was not enough space to place the ship.");
                    }
                    if (response == ShipPlacement.Overlap)
                    {
                        Console.WriteLine("That overlaps with another ship.");
                    }
                    if (response == ShipPlacement.Ok)
                    {
                        break;
                    }
                } while (true);
            }
        }