private void comboGameName_SelectedIndexChanged(object sender, EventArgs e) { if (comboGameName.SelectedIndex < 0) { return; } int gameIndex = GameFile.GetGameIndexFull((string)comboGameName.Items[comboGameName.SelectedIndex]); if (gameIndex < 0) { return; } GameParams pars = GameFile.GetGameParameters(gameIndex); if (pars == null) { return; } textGameName.Text = pars.pName; comboGameType.Text = string.Format("={0}{1}*{2}\t({3}*{3})", (pars.pDiag != 0)?"X":"", pars.pX, pars.pY, pars.pSize); numericLevel.Value = pars.pLevel; textGameComment.Text = pars.pComment; if ((actGameDef.gxCells != pars.pX) || (actGameDef.gyCells != pars.pY) || (actGameDef.gxCross != pars.pDiag)) { actGameDef = new GameDef(pars.pX, pars.pY, pars.pDiag, comboGameType.Text); gameTable.InitTable(pars.pX, pars.pY, pars.pDiag); } for (int yy = 0; yy < pars.pSize; yy++) { string rowLine = GameFile.GetGameRow(gameIndex, yy); gameTable.FillTableRow(yy, ((rowLine.Length > 0) && (rowLine[0] != '*'))?rowLine:""); } int nErr = gameTable.CheckTable(true); pictureTable_Resize(null, null); //int errnum=gameTable.CheckTable(true); }
static public List <int[]> CheckValues(GameCell cell) { GameDef def = SuDokuForm.actGameDef; int flag = 0; int num; List <int[]> doubles = new List <int[]>(); // Own cell num = cell.fixNum; if (num > 0) { int bits = (1 << num); flag |= bits; } #region Check rows & columns // Test row for (int xx = 0; xx < SuDokuForm.gameTable.tabSize; xx++) { if (cell.cellX == xx) { continue; // exclude own cell } SetFlag(ref flag, xx, cell.cellY, doubles); } // Test column for (int yy = 0; yy < SuDokuForm.gameTable.tabSize; yy++) { if (cell.cellY == yy) { continue; // exclude own cell } SetFlag(ref flag, cell.cellX, yy, doubles); } #endregion #region Check diagonals // Test diagonals if (def.xCross == (int)GameType.DIAGGAME) { if (cell.cellX == cell.cellY) { // if cell in top-left - bottom-right diagonal for (int ii = 0; ii < SuDokuForm.gameTable.tabSize; ii++) { if (cell.cellX == ii) { continue; // exclude own cell } SetFlag(ref flag, ii, ii, doubles); } } if (cell.cellX == (SuDokuForm.gameTable.tabSize - 1 - cell.cellY)) { // if cell in bottom-left - top-right diagonal for (int ii = 0; ii < SuDokuForm.gameTable.tabSize; ii++) { if (cell.cellX == ii) { continue; // exclude own cell } SetFlag(ref flag, ii, SuDokuForm.gameTable.tabSize - 1 - ii, doubles); } } } #endregion #region Test cell group // Test group for (int yy = 0; yy < def.yCells; yy++) { int y = (cell.cellY / def.yCells * def.yCells) + yy; for (int xx = 0; xx < def.xCells; xx++) { int x = (cell.cellX / def.xCells * def.xCells) + xx; if ((cell.cellX == x) && (cell.cellY == y)) { continue; // exclude own cell } SetFlag(ref flag, x, y, doubles); } #endregion } cell.vFlag = flag; return(doubles); }
static public List <int[]> StepValue(GameItem item) { GameDef def = SuDokuForm.actGameDef; List <int[]> doubles = new List <int[]>(); // Own item int num = item.actNum; // Num must greather than 0 int flag = item.actFlag; #region Check rows & columns // Test row for (int xx = 0; xx < SuDokuForm.gameTable.tabSize; xx++) { if (item.cellX == xx) { continue; // exclude own cell } bool retOK = SetValue(flag, xx, item.cellY); } // Test column for (int yy = 0; yy < SuDokuForm.gameTable.tabSize; yy++) { if (item.cellY == yy) { continue; // exclude own cell } bool retOK = SetValue(flag, item.cellX, yy); } #endregion #region Check diagonals // Test diagonals if (def.xCross == (int)GameType.DIAGGAME) { if (item.cellX == item.cellY) { // if item in top-left - bottom-right diagonal for (int ii = 0; ii < SuDokuForm.gameTable.tabSize; ii++) { if (item.cellX == ii) { continue; // exclude own cell } bool retOK = SetValue(flag, ii, ii); } } if (item.cellX == (SuDokuForm.gameTable.tabSize - 1 - item.cellY)) { // if item in bottom-left - top-right diagonal for (int ii = 0; ii < SuDokuForm.gameTable.tabSize; ii++) { if (item.cellX == ii) { continue; // exclude own cell } bool retOK = SetValue(flag, ii, SuDokuForm.gameTable.tabSize - 1 - ii); } } } #endregion #region Test cell group // Test group for (int yy = 0; yy < def.yCells; yy++) { int y = (item.cellY / def.yCells * def.yCells) + yy; for (int xx = 0; xx < def.xCells; xx++) { int x = (item.cellX / def.xCells * def.xCells) + xx; if ((item.cellX == x) && (item.cellY == y)) { continue; // exclude own cell } bool retOK = SetValue(flag, x, y); } #endregion } item.vFlag = flag; return(doubles); }
public NumPad(GameCell cll, GameDef def, int state, bool mode) { // mode: // all =true - left button - view all num // =false - right button - view available nums InitializeComponent(); cell = cll; siz = def.gtabSize; bas = (siz > 9)?Constants.chrBase:Constants.numBase; // show '1' if table <= 3x3 else 'A' CellResult rerr = SuDokuForm.gameTable.CountCellFlag(cell); int nC = Math.Max(def.gxCells, def.gyCells); int nR = Math.Min(def.gxCells, def.gyCells); const int offs = 2; int buttSiz = 30; this.Size = new Size(buttSiz * nC + offs, buttSiz * (nR + 1) + offs); Button[,] butts = new Button[nC, nR]; Button butt; int mask = rerr.cellnums; if (state == 1) { if (cell.canresmask != 0) { mask &= ~cell.canresmask; } } for (int yy = 0; yy < nR; yy++) { for (int xx = 0; xx < nC; xx++) { butt = new Button(); butt.Size = new Size(buttSiz - offs, buttSiz - offs); butt.Location = new Point(xx * buttSiz + offs, yy * buttSiz + offs); int num = yy * nC + xx; butt.Text = ((char)(num + ((SuDokuForm.gameTable.tabSize >= 10)?0x41:0x31))).ToString(); butt.Tag = num + 1; if ((!mode) || (state == 1)) { //if((rerr.cellnums&(1<<(num)))!=0) if ((mask & (1 << (num))) != 0) { butt.Enabled = false; } } butt.Click += new System.EventHandler(this.button_Click); butt.KeyPress += new KeyPressEventHandler(this.NumPad_KeyPress); butt.DialogResult = DialogResult.OK; this.Controls.Add(butt); } } // Cancel butt = new Button(); butt.Size = new Size(buttSiz * (nC - 1) - offs, buttSiz - offs); butt.Location = new Point(offs, nR * buttSiz + offs); butt.Text = "- -"; butt.Click += new System.EventHandler(this.button_Click); butt.DialogResult = DialogResult.Cancel; butt.Tag = (int)0; this.Controls.Add(butt); // Abort butt = new Button(); butt.Size = new Size(buttSiz - offs, buttSiz - offs); butt.Location = new Point((nC - 1) * buttSiz + offs, nR * buttSiz + offs); butt.Text = "x"; butt.DialogResult = DialogResult.Abort; butt.Click += new System.EventHandler(this.button_Click); butt.Tag = (int)(-1); this.Controls.Add(butt); }
void InitSuDokuTable(GameDef game) { gameTable = new GameTable(game.gxCells, game.gyCells); pictureTable_Resize(null, null); }
private void comboGameType_SelectedIndexChanged(object sender, EventArgs e) { actGameDef = Constants.gameDefTb[comboGameType.SelectedIndex]; InitSuDokuTable(actGameDef); }