private int PlusOneIfCellIsAlive( GameBoardCell[,] gameBoardCells, int xPosition, int yPosition ) { int height = gameBoardCells.GetLength( 0 ); int width = gameBoardCells.GetLength( 1 ); if ( xPosition < 0 | xPosition > height | yPosition < 0 | yPosition > width) { return 0; // out of bounds } if ( gameBoardCells[xPosition, yPosition].IsAlive ) { return 1; } return 0; }
public CellCoordinates Find( GameBoardCell[,] gameBoardCells, GameBoardCell cell ) { int w = gameBoardCells.GetLength( 0 ); // width int h = gameBoardCells.GetLength( 1 ); // height for ( int x = 0; x < w; ++x ) { for ( int y = 0; y < h; ++y ) { if ( gameBoardCells[x, y].Equals( cell ) ) { return new CellCoordinates { X = x, Y = y }; } } } throw new KeyNotFoundException(); }