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 CheckHighlighting(int index) { if (game.RowValid(game.GetRowByIndex(index))) { for (var i = 0; i < game.gridWidth; i++) { Control current = sudokuPanel.Controls.Find("sudoku_" + i + "_" + game.GetRowByIndex(index), true)[0]; current.ForeColor = Color.Green; // Work in progress //current.Enabled = false; } hintOutput.Text = "row valid"; } if (game.ColumnValid(game.GetColumnByIndex(index))) { for (var i = 0; i < game.gridHeight; i++) { Control current = sudokuPanel.Controls.Find("sudoku_" + game.GetColumnByIndex(index) + "_" + i, true)[0]; current.ForeColor = Color.Green; //current.Enabled = false; } hintOutput.Text = "column valid"; } if (game.SquareValid(game.GetSquareFromIndex(index))) { int square = game.GetSquareFromIndex(index); for (var i = 0; i < game.numberOfSquares; i++) { Control current = sudokuPanel.Controls.Find("sudoku_" + game.GetColumnByIndex(game.GetBySquare(square, i)) + "_" + game.GetRowByIndex(game.GetBySquare(square, i)), true)[0]; current.ForeColor = Color.Green; //current.Enabled = false; } hintOutput.Text = "square valid"; } }