示例#1
0
void clickTile(GameBoard *g, int row, int col) {
    
	// if the tile has no neighbouring mines AND is covered (0 value)..
    if ( g->board[row][col].numOfMines==0 && g->board[row][col].isVisible==FALSE)
    {
		if (row < g->rows-1 && g->board[row][col].numOfMines==0 && g->board[row+1][col].numOfMines>=0 && g->board[row+1][col].isVisible<=0) { //can go right
			g->board[row][col].isVisible=1;
			clickTile(g, row+1, col);
		}
		if (col < g->cols-1 && g->board[row][col].numOfMines==0 && g->board[row][col+1].numOfMines>=0 && g->board[row][col+1].isVisible==0) { //can go down
			g->board[row][col].isVisible=1;
			clickTile(g, row, col+1);
		}
		if (row > 0 && g->board[row][col].numOfMines==0 && g->board[row-1][col].numOfMines>=0 && g->board[row-1][col].isVisible<=0) { //can go left
			g->board[row][col].isVisible=1;
			clickTile(g, row-1, col);
		}
		if (col > 0 && g->board[row][col].numOfMines==0 && g->board[row][col-1].numOfMines>=0 && g->board[row][col-1].isVisible<=0) { //can go up
			g->board[row][col].isVisible=1;
			clickTile(g, row, col-1);
		}

		g->board[row][col].isVisible=TRUE;
    }

    // if the tile neighbours a mine and is covered (0 < value)..
	if ( g->board[row][col].numOfMines>0 && g->board[row][col].isVisible==FALSE)
	{
		g->board[row][col].isVisible=TRUE;
	}

	// if the tile is uncovered then don't do anything
    if (g->board[row][col].isVisible==TRUE) return;
    // if the tile is flagged then it shouldn't be uncovered
    else if (g->board[row][col].isFlagged==TRUE) return;
    // if the tile is a mine, set the losing condition
    else if (g->board[row][col].isMine==TRUE) {
    	g->board[row][col].isVisible = 1;
    	g->isMineClicked = 1;
    }
    // uncover the tile
    else {
    	g->board[row][col].isVisible=1;
    	g->board[row][col].isFlagged=0;
    } 
}
示例#2
0
void clickTile(GameBoard *g, int row, int col)
{
	int i,j;
	if( !(*(g->board+row)+col)->isVisible &&  !(*(g->board+row)+col)->isFlagged )
	{
		if( (*(g->board+row)+col)->isMine)
		{
			// clicked on mine, oops
			(*(g->board+row)+col)->isVisible = TRUE;
			g->isMineClicked = TRUE;
		}
		else
		{
			if( (*(g->board+row)+col)->numOfMines > 0)
			{
				(*(g->board+row)+col)->isVisible = TRUE;
				g->hiddenTiles--;
			}
			else
			{
				// number of îeighbors mines = 0
				// call this function for all neighbors
				(*(g->board+row)+col)->isVisible = TRUE;
				g->hiddenTiles--;
				for(i=row-1; i<=row+1; i++)
				{
					for(j=col-1; j<=col+1; j++)
					{
						if( i>=0 && i<(g->rows) && j>=0 && j<(g->cols) && !(i==row && j==col) )
							clickTile(g, i, j);
					}
				}
			}
		}		
	}
}