예제 #1
0
        public bool Equals(Cell cell)
        {
            if (cell == null)
            return false;

              return this.GetHashCode() == cell.GetHashCode();
        }
예제 #2
0
        public bool AddCell(Cell cell)
        {
            if (!this._cells.Any())
              {
            this._cells.Add(cell);
            return true;
              }

              if (this._cells.Count < this._size)
              {
            bool valid = false;
            foreach (Cell shipCell in this._cells)
            {
              if (shipCell.Equals(cell))
            return false;
              valid = valid || shipCell.IsNeighbor(cell);
            }
            if (valid)
            {
              this._cells.Add(cell);
              return true;
            }
              }

              return false;
        }
예제 #3
0
 public bool IsNeighbor(Cell cell)
 {
     if (this.Equals(cell))
     return false;
       return this._x == cell._x && Math.Abs(this._y - cell._y) == 1 ||
      this._y == cell._y && Math.Abs(this._x - cell._x) == 1;
 }
예제 #4
0
 public bool RemoveCell(Cell cell)
 {
     return this._cells.Remove(cell);
 }