Пример #1
0
        private void Cell_SourceUpdated(object sender, DataTransferEventArgs e)
        {
            _ = new TextBox();
            TextBox TextSender = (TextBox)sender;

            new MultiBinding();
            MultiBinding MultiBindText = BindingOperations.GetMultiBinding(TextSender, TextBox.TextProperty);

            new Binding();
            Binding Bind0 = (Binding)MultiBindText.Bindings[0];

            int rowText = Grid.GetRow(TextSender);

            new RowPuzzle(rowText);
            RowPuzzle SourceBindR = (RowPuzzle)Bind0.Source;

            if (SourceBindR.ParentGrid.Win())
            {
                SourceBindR.ParentGrid.OnWinTrigger();
            }
        }
Пример #2
0
        private void Play(int nbRows_Per_Block, int nbCols_Per_Block, int[,] Puzzle)
        {
            Window WindSudoku = new Window
            {
                Width  = 700,
                Height = 700
            };

            Grid GridUser = new Grid();

            ModelSudoku VmSudoku = new ModelSudoku(nbRows_Per_Block, nbCols_Per_Block);

            VmSudoku.Initialiser(Puzzle);

            for (int IndexSudoku = 0; IndexSudoku < VmSudoku.NbRows_Per_Block * VmSudoku.NbCols_Per_Block; IndexSudoku++)
            {
                RowDefinition Row = new RowDefinition();
                GridUser.RowDefinitions.Add(Row);

                ColumnDefinition Col = new ColumnDefinition();
                GridUser.ColumnDefinitions.Add(Col);
            }

            WindSudoku.Content = GridUser;


            int indexRowCell_In_Block;
            int indexColCell_In_Block;

            int indexRowBlock_In_Sudoku;
            int indexColBlock_In_Sudoku;

            int indexRowCell_In_GridUser;
            int indexColCell_In_GridUser;

            int nbBlocksRow = VmSudoku.NbCols_Per_Block;
            int nbBlocksCol = VmSudoku.NbRows_Per_Block;

            int indexRowBorder;
            int indexColBorder;

            int index_In_BlockArray1D;



            //TEXTBOX: Enter a number, and TEXTBLOCK: constant

            for (indexRowBlock_In_Sudoku = 0; indexRowBlock_In_Sudoku < nbBlocksRow; indexRowBlock_In_Sudoku++)
            {
                for (indexColBlock_In_Sudoku = 0; indexColBlock_In_Sudoku < nbBlocksCol; indexColBlock_In_Sudoku++)
                {
                    for (indexRowCell_In_Block = 0; indexRowCell_In_Block < VmSudoku.NbRows_Per_Block; indexRowCell_In_Block++)
                    {
                        for (indexColCell_In_Block = 0; indexColCell_In_Block < VmSudoku.NbCols_Per_Block; indexColCell_In_Block++)
                        {
                            if (Puzzle[VmSudoku.Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku), VmSudoku.Column_In_Sudoku(indexRowCell_In_Block, indexColCell_In_Block)] == 0)
                            {
                                TextBox Cell = new TextBox
                                {
                                    HorizontalAlignment = HorizontalAlignment.Stretch,
                                    VerticalAlignment   = VerticalAlignment.Stretch,
                                    TextAlignment       = TextAlignment.Center,
                                    FontSize            = 35,
                                };

                                GridUser.Children.Add(Cell);


                                Grid.SetRow(Cell, VmSudoku.Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block));
                                Grid.SetColumn(Cell, VmSudoku.Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block));

                                _ = new RowPuzzle(VmSudoku.Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block));
                                RowPuzzle RowP = (RowPuzzle)VmSudoku.Array_Rows[VmSudoku.Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block)];

                                Binding BindRow = new Binding
                                {
                                    Source = RowP,
                                    Path   = new PropertyPath(string.Format("Array1D[{0}]", VmSudoku.Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block)))
                                };


                                _ = new ColumnPuzzle(VmSudoku.Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block));
                                ColumnPuzzle ColP = (ColumnPuzzle)VmSudoku.Array_Cols[VmSudoku.Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block)];

                                Binding BindCol = new Binding
                                {
                                    Source = ColP,
                                    Path   = new PropertyPath(string.Format("Array1D[{0}]", VmSudoku.Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block)))
                                };

                                index_In_BlockArray1D = indexColCell_In_Block + VmSudoku.NbCols_Per_Block * indexRowCell_In_Block;

                                Binding BindBlock = new Binding
                                {
                                    Source = (BlockPuzzle)VmSudoku.Array_Blocks[VmSudoku.Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku)],
                                    Path   = new PropertyPath(string.Format("Array1D[{0}]", VmSudoku.IndexArray1D_In_Block(indexRowCell_In_Block, indexColCell_In_Block)))
                                };

                                MultiBinding MultiBind = new MultiBinding
                                {
                                    UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                                    NotifyOnSourceUpdated = true,
                                    Mode = BindingMode.OneWayToSource,

                                    Converter = new MultiConverterTab()
                                };

                                MultiBind.Bindings.Add(BindRow);
                                MultiBind.Bindings.Add(BindCol);
                                MultiBind.Bindings.Add(BindBlock);

                                Cell.SetBinding(TextBox.TextProperty, MultiBind);

                                Cell.SourceUpdated += Cell_SourceUpdated;

                                //Cell.TextChanged += Cell_TextChanged;
                            }
                            else
                            {
                                TextBlock Cell = new TextBlock
                                {
                                    Background          = Brushes.LightGray,
                                    FontWeight          = FontWeights.Bold,
                                    HorizontalAlignment = HorizontalAlignment.Stretch,
                                    VerticalAlignment   = VerticalAlignment.Stretch,
                                    TextAlignment       = TextAlignment.Center,
                                    FontSize            = 35,
                                    Text = Puzzle[VmSudoku.Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku), VmSudoku.Column_In_Sudoku(indexRowCell_In_Block, indexColCell_In_Block)].ToString()
                                };

                                GridUser.Children.Add(Cell);

                                Grid.SetRow(Cell, VmSudoku.Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block));
                                Grid.SetColumn(Cell, VmSudoku.Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block));
                            }
                        }
                    }
                }
            }

            //BORDERS
            for (indexRowBlock_In_Sudoku = 0; indexRowBlock_In_Sudoku < nbBlocksRow; indexRowBlock_In_Sudoku++)
            {
                indexRowBorder = indexRowBlock_In_Sudoku * VmSudoku.NbRows_Per_Block;


                for (indexColBlock_In_Sudoku = 0; indexColBlock_In_Sudoku < nbBlocksCol; indexColBlock_In_Sudoku++)
                {
                    //THIN BORDERS
                    for (indexRowCell_In_Block = 0; indexRowCell_In_Block < VmSudoku.NbRows_Per_Block; indexRowCell_In_Block++)
                    {
                        for (indexColCell_In_Block = 0; indexColCell_In_Block < VmSudoku.NbCols_Per_Block; indexColCell_In_Block++)
                        {
                            Border ThinBord = new Border
                            {
                                BorderThickness = new Thickness(1),
                                BorderBrush     = Brushes.Gray
                            };

                            indexRowCell_In_GridUser = indexRowCell_In_Block + VmSudoku.NbRows_Per_Block * indexRowBlock_In_Sudoku;
                            indexColCell_In_GridUser = indexColCell_In_Block + VmSudoku.NbCols_Per_Block * indexColBlock_In_Sudoku;

                            GridUser.Children.Add(ThinBord);

                            Grid.SetRow(ThinBord, indexRowCell_In_GridUser);
                            Grid.SetColumn(ThinBord, indexColCell_In_GridUser);
                        }
                    }


                    //THICK BORDERS
                    Border ThickBord = new Border
                    {
                        BorderThickness = new Thickness(5),
                        BorderBrush     = Brushes.Black
                    };

                    GridUser.Children.Add(ThickBord);


                    indexColBorder = indexColBlock_In_Sudoku * VmSudoku.NbCols_Per_Block;

                    Grid.SetRow(ThickBord, indexRowBorder);
                    Grid.SetColumn(ThickBord, indexColBorder);

                    Grid.SetRowSpan(ThickBord, VmSudoku.NbRows_Per_Block);
                    Grid.SetColumnSpan(ThickBord, VmSudoku.NbCols_Per_Block);
                }
            }

            VmSudoku.EventWin += VmSudoku_EventWin;

            WindSudoku.Show();
        }
Пример #3
0
        public void Initialiser(int[,] Tab)
        {
            int indexRowCell_In_Block;
            int indexColCell_In_Block;

            int indexRowBlock_In_Sudoku;
            int indexColBlock_In_Sudoku;


            int nbBlocksRow = NbCols_Per_Block;
            int nbBlocksCol = NbRows_Per_Block;

            int Id_Row;
            int Id_Col;



            //Creation of 9 Rows
            for (indexRowBlock_In_Sudoku = 0; indexRowBlock_In_Sudoku < nbBlocksRow; indexRowBlock_In_Sudoku++)
            {
                for (indexRowCell_In_Block = 0; indexRowCell_In_Block < NbRows_Per_Block; indexRowCell_In_Block++)
                {
                    Id_Row = Row_In_GridUser(indexRowBlock_In_Sudoku, indexRowCell_In_Block);
                    RowPuzzle RowP = new RowPuzzle(Id_Row)
                    {
                        ParentGrid = this
                    };

                    for (indexColBlock_In_Sudoku = 0; indexColBlock_In_Sudoku < nbBlocksCol; indexColBlock_In_Sudoku++)
                    {
                        for (indexColCell_In_Block = 0; indexColCell_In_Block < NbCols_Per_Block; indexColCell_In_Block++)
                        {
                            RowP.Array1D.Add(Tab[Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku), Column_In_Sudoku(indexRowCell_In_Block, indexColCell_In_Block)]);
                        }
                    }

                    Array_Rows.Add(RowP);
                }
            }

            //Creation of 9 Columns
            for (indexColBlock_In_Sudoku = 0; indexColBlock_In_Sudoku < nbBlocksCol; indexColBlock_In_Sudoku++)
            {
                for (indexColCell_In_Block = 0; indexColCell_In_Block < NbCols_Per_Block; indexColCell_In_Block++)
                {
                    Id_Col = Column_In_GridUser(indexColBlock_In_Sudoku, indexColCell_In_Block);

                    ColumnPuzzle ColP = new ColumnPuzzle(Id_Col);

                    for (indexRowBlock_In_Sudoku = 0; indexRowBlock_In_Sudoku < nbBlocksRow; indexRowBlock_In_Sudoku++)
                    {
                        for (indexRowCell_In_Block = 0; indexRowCell_In_Block < NbRows_Per_Block; indexRowCell_In_Block++)
                        {
                            ColP.Array1D.Add(Tab[Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku), Column_In_Sudoku(indexRowCell_In_Block, indexColCell_In_Block)]);
                        }
                    }

                    Array_Cols.Add(ColP);
                }
            }

            //Creation of 9 Blocks
            for (indexRowBlock_In_Sudoku = 0; indexRowBlock_In_Sudoku < nbBlocksRow; indexRowBlock_In_Sudoku++)
            {
                for (indexColBlock_In_Sudoku = 0; indexColBlock_In_Sudoku < nbBlocksCol; indexColBlock_In_Sudoku++)
                {
                    BlockPuzzle BlockP = new BlockPuzzle(NbRows_Per_Block, NbCols_Per_Block, indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku);

                    for (indexRowCell_In_Block = 0; indexRowCell_In_Block < NbRows_Per_Block; indexRowCell_In_Block++)
                    {
                        for (indexColCell_In_Block = 0; indexColCell_In_Block < NbCols_Per_Block; indexColCell_In_Block++)
                        {
                            BlockP.Array1D.Add(Tab[Row_In_Sudoku(indexRowBlock_In_Sudoku, indexColBlock_In_Sudoku), Column_In_Sudoku(indexRowCell_In_Block, indexColCell_In_Block)]);
                        }
                    }

                    Array_Blocks.Add(BlockP);
                }
            }
        }