AddShip() public method

Add the ship on the grid
public AddShip ( casePlatform shipCase ) : void
shipCase casePlatform
return void
示例#1
0
        /// <summary>
        /// Queries the player for various details about the ship they wish to add,
        /// then adds it to the player's game board.
        /// </summary>
        private void AddShip()
        {
            Console.WriteLine("Creating new ship...");

            Ship newShip;

            newShip.length    = UserInput.GetInt("How many spaces long is the ship?", Ship.MIN_LENGTH, Ship.MAX_LENGTH);
            newShip.xPosition = UserInput.GetInt("Which column should the front of the ship be placed in?", 1, GameBoard.BOARD_SIZE);
            newShip.yPosition = UserInput.GetInt("Which row should the front of the ship be placed in?", 1, GameBoard.BOARD_SIZE);
            newShip.vertical  = UserInput.GetBoolean("What orientation would you like to place your ship?\n" +
                                                     "If horizontal is chosen, the ship will extend to the right from your chosen position.\n" +
                                                     "If vertical is chosen, the ship will extend downwards from your chosen position.\n(V for vertical) ", 'V');

            board.AddShip(newShip);
        }