Exemplo n.º 1
0
 private void BgwSolver_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (solved == false)
     {
         if (Application.OpenForms.OfType <frmOptions>().Count() <= 0)
         {
             optionsForm = new frmOptions();
         }
     }
     optionsForm.Show();
 }
Exemplo n.º 2
0
 //Fonction qui initialise le tableau
 private void frmMain_Load(object sender, EventArgs e)
 {
     //Initialise chaque case avec une valeur de 0
     for (int i = 0; i < 9; i++)
     {
         for (int k = 0; k < 9; k++)
         {
             candidates[new Point(i, k)] = new List <int>();
             superCandidates[i, k]       = 0;
             board[i, k] = 0;
         }
     }
     optionsForm           = new frmOptions();
     optionsForm.validated = true;
     optionsForm.Show();
     optionsForm.Activate();
 }
Exemplo n.º 3
0
        //Fonction qui traite les appuis de clé
        private void frmMain_KeyUp(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            if (bgwSolver.IsBusy == false || testing == true)
            {
                if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Escape)
                {
                    if (Application.OpenForms.OfType <frmOptions>().Count() <= 0)
                    {
                        optionsForm = new frmOptions();
                    }
                    optionsForm.Show();
                    //Si c'est la clé d'espace et le tableau est légale, résoudre le tableau
                }
                else if (e.KeyCode == Keys.Back)
                {
                    if (playerInput == false)
                    {
                        startingBoard[selectedIndex.X, selectedIndex.Y] = 0;
                    }
                    board[selectedIndex.X, selectedIndex.Y] = 0;
                    selectedIndex.X--;
                    if (selectedIndex.X < 0)
                    {
                        selectedIndex.Y--;
                        selectedIndex.X = 8;
                        if (selectedIndex.Y < 0)
                        {
                            selectedIndex.Y = 8;
                        }
                    }
                    isLegal(board);
                }
                else
                {
                    switch (e.KeyCode)
                    {
                    case Keys.Left:
                        selectedIndex.X--;
                        break;

                    case Keys.Right:
                        selectedIndex.X++;
                        break;

                    case Keys.Up:
                        selectedIndex.Y--;
                        break;

                    case Keys.Down:
                        selectedIndex.Y++;
                        break;
                    }
                    if (selectedIndex.X < 0)
                    {
                        selectedIndex.X = 8;
                        selectedIndex.Y--;
                    }
                    else if (selectedIndex.X > 8)
                    {
                        selectedIndex.X = 0;
                        selectedIndex.Y++;
                    }
                    if (selectedIndex.Y < 0)
                    {
                        selectedIndex.Y = 8;
                    }
                    else if (selectedIndex.Y > 8)
                    {
                        selectedIndex.Y = 0;
                    }
                    KeysConverter kc    = new KeysConverter();
                    string        s     = kc.ConvertToString(e.KeyCode);
                    char          c     = s.Substring(s.Length - 1).ToCharArray()[0];
                    int           ascii = (int)c;
                    try
                    {
                        if (ascii > 47 && ascii < 58)
                        {
                            if (playerInput == false)
                            {
                                startingBoard[selectedIndex.X, selectedIndex.Y] = Convert.ToInt32(c.ToString());
                                selectedIndex.X++;
                                if (selectedIndex.X > 8)
                                {
                                    selectedIndex.X = 0;
                                    selectedIndex.Y++;
                                    if (selectedIndex.Y > 8)
                                    {
                                        selectedIndex.Y = 0;
                                    }
                                }
                            }
                            else if (startingBoard[selectedIndex.X, selectedIndex.Y] == 0)
                            {
                                board[selectedIndex.X, selectedIndex.Y] = Convert.ToInt32(c.ToString());
                                if (isLegal(board) == true && board.Cast <int>().Contains <int>(0) == false)
                                {
                                    picMain.Refresh();
                                    MessageBox.Show("Complété!");
                                    if (Application.OpenForms.OfType <frmOptions>().Count() <= 0)
                                    {
                                        optionsForm = new frmOptions();
                                    }
                                    optionsForm.Show();
                                }
                                selectedIndex.X++;
                                if (selectedIndex.X > 8)
                                {
                                    selectedIndex.X = 0;
                                    selectedIndex.Y++;
                                    if (selectedIndex.Y > 8)
                                    {
                                        selectedIndex.Y = 0;
                                    }
                                }
                            }
                            isLegal(board);
                        }
                    }
                    catch (Exception ex) { }
                }
                picMain.Refresh();
                if (playerInput == true)
                {
                    resetBoard();
                }
            }
        }