public Cell(int number, Cell block, Control playingArea, int value) : this(number, block, playingArea) { txt.ReadOnly = true; txt.SetValue(value); Highlight(true); }
public Cell(int number, Cell block, Control playingArea) : this(number) { txt = new TextBoxEx() { Left = block.X * (Sq * Grid + InterGap) + X * Grid, Top = block.Y * (Sq * Grid + InterGap) + Y * Grid }; txt.ValueChanged += new EventHandler(txt_ValueChanged); playingArea.Controls.Add(txt); }
private void InitSudoku() { panel1.Controls.Clear(); totals.Clear(); allCells.Clear(); cellsBySqr.Clear(); cellsByRow.Clear(); cellsByCol.Clear(); Dictionary<int, int> values = SudoGen.GetSudokuValues(); //GetSudokuValuesOld(); List<int> wanted = new List<int>(); for (int i = 0; i < 9; i++) { int count = 3 + new Random(DateTime.Now.Millisecond).Next(2); List<int> places = new List<int>(); for (int j = 0; j < count; j++) { int place = 0; Random r = new Random(DateTime.Now.Millisecond); do { place = r.Next(8); } while (places.Contains(place)); wanted.Add(i * 9 + place); places.Add(place); } } for (int i = 0; i < 9; i++) { cellsByRow.Add(new List<Cell>()); cellsByCol.Add(new List<Cell>()); cellsBySqr.Add(new List<Cell>()); } int index = 0; for (int i = 0; i < 9; i++) { Cell square = new Cell(i); for (int j = 0; j < 9; j++) { Cell c; //int value; if (wanted.Contains(index)) // values.TryGetValue(index, out value)) c = new Cell(j, square, panel1, values[index]); else c = new Cell(j, square, panel1); cellsByRow[square.Y * Cell.Sq + c.Y].Add(c); cellsByCol[square.X * Cell.Sq + c.X].Add(c); cellsBySqr[i].Add(c); allCells.Add(c); c.ValueChanged += new EventHandler(c_ValueChanged); index += 1; } } ShowTotals(); }