Ejemplo n.º 1
0
        private void InitBoard(int width, int height, int numOfMines)
        {
            _board = new Board(width, height, numOfMines);
            var w = width * _size;
            var h = height * _size;

            this.Width      = w + 50;
            this.Height     = h + 100;
            this.ResizeMode = System.Windows.ResizeMode.CanResize;

            grdMain.Height = h + 50;

            grdGameArea.Width  = w;
            grdGameArea.Height = h;

            grdGameArea.Children.Clear();
            grdGameArea.ColumnDefinitions.Clear();
            grdGameArea.RowDefinitions.Clear();

            for (int i = 0; i < width; i++)
            {
                var colDef = new ColumnDefinition();
                colDef.Width = new GridLength(_size);
                grdGameArea.ColumnDefinitions.Add(colDef);
            }

            for (int i = 0; i < height; i++)
            {
                var rowDef = new RowDefinition();
                rowDef.Height = new GridLength(_size);
                grdGameArea.RowDefinitions.Add(rowDef);
            }

            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    var ucCell = new UC_Cell(row, col, _board.Cells[row, col]);
                    (ucCell.DataContext as CellVM).IsOpened = false;

                    ucCell.btnContent.Click   += btnContent_Click;
                    ucCell.OnCellRightClicked += Cell_RightClicked;

                    Grid.SetColumn(ucCell, col);
                    Grid.SetRow(ucCell, row);

                    grdGameArea.Children.Add(ucCell);
                }
            }

            this.ResizeMode = System.Windows.ResizeMode.NoResize;
        }
Ejemplo n.º 2
0
        private void InitBoard(int width, int height, int numOfMines)
        {
            _board = new Board(width, height, numOfMines);
            var w = width * _size;
            var h = height * _size;

            this.Width = w + 50;
            this.Height = h + 100;
            this.ResizeMode = System.Windows.ResizeMode.CanResize;

            grdMain.Height = h + 50;

            grdGameArea.Width = w;
            grdGameArea.Height = h;

            grdGameArea.Children.Clear();
            grdGameArea.ColumnDefinitions.Clear();
            grdGameArea.RowDefinitions.Clear();

            for (int i = 0; i < width; i++)
            {
                var colDef = new ColumnDefinition();
                colDef.Width = new GridLength(_size);
                grdGameArea.ColumnDefinitions.Add(colDef);
            }

            for (int i = 0; i < height; i++)
            {
                var rowDef = new RowDefinition();
                rowDef.Height = new GridLength(_size);
                grdGameArea.RowDefinitions.Add(rowDef);
            }

            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    var ucCell = new UC_Cell(row, col, _board.Cells[row, col]);
                    (ucCell.DataContext as CellVM).IsOpened = false;

                    ucCell.btnContent.Click += btnContent_Click;
                    ucCell.OnCellRightClicked += Cell_RightClicked;

                    Grid.SetColumn(ucCell, col);
                    Grid.SetRow(ucCell, row);

                    grdGameArea.Children.Add(ucCell);
                }
            }

            this.ResizeMode = System.Windows.ResizeMode.NoResize;
        }