private static void ShowEmpty(int x, int y, Board board, Grid grid) { if (x < 0 || x > 8) { return; } if (y < 0 || y > 8) { return; } if (board.pola[x, y].visible) { return; } if (board.pola[x, y].value != 9 && board.pola[x, y].visible == false) { board.pola[x, y].visible = true; numbersOfVisible--; Button button = (LogicalTreeHelper.FindLogicalNode(grid, "b_" + x + y)) as Button; if (board.pola[x, y].value != 0) { button.Content = board.pola[x, y].value; button.Foreground = NumberColors.GetColor(board.pola[x, y].value); } else { button.IsEnabled = false; } } if (board.pola[x, y].flagged) { board.pola[x, y].flagged = false; numberOfMinesByPlayer++; Label minesCounter = grid.FindName("minesCounter") as Label; minesCounter.Content = numberOfMinesByPlayer; Button btn = (LogicalTreeHelper.FindLogicalNode(grid, "b_" + x + y)) as Button; btn.Content = null; } if (board.pola[x, y].value != 0) { return; } ShowEmpty(x, y, board, grid); ShowEmpty(x - 1, y - 1, board, grid); ShowEmpty(x - 1, y, board, grid); ShowEmpty(x - 1, y + 1, board, grid); ShowEmpty(x + 1, y - 1, board, grid); ShowEmpty(x + 1, y, board, grid); ShowEmpty(x + 1, y + 1, board, grid); ShowEmpty(x, y - 1, board, grid); ShowEmpty(x, y + 1, board, grid); }
public static void Pole_Click(object sender, EventArgs e, Board board, DispatcherTimer dispatcherTimer, Grid grid) { Button btn = sender as Button; string name = btn.Name; int x = int.Parse(name[2].ToString()); int y = int.Parse((name[3]).ToString()); if (firstClick) { firstClick = false; board.GenerateMines(x, y); } if (!board.pola[x, y].flagged && !gameWon && !gameOver) { dispatcherTimer.Start(); if (board.pola[x, y].value == 0) { ShowEmpty(x, y, board, grid); } else if (board.pola[x, y].value == 9) { Image image = btn.Content as Image; image.Visibility = Visibility.Visible; image.Source = new BitmapImage(new Uri("/Minesweeper;component/img/mine.png", UriKind.Relative)); btn.IsEnabled = false; Fail(board, dispatcherTimer, grid); } else { btn.Content = board.pola[x, y].value; btn.Foreground = NumberColors.GetColor(board.pola[x, y].value); if (!board.pola[x, y].visible) { board.pola[x, y].visible = true; numbersOfVisible--; } } CheckWin(board, dispatcherTimer, grid); } }