public void GenerateGrid(int[] originalNumbersArray, int[] currentSaveArray) { for (var i = 0; i < originalNumbersArray.Length; i++) { if (originalNumbersArray[i] == 0) { if (currentSaveArray[i] != 0) { sudokuPanel.Controls.Add(controller.MakeSudokuButton("sudoku_", currentSaveArray[i].ToString(), game.GetRowByIndex(i), game.GetColumnByIndex(i), false)); } else { sudokuPanel.Controls.Add(controller.MakeSudokuButton("sudoku_", "", game.GetRowByIndex(i), game.GetColumnByIndex(i), false)); } } else { sudokuPanel.Controls.Add(controller.MakeSudokuButton("sudoku_", originalNumbersArray[i].ToString(), game.GetRowByIndex(i), game.GetColumnByIndex(i), true)); } } // Giving all of the textboxes the commmon event + add the borders foreach (Control ctrl in sudokuPanel.Controls) { if ((ctrl as TextBox) != null) { (ctrl as TextBox).TextChanged += CommonHandler_TextChanged; } string[] splitArray = (ctrl as TextBox).Name.Split('_'); int currentIndex = game.GetByColumn(int.Parse(splitArray[1]), int.Parse(splitArray[2])); if ((game.GetRowByIndex(currentIndex) + 1) % (game.gridHeight / game.squareHeight) == 0) // it is on a row with a horizonal line, bottom { (ctrl as TextBox).Controls.Add(new Label() { Height = 3, Dock = DockStyle.Bottom, BackColor = Color.Black }); } if ((game.GetColumnByIndex(currentIndex) + 1) % (game.gridWidth / game.squareWidth) - 1 == 0 && game.GetColumnByIndex(currentIndex) != 0) { (ctrl as TextBox).Controls.Add(new Label() { Width = 3, Dock = DockStyle.Left, BackColor = Color.Black }); } } }
private Button GetCellButton(Game game, int c, int s) { int[] numbersArray = game.ToArray(); int posIndex = game.GetBySquare(0, c); int cellIndex = game.GetBySquare(s, c); int row = game.GetRowByIndex(posIndex); int col = game.GetColumnByIndex(posIndex); Button btn = MakeButton( game.GetRowByIndex(cellIndex) + "_" + game.GetColumnByIndex(cellIndex), numbersArray[cellIndex].ToString(), row, col, game.numbersArray[cellIndex] == game.originalNumbersArray[cellIndex] && game.numbersArray[cellIndex] != 0 ); btn.Click += GridButton_clicked; btn.BackColor = Color.White; return(btn); }
private Panel MakeSquare(int s) { int cellIndex = game.GetBySquare(s, 0); int row = game.GetRowByIndex(cellIndex); int col = game.GetColumnByIndex(cellIndex); Panel squarePanel = new Panel { Name = s.ToString(), AutoSize = true, Size = new Size(BoxWidth * game.squareWidth, BoxWidth * game.squareHeight), BorderStyle = BorderStyle.FixedSingle, BackColor = Color.Black }; squarePanel.Location = new Point(col * BoxWidth, row * BoxWidth); for (int c = 0; c < game.numberOfSquares; c++) { squarePanel.Controls.Add(GetCellButton(game, c, s)); } return(squarePanel); }
private void DrawGames(SudokuGameForm SForm, Game g) { Font LabelFont = new Font("Segoe UI Symbol", 12); Size s = new Size(g.gridWidth * boxWidth, g.gridWidth * boxWidth + boxWidth); Panel Original = MakePanel(10, 10, s, "Original", "Original"); Panel GameSave = MakePanel((Original.Width) + boxWidth, 10, s, "Game Save", "GameSave"); int col, row; Label OG, GS; for (int c = 0; c < g.originalNumbersArray.Length; c++) { col = g.GetColumnByIndex(c); row = g.GetRowByIndex(c); OG = SForm.AddLabel( "Original" + c, g.originalNumbersArray[c] == 0 ? "" : g.originalNumbersArray[c].ToString(), row, col ); GS = SForm.AddLabel( "GameSave" + c, g.numbersArray[c] == 0 ? "" : g.numbersArray[c].ToString(), row, col ); OG.Click += SudokuCellLabel_Clicked; GS.Click += SudokuCellLabel_Clicked; OG.MouseEnter += SudokuCellLabel_Hover; GS.MouseEnter += SudokuCellLabel_Hover; GameSave.Controls.Add(GS); Original.Controls.Add(OG); } Controls.Add(Original); Controls.Add(GameSave); SetFormSize(20 + Original.Width + GameSave.Width + boxWidth, (g.gridWidth + 2) * boxWidth + CancelBtn.Height + 10); }