Esempio n. 1
0
        private void Buttons_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            string[] indexes = btn.Tag.ToString().Split(',');
            int      row     = Convert.ToInt32(btn.Tag.ToString().Substring(0, 1));
            int      column  = Convert.ToInt32(btn.Tag.ToString().Substring(2, 1));

            //in indexes[0] you've got the i index and in indexes[1] the j index
            Console.WriteLine(indexes[0] + "," + indexes[1]);
            List <int> lstPossibleNums = new List <int>();

            lstPossibleNums = mySudoku.GetPossibleNums(row, column);
            frmNumbers frmNumber = new frmNumbers(lstPossibleNums);

            frmNumber.StartPosition = FormStartPosition.Manual;
            frmNumber.Location      = new Point(this.Location.X + buttonArray[row, column].Location.X, this.Location.Y + buttonArray[row, column].Location.Y);

            var result = frmNumber.ShowDialog();

            if (result == DialogResult.OK)
            {
                string val = frmNumber.ReturnValue;            //values preserved after close

                if (val == "X")
                {
                    buttonArray[row, column].Text = "";
                    mySudoku.EnterValue(0, row, column);
                }
                else
                {
                    buttonArray[row, column].Text = val;
                    mySudoku.EnterValue(Convert.ToInt32(val), row, column);
                    if (mySudoku.IsGameFinished() == true)
                    {
                        MessageBox.Show("You did it! \n You beat Sudoku", "Congrats!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        PrepareNewGame();
                    }
                }
            }
            frmNumber.Dispose();
        }