Пример #1
0
        void Calculate_MouseClick(object sender, MouseEventArgs e)
        {
            int startTime = System.Environment.TickCount;

            if (SUDOKU.RemoveRowColumn() == 0 || SUDOKU.XRemoveGrid() == 0 || SUDOKU.YRemoveGrid() == 0 || SUDOKU.FiveNumble1() == 0 || SUDOKU.FiveNumble2() == 0 || SUDOKU.FiveNumble3() == 0 || SUDOKU.FiveNumble4() == 0 || SUDOKU.FiveNumble5() == 0 || SUDOKU.FiveNumble6() == 0 || SUDOKU.FiveNumble7() == 0 || SUDOKU.FiveNumble8() == 0 || SUDOKU.FiveNumble9() == 0 || SUDOKU.FiveNumble10() == 0 || SUDOKU.FiveNumble11() == 0 || SUDOKU.FiveNumble12() == 0 || SUDOKU.XNineGrid() == 0 || SUDOKU.YNineGrid() == 0 || SUDOKU.RoundRemove() == 0)
            {
                Warning warning = new Warning();
                if (warning.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    for (int m = 0; m < 9; m++)
                    {
                        for (int n = 0; n < 9; n++)
                        {
                            SUDOKU.receive[m, n] = 0;
                            var tempLable = this.Controls.Find(m.ToString() + n.ToString(), false).First();
                            tempLable.Text      = null;
                            tempLable.ForeColor = Color.Black;
                        }
                    }
                    timeBox.Text = null;
                    SUDOKU.ArrayClear();
                    SUDOKU.countTimes = 2;
                }
            }
            else if (SUDOKU.LongTime() == 1 && SUDOKU.countTimes == 1)
            {
                for (int k = 0; k < 9; k++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        var tempLable = this.Controls.Find(k.ToString() + j.ToString(), false).First();
                        tempLable.Text = string.Format("{0}", SUDOKU.receive[k, j]);
                        tempLable.Font = new Font("", 20, FontStyle.Bold);
                    }
                }
            }
            else
            {
                SUDOKU.GetResult(0);
                for (int k = 0; k < 9; k++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        var tempLable = this.Controls.Find(k.ToString() + j.ToString(), false).First();
                        tempLable.Text = string.Format("{0}", SUDOKU.Rereceive[k, j]);
                        tempLable.Font = new Font("", 20, FontStyle.Bold);
                    }
                }
            }
            int endTime = System.Environment.TickCount;
            int runTime = endTime - startTime;

            if (SUDOKU.countTimes == 1)
            {
                timeBox.Text = string.Format("{0}ms", runTime);
            }
            SUDOKU.countTimes = 0;
            times             = 0;
        }
Пример #2
0
        static void Input()
        {
            int    r = 0;
            string lineRead;
            Sudoku SUDOKU     = null;
            bool   processing = false;

            while ((lineRead = Console.ReadLine()).Trim() != null && lineRead != "0")
            {
                if (Regex.IsMatch(lineRead.Trim(), @"^[0-9]+ [0-9]+$"))
                {
                    if (processing)
                    {
                        r          = 0;
                        processing = false;
                        SUDOKU.SolvePuzzle();
                    }
                    processing = true;
                    string[] firstLine = lineRead.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    if (firstLine[0] == "9")
                    {
                        Console.Write("");
                    }
                    SUDOKU = new Sudoku(int.Parse(firstLine[0]), int.Parse(firstLine[1]));
                }
                else
                {
                    string[] content = lineRead.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < content.Length; c++)
                    {
                        SUDOKU[r, c] = content[c];
                    }
                    r++;
                }
            }
            if (SUDOKU._boardWidth == 12)
            {
                Console.Write("");
            }
            SUDOKU.SolvePuzzle();

            if (Console.ReadLine() != null)
            {
                Input();
            }
            else
            {
                Environment.Exit(1);
            }
        }
Пример #3
0
 void buttonRestart_MouseClick(object sender, MouseEventArgs e)
 {
     for (int m = 0; m < 9; m++)
     {
         for (int n = 0; n < 9; n++)
         {
             SUDOKU.receive[m, n] = 0;
             var tempLable = this.Controls.Find(m.ToString() + n.ToString(), false).First();
             tempLable.Text      = null;
             tempLable.ForeColor = Color.Black;
         }
     }
     timeBox.Text = null;
     SUDOKU.ArrayClear();
 }
Пример #4
0
        private void gridMainform_MouseClick(object sender, MouseEventArgs e)
        {
            Choose winChoose    = new Choose();
            Label  gridMainform = (Label)sender;

            if (e.Button == MouseButtons.Left)
            {
                x = (gridMainform.Top) / 51;
                y = (gridMainform.Left) / 51;
                winChoose.StartPosition = System.Windows.Forms.FormStartPosition.Manual;//手动写位置
                winChoose.Location      = new Point(Control.MousePosition.X - 45, Control.MousePosition.Y - 45);
                if (gridMainform.Text == "")
                {
                    var testTemp = System.Windows.Forms.DialogResult.OK;
                    if (winChoose.ShowDialog() == testTemp)
                    {
                        SUDOKU.receive[x, y] = winChoose.valueTemp;
                        SUDOKU.LabelFalse(x, y);

                        gridMainform.Text      = Convert.ToString(winChoose.valueTemp);
                        gridMainform.ForeColor = Color.Red;
                        gridMainform.Font      = new Font("", 20, FontStyle.Bold);
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                x = (gridMainform.Top) / 51;
                y = (gridMainform.Left) / 51;
                if (SUDOKU.receive[x, y] != 0)
                {
                    SUDOKU.LabelCancel(x, y);
                    SUDOKU.receive[x, y]   = 0;
                    gridMainform.Text      = null;
                    gridMainform.ForeColor = Color.Black;
                }
            }
        }