public class board{ final int rows, cols; final cell[][] cells; public board(int numbRows, int numbCols){ rows = numbRows; cols = numbCols; cells = new cell[numbRows][numbCols]; fillWithCells(); } public void makeCell(int row, int col){ cell cell = new cell(row, col); cells[row][col] = cell; } public void fillWithCells(){ for(int x = 0; x < rows; x++){ for(int y = 0; y < cols; y++){ makeCell(x, y); } } } public cell getCell(int row, int col){ if(row < 0 || row >= rows) return null; if(col < 0 || col >= cols) return null; return cells[row][col]; } public cell[][] getCells(){ return cells; } public void generateFood(){ int row = 0; int col = 0; while(true){ row = (int)(Math.random() * rows); col = (int)(Math.random() * cols); if(!cells[row][col].isSnakeCell){ cells[row][col].setFoodCell(true); break; } } } }