当前位置: 首页>>代码示例>>C#>>正文


C# Ship.Deployed方法代码示例

本文整理汇总了C#中Ship.Deployed方法的典型用法代码示例。如果您正苦于以下问题:C# Ship.Deployed方法的具体用法?C# Ship.Deployed怎么用?C# Ship.Deployed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ship的用法示例。


在下文中一共展示了Ship.Deployed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddShip

    /// <summary>
    ///  AddShip add a ship to the SeaGrid
    /// </summary>
    /// <param name="row"></param>
    /// <param name="col"></param>
    /// <param name="direction"></param>
    /// <param name="newShip"></param>
    /// <param name="oldRow"></param>
    /// <param name="oldCol"></param>
    /// <param name="oldDirection"></param>
    private void AddShip(int row, int col, Direction direction, Ship newShip, Direction? oldDirection = null, int oldRow = -99, int oldCol = -99)
    {
        try {
            int size = newShip.Size;
            int currentRow = row;
            int currentCol = col;
            int dRow = 0;
            int dCol = 0;

            if (direction == Direction.LeftRight)
            {
                dRow = 0;
                dCol = 1;
            }
            else if (direction == Direction.UpDown)
            {
                dRow = 1;
                dCol = 0;
            }

            //place ship's tiles in array and into ship object
            int i = 0;
            for (i = 0; i <= size - 1; i++) {
                if (currentRow < 0 | currentRow >= Width | currentCol < 0 | currentCol >= Height) {
                    throw new InvalidOperationException("Ship can't fit on the board");
                }

                _GameTiles[currentRow, currentCol].Ship = newShip;

                currentCol += dCol;
                currentRow += dRow;
            }
            //@Lai Hoang Thanh Nguyen 16/09/2015
            //fixed error wrong passing row and col variables
            newShip.Deployed(direction, row, col);
        } catch (Exception e) {
            //@Issue2 @LaiHoang Thanh Nguyen 16/09/2015 re-generate old position instead of deleting a new wrong position.
            if (oldRow != -99 && oldDirection != null)
            {
                newShip.Remove();
                AddShip(oldRow, oldCol, oldDirection.Value, newShip);
            }
            else
            {
                newShip.Remove();
            }
                //if fails remove the ship
            throw new ApplicationException(e.Message);

        } finally {
            if (Changed != null) {
                Changed(this, EventArgs.Empty);
            }
        }
    }
开发者ID:jazonzos,项目名称:BattleShips,代码行数:65,代码来源:SeaGrid.cs

示例2: AddShip

    /// <summary>
    /// AddShip add a ship to the SeaGrid
    /// </summary>
    /// <param name="row">row coordinate</param>
    /// <param name="col">col coordinate</param>
    /// <param name="direction">direction of ship</param>
    /// <param name="newShip">the ship</param>
    private void AddShip(int row, int col, Direction direction, Ship newShip)
    {
        try {
            int size = newShip.Size;
            int currentRow = row;
            int currentCol = col;
            int dRow = 0;
            int dCol = 0;

            if (direction == Direction.LeftRight) {
                dRow = 0;
                dCol = 1;
            } else {
                dRow = 1;
                dCol = 0;
            }

            //place ship's tiles in array and into ship object
            int i = 0;
            for (i = 0; i <= size - 1; i++) {
                if (currentRow < 0 | currentRow >= Width | currentCol < 0 | currentCol >= Height) {
                    throw new InvalidOperationException("Ship can't fit on the board");
                }

                _GameTiles[currentRow, currentCol].Ship = newShip;

                currentCol += dCol;
                currentRow += dRow;
            }

            newShip.Deployed(direction, row, col);
        } catch (Exception e) {
            newShip.Remove();
            //if fails remove the ship
            throw new ApplicationException(e.Message);

        } finally {
            if (Changed != null) {
                Changed(this, EventArgs.Empty);
            }
        }
    }
开发者ID:sdawson12,项目名称:Battleship-Wiki,代码行数:49,代码来源:SeaGrid.cs

示例3: AddShip

        /// AddShip add a ship to the SeaGrid
        private void AddShip(int row, int col, Direction direction, Ship ship)
        {
            try {
                    int size = ship.Size;
                    int currentRow = row;
                    int currentCol = col;
                    int dRow = 0;
                    int dCol = 0;

                    if (direction == Direction.LeftRight) {
                         dRow = 0;
                         dCol = 1;
                    } else {
                         dRow = 1;
                         dCol = 0;
                    }

                    //place ship's tiles in array and into ship object
                    for (int i = 0; i < size; i++) {
                         if (currentRow < 0 | currentRow > _WIDTH | currentCol < 0 | currentCol > _HEIGHT) {
                              throw new InvalidOperationException("Ship can't fit on the board");
                         }
                         _gameTiles[currentRow, currentCol].Ship = ship;
                         currentCol += dCol;
                         currentRow += dRow;
                    }
                    ship.Deployed(direction, row, col);
               }
               catch (Exception e) {
                    ship.Remove();
                    //if fails remove the ship
                    throw new ApplicationException(e.Message);
               }
        }
开发者ID:kflo,项目名称:Battleship2,代码行数:35,代码来源:SeaGrid.cs


注:本文中的Ship.Deployed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。