コード例 #1
0
ファイル: SudokuGrid.xaml.cs プロジェクト: delner/sudoku
        public SudokuGrid()
        {
            InitializeComponent();

            this._puzzle = new SudokuPuzzle() { Rank = 3 };
            this._zones = new SudokuZone[this._puzzle.Rank, this._puzzle.Rank];

            // Load the UI
            StackPanel gridStackPanel = new StackPanel() { Orientation = Orientation.Vertical };

            for (int i = 0; i < this._puzzle.Rank; i++)
            {
                StackPanel rowStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };

                for (int j = 0; j < this._puzzle.Rank; j++)
                {
                    SudokuZone zone = new SudokuZone();
                    this._zones[i, j] = zone;
                    rowStackPanel.Children.Add(zone);
                }

                gridStackPanel.Children.Add(rowStackPanel);
            }

            this.SudokuZoneContainer.Child = gridStackPanel;
        }
コード例 #2
0
ファイル: SudokuCell.xaml.cs プロジェクト: delner/sudoku
        public SudokuCell(SudokuZone zone, int zoneRow, int zoneCol)
        {
            InitializeComponent();

            this._zone = zone;

            this._zoneRow = zoneRow;
            this._zoneCol = zoneCol;
            this._value = null;
            this._cellState = SudokuCell.CellState.Editable;
            this._textChangedHandler = new TextChangedEventHandler(CellTextBox_TextChanged);
            this.DataContext = this;

            this.CellTextBox.MaxLength = (zone.Grid.Puzzle.Rank * zone.Grid.Puzzle.Rank).ToString().Length;

            this.BindTextBoxHandler();
        }
コード例 #3
0
ファイル: SudokuCell.xaml.cs プロジェクト: delner/sudoku
        public SudokuCell()
        {
            InitializeComponent();

            this._zone = null;

            this._zoneRow = 0;
            this._zoneCol = 0;
            this._value = null;
            this._cellState = SudokuCell.CellState.Editable;
            this._textChangedHandler = new TextChangedEventHandler(CellTextBox_TextChanged);
            this.DataContext = this;

            this.CellTextBox.MaxLength = (3 * 3).ToString().Length;

            this.BindTextBoxHandler();
        }
コード例 #4
0
ファイル: SudokuGrid.xaml.cs プロジェクト: delner/sudoku
        public SudokuGrid(SudokuPuzzle puzzle, SudokuPuzzleLoadOptions loadOptions)
        {
            InitializeComponent();

            this._puzzle = puzzle;
            this._zones = new SudokuZone[puzzle.Rank, puzzle.Rank];

            // Load the UI
            StackPanel gridStackPanel = new StackPanel() { Orientation = Orientation.Vertical };

            for (int i = 0; i < puzzle.Rank; i++)
            {
                StackPanel rowStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };

                for (int j = 0; j < puzzle.Rank; j++)
                {
                    SudokuZone zone = new SudokuZone(this, i, j);
                    this._zones[i, j] = zone;
                    rowStackPanel.Children.Add(zone);
                }

                gridStackPanel.Children.Add(rowStackPanel);
            }

            this.SudokuZoneContainer.Child = gridStackPanel;

            // Load the puzzle into the UI
            switch (loadOptions)
            {
                case SudokuPuzzleLoadOptions.StartNew:
                    for (int i = 0; i < (this._puzzle.Rank * this._puzzle.Rank); i++)
                    {
                        for (int j = 0; j < (this._puzzle.Rank * this._puzzle.Rank); j++)
                        {
                            int value = int.Parse(this._puzzle.Format[i].Split(new char[] { ',' })[j].ToString());

                            SudokuCell cell = this.GetCell(i, j);
                            if (value != 0)
                            {
                                cell.Value = value;
                                cell.State = SudokuCell.CellState.Locked;
                            }
                        }
                    }
                    break;

                case SudokuPuzzleLoadOptions.LoadSavedGame:
                    for (int i = 0; i < (this._puzzle.Rank * this._puzzle.Rank); i++)
                    {
                        for (int j = 0; j < (this._puzzle.Rank * this._puzzle.Rank); j++)
                        {
                            int value = int.Parse(this._puzzle.SaveState[i].Split(new char[] { ',' })[j].ToString());
                            int formatValue = int.Parse(this._puzzle.Format[i].Split(new char[] { ',' })[j].ToString());

                            SudokuCell cell = this.GetCell(i, j);
                            if (value != 0)
                            {
                                if (value != formatValue)
                                {

                                        cell.Value = value;
                                        cell.State = SudokuCell.CellState.Editable;
                                }
                                else
                                {
                                        cell.Value = value;
                                        cell.State = SudokuCell.CellState.Locked;
                                }
                            }
                        }
                    }
                    break;

                case SudokuPuzzleLoadOptions.LoadSolution:
                    for (int i = 0; i < (this._puzzle.Rank * this._puzzle.Rank); i++)
                    {
                        for (int j = 0; j < (this._puzzle.Rank * this._puzzle.Rank); j++)
                        {
                            int value = int.Parse(this._puzzle.Solution[i].Split(new char[] { ',' })[j].ToString());
                            int formatValue = int.Parse(this._puzzle.Format[i].Split(new char[] { ',' })[j].ToString());

                            SudokuCell cell = this.GetCell(i, j);
                            if (value != 0)
                            {
                                if (value != formatValue)
                                {
                                    cell.Value = value;
                                    cell.State = SudokuCell.CellState.Editable;
                                }
                                else
                                {
                                    cell.Value = value;
                                    cell.State = SudokuCell.CellState.Locked;
                                }
                            }
                        }
                    }
                    break;

                case SudokuPuzzleLoadOptions.EditMode:
                    for (int i = 0; i < (this._puzzle.Rank * this._puzzle.Rank); i++)
                    {
                        for (int j = 0; j < (this._puzzle.Rank * this._puzzle.Rank); j++)
                        {
                            int value = int.Parse(this._puzzle.Format[i].Split(new char[] { ',' })[j].ToString());

                            SudokuCell cell = this.GetCell(i, j);
                            if (value != 0)
                            {
                                cell.Value = value;
                            }
                        }
                    }
                    break;

                default:
                    // Do not load anything
                    break;
            }
        }