private void UpdateWindow()
        {
            int n_flagged = 0;

            for (int i = 0; i < flagged.GetLength(0); i++)
            {
                for (int j = 0; j < flagged.GetLength(1); j++)
                {
                    if (flagged[i, j] == true)
                    {
                        n_flagged++;
                    }
                }
            }
            NUMBER_MINES.Text = Convert.ToString(game.GetNumberMines() - n_flagged);

            for (int i = 0; i < game.GetRows(); i++)
            {
                for (int j = 0; j < game.GetCols(); j++)
                {
                    if (game.GetField()[i, j].IsOpen() == false)
                    {
                        if (flagged[i, j] == true)
                        {
                            buttons[i, j].Content = "\uD83C\uDFF3";

                            //buttons[i, j].Background = System.Windows.Media.Brushes.Green;
                            buttons[i, j].FontWeight = FontWeights.Bold;
                        }
                        else
                        {
                            buttons[i, j].Content    = "";
                            buttons[i, j].Background = System.Windows.Media.Brushes.DarkGray;
                        }
                    }
                    else if (game.GetField()[i, j].IsMine() == true)
                    {
                        buttons[i, j].Content    = "\uD83D\uDCA3";
                        buttons[i, j].FontSize   = 20.0;
                        buttons[i, j].Background = System.Windows.Media.Brushes.Red;
                        buttons[i, j].FontWeight = FontWeights.Bold;
                    }
                    else
                    {
                        int nM = game.GetField()[i, j].GetNNeighbouringMines();
                        buttons[i, j].Content    = (nM > 0) ? Convert.ToString(nM) : "";
                        buttons[i, j].Foreground = colors[nM];
                        buttons[i, j].Background = System.Windows.Media.Brushes.LightGray;
                        buttons[i, j].FontSize   = 20.0;
                        buttons[i, j].FontWeight = FontWeights.Bold;
                    }
                }
            }
        }
        public MinesweeperWindow(string mode, MainWindow main_window)
        {
            main_window.Close();
            InitializeComponent();
            game = new Field();
            game.StartSession(mode);

            buttons = new Button[game.GetRows(), game.GetCols()];
            flagged = new bool[game.GetRows(), game.GetCols()];

            this.Height = game.GetRows() * CELL_SIZE;
            this.Width  = game.GetCols() * CELL_SIZE;

            GRID_VAR.Rows    = game.GetRows();
            GRID_VAR.Columns = game.GetCols();

            GRID_VAR.Height = game.GetRows() * CELL_SIZE;
            GRID_VAR.Width  = game.GetCols() * CELL_SIZE;

            for (int i = 0; i < game.GetRows(); i++)
            {
                for (int j = 0; j < game.GetCols(); j++)
                {
                    System.Windows.Controls.Button newBtn = new Button();

                    newBtn.Content             = "";
                    newBtn.Name                = ("B" + (i * game.GetCols() + j)).ToString();
                    newBtn.Click              += Button_Click;
                    newBtn.MouseRightButtonUp += RightClick;
                    newBtn.MouseDoubleClick   += DoubleClick;
                    //newBtn.Width = CELL_SIZE;
                    //newBtn.Height = CELL_SIZE;
                    newBtn.BorderBrush     = Brushes.Black;
                    newBtn.BorderThickness = new Thickness(0.5);

                    GRID_VAR.Children.Add(newBtn);
                    buttons[i, j] = newBtn;


                    flagged[i, j] = false;
                }
            }

            timer          = new DispatcherTimer();
            timer.Tick    += UpdateTime;
            timer.Interval = new TimeSpan(0, 0, 0, 0, 1000);

            //this.MaxWidth = this.MinWidth = this.Width;
            //this.MaxHeight = this.MinHeight = this.Height;

            UpdateWindow();

            TIME.Text = secCounter.ToString("000");
        }