Exemplo n.º 1
0
        /// <summary>
        /// retourne vrai si la case est une case voisine.
        /// </summary>
        /// <returns> Vrai ou faux.</returns>
        private bool IsNeighbourrFromPrecedent()
        {
            int rx, ry;

            this.labNotification.Text = string.Empty;

            // pas la première case
            if (DonneesLettres.PrecedentSquare.X != -1)
            {
                // traitement
                rx = Math.Abs(DonneesLettres.ChoosenSquare.X - DonneesLettres.PrecedentSquare.X);
                ry = Math.Abs(DonneesLettres.ChoosenSquare.Y - DonneesLettres.PrecedentSquare.Y);
                if (rx >= -1 && rx <= 1 && ry >= -1 && ry <= 1)
                {
                    DonneesLettres.StoreUsingPlace();
                    this.labNotification.Text = " ";
                    return(true);
                }
                else
                {
                    this.labNotification.Text = "Choix innacceptable : pas voisine";
                    return(false);
                }
            }
            else
            {
                DonneesLettres.StoreUsingPlace();
                this.labNotification.Text = " ";
                return(true);
            }
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string t;
            int    cpt = 0;

            this.labEncouragement.Text  = string.Empty;
            this.labEncouragement2.Text = string.Empty;

            for (int j = 0; j < 4; j++)
            {
                // Création des LABEL  de la grille
                for (int i = 0; i < 4; i++)
                {
                    cpt++;
                    int     pas = 60;
                    LAbelXY l   = new LAbelXY();
                    {
                        l.Font   = new System.Drawing.Font("Microsoft Sans Serif", 14F, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
                        l.Parent = this;
                    }

                    l.Click    += new EventHandler(this.LetterIsChoosen);
                    t           = cpt.ToString();
                    l.Text      = t;
                    l.Name      = t;
                    l.Width     = pas - 20;
                    l.Height    = pas - 20;
                    l.Top       = 20 + (j * pas);
                    l.Left      = 20 + (i * pas);
                    l.ForeColor = this.defaultColor;
                    l.X         = i;
                    l.Y         = j;
                    l.Show();
                }
            }

            DataGame.ResetWordScore();
            DataGame.RazScoreTotal();

            // Pour la contruction d'un arbre des lettres à partir de la liste des mots français
            LoadWordsDictionnary.InitialiseEnvironnement();
            if (LoadWordsDictionnary.GetAuthorizationStatus())
            {
                DonneesLettres.MatrixIniialization();
                this.NewGame();
            }
            else
            {
                _ = MessageBox.Show(
                    "Erreur à l'ouverture du dictionnaire des mots Français\r\n" +
                    " Verifiez si le fichier MOTS TRADUITS.txt est présent sous le même répertoire que celui\r\n" +
                    " de l'application.", "Erreur fatale.", buttons: MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
            }

            this.PossibleWordsInTextbox2();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Exécute les choses à faire lors d'un clic sur une lettre de la matrice.
        /// </summary>
        /// <param name="labelName"> Lettre cliquée.</param>
        /// <param name="ligne"> coordonnée en X.</param>
        /// <param name="colonne"> Coordonnée en Y.</param>
        private void GereClicSurLettre(string labelName, int ligne, int colonne)
        {
            DonneesLettres.ChoosenSquare.X = colonne;
            DonneesLettres.ChoosenSquare.Y = ligne;

            if (this.IsNeighbourrFromPrecedent())
            {
                // pour tous les labels de la form
                foreach (Label letterLabel in this.Controls.OfType <Label>())
                {
                    // si le label est celui cliqué
                    if (letterLabel.Name == labelName)
                    {
                        this.textBox1.Text += letterLabel.Text;
                        this.UpdateWordScore(char.Parse(letterLabel.Text));
                        DonneesLettres.ArrayOfLetterUse[colonne, ligne] = true;
                    }

                    DonneesLettres.SetPlaceOfUsingLetter(ligne, colonne);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Dessine la matrice.
        /// </summary>
        private void DrawMatrix()
        {
            int compteur = 0;

            try
            {
                foreach (LAbelXY labelDeLettre in this.Controls.OfType <LAbelXY>())
                {
                    labelDeLettre.Text    = DonneesLettres.TableauDeLettres[labelDeLettre.Y, labelDeLettre.X].ToString();
                    labelDeLettre.Visible = true;
                    compteur++;
                }
            }
            catch
            {
                MessageBox.Show("Erreur dans la boucle foreach de dessinneMatrice");
            }

            DonneesLettres.PrecedentSquare.X = -1;

            // initialise case précédente
            DonneesLettres.PrecedentSquare.Y = -1;
            DonneesLettres.ResetLettersUtilisationArray();
        }
Exemplo n.º 5
0
 private void Bt_Rotation_Click(object sender, EventArgs e)
 {
     DonneesLettres.RotateMatrix();
     this.DrawMatrix();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Génère aléatoirement des lettres qui sont mises dans le tableau"matrice".
        /// </summary>
        private void CreateMatrix()
        {
            int  cptVoyelle      = 0;
            int  voyelleDeSuite  = 0;
            int  consonneDeSuite = 0;
            int  noteDeChiant    = 0;
            int  difficulteLettre;
            int  maxVoyelle = 6;
            bool estUneVoyelle;
            bool accord = true;
            char lettre;
            var  rand = new Random();

            // remplit un tableau [0..15] d'un caractère aléatoire
            int i = 0;

            // this.textBox2.Clear();
            while (i < 16)
            {
                int a = rand.Next(0, 25);
                lettre = DonneesLettres.Alphabet[a];
                if (i > 0)
                {
                    if (lettre != DonneesLettres.ArrayOfLetters[i - 1])
                    {
                        accord = true;
                    }
                    else
                    {
                        accord = false;
                    }
                }

                if (accord)
                {
                    // this.textBox2.Text = this.textBox2.Text + lettre.ToString() + " TIRE = " + nbDeLaLettre(lettre).ToString() + " fois \r\n";
                    difficulteLettre = DonneesLettres.TabloDifficulte[a];
                    if (DonneesLettres.TabloConsonneOuVoyelle[a] == 1)
                    {// détermine si le caractère est ou non une voyelle
                        estUneVoyelle = true;
                    }
                    else
                    {
                        estUneVoyelle = false;
                    }

                    if (estUneVoyelle && voyelleDeSuite < 3)
                    {     // Tirage d'une voyelle
                        if (cptVoyelle <= maxVoyelle)
                        { // nombre de voyelles tirées inférieur au maximaum autorisé
                          // cas autorisé
                            if (difficulteLettre > 0)
                            {// si tirage voyelle difficile
                                if (DonneesLettres.PlaceInMatrix(lettre) == -1 && noteDeChiant <= 4)
                                {
                                    // difficile pas en double
                                    DonneesLettres.ArrayOfLetters[i] = lettre;
                                    noteDeChiant += DonneesLettres.TabloDifficulte[i];
                                    cptVoyelle++;
                                    i++;
                                    voyelleDeSuite++;
                                    consonneDeSuite = 0;

                                    // this.textBox2.Text = this.textBox2.Text + "Voyelle difficile Ajoutée = " + lettre.ToString() + "\r\n";
                                }
                            }
                            else
                            {
                                // voyelle facile
                                DonneesLettres.ArrayOfLetters[i] = lettre;
                                voyelleDeSuite++;
                                consonneDeSuite = 0;

                                // this.textBox2.Text = this.textBox2.Text + "Voyelle facile Ajoutée = " + lettre.ToString() + "\r\n";
                            }
                        }
                    }
                    else
                    {             // tirage d'une consonne
                        if (consonneDeSuite <= 2)
                        {         // et pas trop de consonnnes d'affilé
                            if (difficulteLettre < 2)
                            {     // facile
                                if ((difficulteLettre == 2 && DonneesLettres.PlaceInMatrix(lettre) == -1) || (difficulteLettre <= 1 && (DonneesLettres.HowManyInMatrix(lettre) < 3)))
                                { // si la lettre de difficulté 2 n'est pas déjà tirée
                                    DonneesLettres.ArrayOfLetters[i] = lettre;
                                    consonneDeSuite++;
                                    voyelleDeSuite = 0;
                                    i++;

                                    // this.textBox2.Text =
                                    //  this.textBox2.Text = "  " + this.textBox2.Text + "consonne facile Ajoutée = " + lettre.ToString() + " exemplaire n° " + nbDeLaLettre(lettre).ToString() + "\r\n";
                                }
                                else
                                {
                                    // this.textBox2.Text =
                                    //  this.textBox2.Text = "  " + this.textBox2.Text + "consonne facile rejetée = " + lettre.ToString() + "\r\n";
                                }
                            }
                            else
                            {     // pas facile
                                if ((noteDeChiant < 3) && (DonneesLettres.HowManyInMatrix(lettre) < 2))
                                { // acceptable et pas doublé
                                    noteDeChiant += difficulteLettre;

                                    // augmentation de la note globale de chiant
                                    DonneesLettres.ArrayOfLetters[i] = lettre;
                                    consonneDeSuite++;
                                    voyelleDeSuite = 0;
                                    i++;

                                    // this.textBox2.Text = "  " + this.textBox2.Text + " consonne difficile Ajoutée = " + lettre.ToString() + "\r\n";
                                }
                                else
                                {
                                    // on ne fait rien car pas acceptable
                                    //  this.textBox2.Text =
                                    //  this.textBox2.Text = "  " + this.textBox2.Text + "      Consonne rejetée" + lettre.ToString() + "\r\n";
                                }
                            }
                        } // consoles d'affilé
                    }
                }         // fin du if = lettre precedente et conssonne et voyelles à suivre trop nombreuses
            }             // fin du while remmplissage matrice

            // modifications pour rendre plus jouable
            if (DonneesLettres.HowManyInMatrix('E') < 2)
            {// pas assez de E
                int difMax = 0;
                for (int j = 0; j < 16; j++)
                {// Repérage du plus haut diveau de difficulté présent
                    if (DonneesLettres.TabloDifficulte[j] > difMax)
                    {
                        difMax = DonneesLettres.TabloDifficulte[j];
                    }
                }

                for (int j = 0; j < 16; j++)
                {// la première lettre di niveau de difficulté Max est remplacée par E
                    if (DonneesLettres.TabloDifficulte[j] == difMax)
                    {
                        // this.textBox2.Text = this.textBox2.Text + matrice[j].ToString() + " remplacée par = E \r\n";
                        DonneesLettres.ArrayOfLetters[j] = 'E';
                        cptVoyelle++;
                        j = 16;
                    }
                }

                for (int k = 0; k < 16; k++)
                {
                    // this.textBox2.Text = "  " + this.textBox2.Text + k.ToString() + "  " + matrice[k].ToString() + "\r\n";
                }
            }

            if (cptVoyelle < 6)
            {
                // pas assez de voyelles
                int  aChanger = maxVoyelle - cptVoyelle - 1;
                int  tour     = 0;
                char car;
                while (tour < aChanger)
                { // substitution de consonnes par des voyelles
                    int b = rand.Next(0, 15);
                    car = DonneesLettres.ArrayOfLetters[b];
                    if (!DonneesLettres.EstVoyelle(car))
                    {
                        int c = rand.Next(0, 2);

                        // this.textBox2.Text = this.textBox2.Text + matrice[b].ToString() + " remplacée par = " + voyellesCourantes[c] + " \r\n";
                        DonneesLettres.ArrayOfLetters[b] = DonneesLettres.UsualVowels[c];
                        tour++;
                    }
                }

                // fin modifications pour rendre plus jouable
            }

            // transfert des lettres de Matrice vers tableaudelettres
            int ligne = 0, colonne = 0;

            for (int r = 0; r < 16; r++)
            {
                DonneesLettres.TableauDeLettres[ligne, colonne] = DonneesLettres.ArrayOfLetters[r];
                colonne++;
                if (colonne == 4)
                {
                    ligne++;
                    colonne = 0;
                }
            }

            // MessageBox.Show("nb voyelles =" + cptVoyelle);
        }