public SudokuPuzzleView() { int size = 9; InitializeComponent(); var puzzle = new PuzzleGenerator((int)Math.Sqrt(size)); board = puzzle.MakePartialSolution(Difficulty.Hard); boardAs2DArray = puzzle.PartialSolutionAs2DArray; CreateRowAndColumnDefinitions(size); for (var row = 0; row < size; row++) { for (var column = 0; column < size; column++) { var panel = new SudokuPanel(row, column, boardAs2DArray[column, row], squareSize, squareSize); panel.MouseDown += PanelClick; panel.PutBackGroundOnPanel(); this.SudokuGrid.Children.Add(panel); Grid.SetRow(panel, row); Grid.SetColumn(panel, column); } } presenter = new SudokuGridPresenter { SudokuGrid = boardAs2DArray, SudokuGridSquares = board, View = this }; }
public void UpdateGrid(SudokuPanel panel) { SudokuGrid[panel.Column, panel.Row] = panel.Number; SudokuGridSquares.First(s => s.XCoordinate == panel.Column + 1 && s.YCoordinate == panel.Row + 1).Number = panel.Number; if (CheckForWinCondition()) { this.View.WinLabel.Visibility = Visibility.Visible; } }
private void Form1_Load(object sender, EventArgs e) { Cell[,] cells = new Cell[9, 9]; _cells = new Dictionary <Cell, SudokuPanel>(); int dx = 0; for (int i = 0; i < 9; i++) { int dy = 0; if (i > 0 && i % 3 == 0) { dx += 2; } for (int j = 0; j < 9; j++) { if (j > 0 && j % 3 == 0) { dy += 2; } var p = new SudokuPanel(new Cell()); p.BorderStyle = BorderStyle.FixedSingle; p.BackColor = Color.White; p.Size = new Size(80, 80); p.Location = new Point(dx + i * 80, dy + j * 80); p.Font = new Font(FontFamily.GenericSansSerif, 40); p.Changed += PanelChanged; panelBoard.Controls.Add(p); cells[i, j] = p.Cell; _cells.Add(p.Cell, p); } } _board = new Board(cells); }
public SudokuPopup(SudokuPanel popupParent = null) { this.PopupParent = popupParent; }