예제 #1
0
 //------------------------------------------------------
 //	Clear table
 //------------------------------------------------------
 public void ClearTable()
 {
     for (int ii = 0; ii < cellList.Count; ii++)
     {
         GameCell cell = cellList[ii];
         cell.orig   = 0;
         cell.cannum = 0;
         cell.imposs = 0;
         //cell.selected=0;
         cell.fixNum = 0;
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 //------------------------------------------------------
 //	Count forbidden values for a cell
 //------------------------------------------------------
 public CellResult CountCellFlag(GameCell cell)
 {
     return(CountCellFlag(cell.cellX, cell.cellY, cell.fixbitnum));
 }
예제 #4
0
파일: NumPad.cs 프로젝트: mnandi/SuDokuGit
        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);
        }
예제 #5
0
        private void pictureTable_MouseClick(object sender, MouseEventArgs e)
        {
            if (gameState < 0)                  //	0=not playing / 1=playing / -1-play stopped
            {
                return;
            }
            GameCell item = null;
            int      xx   = gameTable.tabSize;

            while (SetLeft(xx, cellSize) > e.X)
            {
                xx--;
            }
            if ((xx < 0) || (xx >= gameTable.tabSize))
            {
                return;
            }
            int yy = gameTable.tabSize;

            while (SetTop(yy, cellSize) > e.Y)
            {
                yy--;
            }
            if ((yy < 0) || (yy >= gameTable.tabSize))
            {
                return;
            }
            gameTable.SetSelectedCell(xx, yy);
            item = gameTable.cell(xx, yy);
            int   x      = SetLeft(xx, cellSize) + cellSize * 7 / 10;
            int   y      = SetTop(yy, cellSize) + cellSize * 7 / 10;
            Point ptCell = ((Control)sender).PointToScreen(new Point(x, y));
            int   num;

            if ((e.Button == MouseButtons.Left) && (gameState > 0))
            {
                //	left buttom & playing
                num = ShowNumpad(ptCell, item, true);
                pictureTable.Focus();
            }
            else
            {
                //	right button | not plying
                num = ShowNumpad(ptCell, item, false);
                pictureTable.Focus();
            }
            if (num >= 0)
            {
                int nerr = 0;
                if (gameState == 0)                             //	0=not playing / 1=playing / -1-play stopped
                //	here not playing
                {
                    item.orig   = 1;
                    item.fixNum = num;
                }
                else
                {
                    //	here playing
                    item.orig = 0;
                    buttonList.Add(new int[] { xx, yy, item.fixNum });
                    item.fixNum = num;
                }
                gameTable.ClearTableErrors();
                nerr = gameTable.CheckTable(item.orig == 1);
                pictureTable_Resize(null, null);
                using (Graphics g = Graphics.FromImage(pictureTable.Image)) {
                    DrawCell(g, br, cellSize, gameTable.cell(xx, yy));
                }
                pictureTable.Refresh();
                if ((gameState == 1) && (gameTable.EndTest() < 0))
                {
                    string msgid;
                    string msgtype;
                    if (nerr > 0)
                    {
                        msgid   = chlang.GetLocalizedString("MB_msg_ERRresult");
                        msgtype = chlang.GetLocalizedString("MB_caption_err");
                        MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        msgid   = chlang.GetLocalizedString("MB_msg_OKresult");
                        msgtype = chlang.GetLocalizedString("MB_caption_result");
                        MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }