Example #1
0
        public override bool Equals(object obj)
        {
            try
            {
                LivingCell testCell = (LivingCell)obj;

                return(myCoordinate.Equals(testCell.myCoordinate) && myGrid == testCell.myGrid);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        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));
            }
        }
Example #3
0
        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);
        }
Example #4
0
 public bool RemoveCell(LivingCell cell)
 {
     return(RemoveCellAtCoordinate(cell.Coordinate));
 }