/// <summary>
 /// Set the _Value to the PossibleAttack value
 /// </summary>
 /// <param name="value">either hit, miss, destroyed, shotalready</param>
 public AttackResult(ResultOfAttack value, string text, int row, int column)
 {
     _Value = value;
     _Text = text;
     _Ship = null;
     _Row = row;
     _Column = column;
 }
Пример #2
0
 /// <summary>
 /// The tile constructor will know where it is on the grid, and is its a ship
 /// </summary>
 /// <param name="row">the row on the grid</param>
 /// <param name="col">the col on the grid</param>
 /// <param name="ship">what ship it is</param>
 public Tile(int row, int col, Ship ship)
 {
     _RowValue = row;
     _ColumnValue = col;
     _Ship = ship;
 }
Пример #3
0
 /// <summary>
 /// Clearship will remove the ship from the tile
 /// </summary>
 public void ClearShip()
 {
     _Ship = null;
 }
Пример #4
0
        /// <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);
            }
            }
        }
 /// <summary>
 /// Set the _Value to the PossibleAttack value, and the _Ship to the ship
 /// </summary>
 /// <param name="value">either hit, miss, destroyed, shotalready</param>
 /// <param name="ship">the ship information</param>
 public AttackResult(ResultOfAttack value, Ship ship, string text, int row, int column)
     : this(value, text, row, column)
 {
     _Ship = ship;
 }
Пример #6
0
        /// <summary>
        /// ProcessDetroy is able to process the destroyed ships targets and remove _LastHit targets.
        /// It will also call RemoveShotsAround to remove targets that it was going to shoot at
        /// </summary>
        /// <param name="row">the row that was shot at and destroyed</param>
        /// <param name="col">the row that was shot at and destroyed</param>
        /// <param name="ship">the row that was shot at and destroyed</param>
        private void ProcessDestroy(int row, int col, Ship ship)
        {
            bool foundOriginal = false;
            Location source = default(Location);
            Target current = null;
            current = _CurrentTarget;

            foundOriginal = false;

            //i = 1, as we dont have targets from the current hit...
            int i = 0;

            for (i = 1; i <= ship.Hits - 1; i++) {
                if (!foundOriginal) {
                    source = current.Source;
                    //Source is nnothing if the ship was originally hit in
                    // the middle. This then searched forward, rather than
                    // backward through the list of targets
                    if (source == null) {
                        source = current.ShotAt;
                        foundOriginal = true;
                    }
                } else {
                    source = current.ShotAt;
                }

                //find the source in _LastHit
                foreach (Target t in _LastHit) {
                    if ((!foundOriginal && t.ShotAt == source) || (foundOriginal & t.Source == source)) {
                        current = t;
                        _LastHit.Remove(t);
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

                RemoveShotsAround(current.ShotAt);
            }
        }
Пример #7
0
using Microsoft.VisualBasic;
Пример #8
0
 /// <summary>
 /// Clearship will remove the ship from the tile
 /// </summary>
 public void ClearShip()
 {
     _Ship = null;
 }
Пример #9
0
 /// <summary>
 /// The tile constructor will know where it is on the grid, and is its a ship
 /// </summary>
 /// <param name="row">the row on the grid</param>
 /// <param name="col">the col on the grid</param>
 /// <param name="ship">what ship it is</param>
 public Tile(int row, int col, Ship ship)
 {
     _RowValue    = row;
     _ColumnValue = col;
     _Ship        = ship;
 }