public bool Equals(Cell cell) { if (cell == null) return false; return this.GetHashCode() == cell.GetHashCode(); }
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; }
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; }
public bool RemoveCell(Cell cell) { return this._cells.Remove(cell); }