1
0
Fork 0
forked from len0rd/rockbox

Clicking on a discovered tile with its number of adjacent mines already flagged now clicks on all adjacent undiscovered and unflagged tiles.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24126 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Antoine Cellerier 2009-12-30 16:15:01 +00:00
parent 4c01e05c63
commit 3358f0e925

View file

@ -389,18 +389,58 @@ void unveil( int *stack, int y, int x )
push( stack, y, x ); push( stack, y, x );
} }
void discover( int y, int x ) int is_flagged( int y, int x )
{ {
int stack[height*width]; if( x >= 0 && y >= 0 && x < width && y < height && minefield[y][x].flag )
return 1;
return 0;
}
int neighbors_flagged( int y, int x )
{
return is_flagged( y-1, x-1 ) +
is_flagged( y-1, x ) +
is_flagged( y-1, x+1 ) +
is_flagged( y, x-1 ) +
is_flagged( y, x ) +
is_flagged( y, x+1 ) +
is_flagged( y+1, x-1 ) +
is_flagged( y+1, x ) +
is_flagged( y+1, x+1 );
}
bool discover( int y, int x, bool explore_neighbors )
{
/* Selected tile. */ /* Selected tile. */
if( x < 0 || y < 0 || x > width - 1 || y > height - 1 if( x < 0 || y < 0 || x > width - 1 || y > height - 1
|| minefield[y][x].known || minefield[y][x].known
|| minefield[y][x].mine || minefield[y][x].flag ) return; || minefield[y][x].mine || minefield[y][x].flag )
{
if( !minefield[y][x].flag && minefield[y][x].mine )
return true;
if( explore_neighbors && minefield[y][x].known &&
minefield[y][x].neighbors == neighbors_flagged( y, x ) )
{
return discover( y-1, x-1, false ) ||
discover( y-1, x, false ) ||
discover( y-1, x+1, false ) ||
discover( y, x-1, false ) ||
discover( y, x, false ) ||
discover( y, x+1, false ) ||
discover( y+1, x-1, false ) ||
discover( y+1, x, false ) ||
discover( y+1, x+1, false );
}
return false;
}
minefield[y][x].known = 1; minefield[y][x].known = 1;
/* Exit if the tile is not empty. (no mines nearby) */ /* Exit if the tile is not empty. (no mines nearby) */
if( minefield[y][x].neighbors ) return; if( minefield[y][x].neighbors ) return false;
int stack[height*width];
push( stack, y, x ); push( stack, y, x );
@ -423,6 +463,8 @@ void discover( int y, int x )
unveil( stack, y+1, x-1 ); unveil( stack, y+1, x-1 );
unveil( stack, y, x-1 ); unveil( stack, y, x-1 );
} }
return false;
} }
/* Reset the whole board for a new game. */ /* Reset the whole board for a new game. */
@ -775,13 +817,12 @@ enum minesweeper_status minesweeper( void )
if( tiles_left == width*height && no_mines ) if( tiles_left == width*height && no_mines )
minesweeper_putmines(p,x,y); minesweeper_putmines(p,x,y);
discover(y, x); if( discover( y, x, true ) )
if( minefield[y][x].mine )
{ {
minefield[y][x].known = 1; minefield[y][x].known = 1;
return MINESWEEPER_LOSE; return MINESWEEPER_LOSE;
} }
tiles_left = count_tiles_left(); tiles_left = count_tiles_left();
if( tiles_left == mine_num ) if( tiles_left == mine_num )
{ {