Exemple #1
0
        //putShip method is called with createShip() after taking each player's names.
        private void putShips(string playerName, Board board, ShipType type)
        {
            Console.Clear();
            PlaceShipRequest request = new PlaceShipRequest();

            while (true)
            {
                //tell the user to place ship and what ship they are placing.
                //based on the ship eunm.
                Console.WriteLine($"{playerName} place your " + type);

                Coordinate    coordinate = ci.AskCoordinate(playerName);
                ShipDirection direction  = ci.AskShipDirection(playerName);
                request.ShipType = type;
                //call the coordinate method and the direction method for each ship placement
                request.Coordinate = coordinate;
                request.Direction  = direction;

                //using the ship placement enum in a switch statement to tell the user ship placement ok or not
                //if not keep asking until a valid input is made.

                ShipPlacement sp = board.PlaceShip(request);
                switch (sp)
                {
                case ShipPlacement.Ok:
                    return;

                case ShipPlacement.Overlap:
                    Console.WriteLine($"{playerName}, space taken. Please re-try");
                    break;

                case ShipPlacement.NotEnoughSpace:
                    Console.WriteLine($"{playerName}, not enough space. Please re-try ");
                    break;

                default:
                    Console.WriteLine("What happened?");
                    break;
                }
            }
        }