本文整理汇总了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);
}
}
}
示例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);
}
}
}
示例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);
}
}