Created
January 11, 2016 22:33
-
-
Save newradius/ff8241ed81c2e7a587e0 to your computer and use it in GitHub Desktop.
Recursividad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reveal neightbours with recursion | |
public void findNeighbors(int row, int col) { | |
if ((row >= 0 && row <= BOARD_SIZE - 1) && (col >= 0 && col <= BOARD_SIZE - 1)) { //Check if row and col is not out of board | |
if ((cell[row][col].getState() != ButtonState.OPEN) && (((Integer) (cell[row][col].getTag())) != -1) | |
&& (cell[row][col].getState() != ButtonState.FLAG) && (cell[row][col].getState() != ButtonState.INTERROGANT) | |
&& (((Integer) (cell[row][col].getTag())) == 0)) { | |
cell[row][col].setBackgroundResource(R.drawable.boton_opened); | |
cell[row][col].setState(ButtonState.OPEN); | |
findNeighbors(row - 1, col); | |
findNeighbors(row - 1, col - 1); | |
findNeighbors(row - 1, col + 1); | |
findNeighbors(row, col - 1); | |
findNeighbors(row, col + 1); | |
findNeighbors(row + 1, col - 1); | |
findNeighbors(row + 1, col); | |
findNeighbors(row + 1, col + 1); | |
} else if ((((Integer) (cell[row][col].getTag())) > 0) // Not empty | |
&& (cell[row][col].getState() != ButtonState.FLAG) && // Not flag | |
(((Integer) (cell[row][col].getTag())) != -1) && //Not bomb | |
(cell[row][col].getState() != ButtonState.INTERROGANT)) { //Not interrogant | |
cell[row][col].setBackgroundResource(R.drawable.boton_opened); | |
cell[row][col].setState(ButtonState.OPEN); | |
cell[row][col].setText(String.valueOf(cell[row][col].getTag())); | |
cell[row][col].setTextColor(numberColor(cell[row][col])); | |
//cell[row][col].setTextSize(10); | |
cell[row][col].setTypeface(null,Typeface.BOLD); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment