public SudokuGrid(SudokuPuzzle puzzle, SudokuPuzzleLoadOptions loadOptions, TextBlock availableValuesTextBlock, TextBlock possibleValuesTextBlock) : this(puzzle, loadOptions) { this._availableValuesTextBlock = availableValuesTextBlock; this._possibleValuesTextBlock = possibleValuesTextBlock; this.CheckAvailableValues(); }
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; } }
public void LoadPuzzle(SudokuPuzzle puzzle, SudokuPuzzleLoadOptions loadOptions) { Global.Game.Grid = new SudokuGrid(puzzle, loadOptions, this.RemainingNumbersTextBlock, this.PossibleValuesTextBlock) { HorizontalAlignment = System.Windows.HorizontalAlignment.Center }; this.SudokuGridContainer.Child = Global.Game.Grid; }