コード例 #1
0
ファイル: FJeu.cs プロジェクト: Elomidas/Sudoku
        //Permet de générer un nouveau jeu, en précisant la difficulté voulue
        private void GenererJeu(int difficulte)
        {
            bool choix = true;

            if (!m_fin)
            {
                try
                {
                    //On affiche un message demandant si le joueur veut abandonner la partie actuelle
                    DialogResult res = MessageBox.Show("La grille actuelle n'est pas terminée ! Voulez-vous vraiment l'abandonner et en commencer une nouvelle ?", "Abandon !", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    choix = res == System.Windows.Forms.DialogResult.Yes;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("\n" + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (choix)
            {
                jeu = Jeu.Generer(difficulte);
                for (int i = 0; i < 9; i++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        String s = this.GetJeu().ValeurString(i, j);
                        //On fait en sorte que la TextBox affiche la valeur en mémoire
                        ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).Text = s;
                        //Seule les cases à remplir par l'utilisateur sont modifiables
                        ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).ReadOnly = !GetJeu().Cache(i, j);
                        if (!GetJeu().Cache(i, j))
                        {//Chiffre visible, fixé
                            //On fixe la police en gras
                            ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                            //On change la couleur du chiffre
                            ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).ForeColor = m_cVisib;
                        }
                        else
                        {//Chiffre caché, à remplir par l'utilisateur
                            //On fixe la police à la normale
                            ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).Font = new System.Drawing.Font("Microsoft Sans Serif", 18F);
                            //On change la couleur du chiffre
                            ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).ForeColor = m_cCache;
                        }
                        ((TextBox)tableLayoutPanel1.GetControlFromPosition(j, i)).BackColor = Color.FromKnownColor(KnownColor.Window);
                    }
                }
                m_fin = false;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Elomidas/Sudoku
 public Form1()
 {
     InitializeComponent();
     m_jeu = new Jeu();
     Jeu res = Jeu.Generer();
 }