Exemple #1
0
 public void NewGame(int level)
 {
     _Clock.Stop();
     _Seconds = new DateTime(0);
     ClearBoard();
     for (int i = 0; i < 9; i++)
     {
         _RemainningNumbers[i].Remaining = 9;
     }
     if (level == 0)
     {
         _Sudoku.New(10);
     }
     else
     {
         _Sudoku.New(101);
     }
     _Sudoku.ClearNotes();
     //switch number
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             if (_Sudoku.IsFixedNumber(i, j))
             {
                 byte           value    = _Sudoku[i, j];
                 SudokuCellView cellview = _MiniCells[new MiniCellKey(i, j, value)];
                 ShowBigNumber(cellview, true);
             }
         }
     }
     _Clock.Interval = 1000;
     Time            = "00:00";
     _Clock.Start();
 }
Exemple #2
0
 private void ShowBigNumber(SudokuCellView cellview, bool IsFixed)
 {
     if (_CellControls.ContainsKey(cellview.Position))
     {
         _CellControls[cellview.Position].DataContext = cellview;
         _CellControls[cellview.Position].Visibility  = Visibility.Visible;
     }
     else
     {
         Button big = new Button();
         big.Visibility = Visibility.Collapsed;
         //me permet de gérer les nombres non "clickable"
         if (!IsFixed)
         {
             big.MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(OnCellDoubleClick);
         }
         big.DataContext = cellview;
         big.Template    = this.CellTemplate;
         _Grid.Children.Add(big);
         Grid.SetColumn(big, (int)(cellview.Position.X * 6 + 1));
         Grid.SetRow(big, (int)(cellview.Position.Y * 6 + 1));
         Grid.SetColumnSpan(big, 5);
         Grid.SetRowSpan(big, 5);
         big.VerticalAlignment   = VerticalAlignment.Stretch;
         big.HorizontalAlignment = HorizontalAlignment.Stretch;
         _CellControls.Add(cellview.Position, big);
         big.Visibility = Visibility.Visible;
     }
 }
Exemple #3
0
        void OnCellClick(object sender, RoutedEventArgs e)
        {
            Button         b        = (sender as Button);
            SudokuCellView cellview = b.DataContext as SudokuCellView;

            if (cellview.IsMiniCell && !cellview.IsFlagged)
            {
                cellview.CheckUnCheck();
            }
        }
Exemple #4
0
        void OnCellFlagClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Button         b        = (sender as Button);
            SudokuCellView cellview = b.DataContext as SudokuCellView;

            if (cellview.IsMiniCell)
            {
                cellview.FlagUnFlag();
            }
        }
Exemple #5
0
        void OnCellDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Button         b        = (sender as Button);
            SudokuCellView cellview = b.DataContext as SudokuCellView;

            ///inversion
            cellview.IsMiniCell = !cellview.IsMiniCell;
            if (cellview.IsMiniCell)
            {
                b.Visibility = Visibility.Collapsed;
                _Sudoku.AddCoup(cellview.X, cellview.Y, 0);
            }
        }
Exemple #6
0
        void OnMiniCellDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Button         b        = (sender as Button);
            SudokuCellView cellview = b.DataContext as SudokuCellView;

            if (cellview.IsMiniCell)
            {
                cellview.CheckUnCheck();
                cellview.IsMiniCell = !cellview.IsMiniCell;
                _Sudoku.AddCoup(cellview.X, cellview.Y, (byte)cellview.Number);
                ShowBigNumber(cellview, false);
            }
        }
Exemple #7
0
        public SudokuGrid()
        {
            _Sudoku            = new Sudoku();
            _RemainningNumbers = new List <SudokuNumber>();
            for (int i = 1; i <= 9; i++)
            {
                _RemainningNumbers.Add(new SudokuNumber(i, 9));
            }
            _Sudoku.OnWin              += new EventHandler <EventArgs>(_Sudoku_OnWin);
            _Sudoku.OnGameBegin        += new EventHandler <EventArgs>(_Sudoku_OnGameBegin);
            _Sudoku.OnRemainingChanged += new EventHandler <RemainingEventArgs>(_Sudoku_OnRemainingChanged);
            _Grid = new Grid();
            Binding binding = new Binding("Background");

            binding.Source = this;
            binding.Mode   = BindingMode.OneWay;
            _Grid.SetBinding(Grid.BackgroundProperty, binding);

            _MiniCellControls = new List <Button>();
            _CellControls     = new Dictionary <Point, Button>();
            _MiniCells        = new Dictionary <MiniCellKey, SudokuCellView>();
            _Clock            = new Timer(1000);
            //_Clock.
            _Clock.Elapsed += new ElapsedEventHandler(_Clock_Elapsed);

            this.Content = _Grid;
            //27 *2 lignes
            for (int i = 0; i < 27 * 2 + 1; i++)
            {
                RowDefinition row = new RowDefinition();
                row.Height = CreateGridLength(i);

                _Grid.RowDefinitions.Add(row);
            }
            //27*2 colonnes
            for (int i = 0; i < 27 * 2 + 1; i++)
            {
                ColumnDefinition col = new ColumnDefinition();

                col.Width = CreateGridLength(i);
                _Grid.ColumnDefinitions.Add(col);
            }
            //le fond de la grille est défini pa l'utilisateur, ce fond sera utilisé pour afficher les lignes
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    Rectangle r = new Rectangle();
                    r.Opacity = 0.8;
                    r.Fill    = Brushes.LightGray;
                    Grid.SetColumn(r, j * 6 + 1);
                    Grid.SetColumnSpan(r, 5);
                    Grid.SetRow(r, i * 6 + 1);
                    Grid.SetRowSpan(r, 5);
                    _Grid.Children.Add(r);
                }
            }
            _Grid.ShowGridLines = false;
            //Ajout des mini cellules
            for (int i = 0; i < 27; i++)
            {
                for (int j = 0; j < 27; j++)
                {
                    Button b = new Button();
                    b.MouseDoubleClick   += new System.Windows.Input.MouseButtonEventHandler(OnMiniCellDoubleClick);
                    b.Click              += new RoutedEventHandler(OnCellClick);
                    b.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(OnCellFlagClick);
                    _MiniCellControls.Add(b);
                    int x = j % 3;
                    int y = i % 3;
                    b.Content = (y * 3 + x + 1);
                    SudokuCellView scv = new SudokuCellView(_Sudoku, (int)j / 3, (int)i / 3, y * 3 + x + 1);
                    b.DataContext = scv;
                    _MiniCells.Add(new MiniCellKey((int)scv.Position.X, (int)scv.Position.Y, (byte)scv.Number), scv);
                    _Grid.Children.Add(b);
                    Grid.SetColumn(b, j * 2 + 1);
                    Grid.SetRow(b, i * 2 + 1);
                    b.VerticalAlignment   = VerticalAlignment.Stretch;
                    b.HorizontalAlignment = HorizontalAlignment.Stretch;
                }
            }
            this.Content = _Grid;
        }