BattleShip.GameBoard.AddShip C# (CSharp) Метод

AddShip() публичный Метод

Add the ship on the grid
public AddShip ( casePlatform shipCase ) : void
shipCase casePlatform
Результат void
        public void AddShip(casePlatform[] shipCase)
        {
            foreach (casePlatform c in shipCase)
            {
                //this.Board[((int)(c.X/40)-1)*10+(int)(c.Y/40)-1] = c;
                this.Board.Remove(c);
                this.Board.Add(c);
            }
        }

Usage Example

Пример #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);
        }