public override bool Equals(object obj) { try { LivingCell testCell = (LivingCell)obj; return(myCoordinate.Equals(testCell.myCoordinate) && myGrid == testCell.myGrid); } catch { return(false); } }
public void AddCellAtCoordinate(int x, int y) { LivingCell cellToAdd = new LivingCell(x, y, this); LivingCell ExistingCell = FindCellAtCoordinate(cellToAdd.Coordinate); if (ExistingCell == null) { _livingCells.Add(cellToAdd.Coordinate, cellToAdd); } else { throw new ApplicationException(string.Format("There shouldn't be any need to add another cell to Coordinate x: {0}, y: {1}. there is already one", x, y)); } }
public int NumberOfSurroundingLivingCells(Map grid) { Coordinate[] surroundingCoordinates = SurroundingCoordinates(); int number = 0; foreach (Coordinate coordinate in surroundingCoordinates) { LivingCell testCell = grid.FindCellAtCoordinate(coordinate); if (testCell != null) { number++; } } return(number); }
public bool RemoveCell(LivingCell cell) { return(RemoveCellAtCoordinate(cell.Coordinate)); }