コード例 #1
0
        private void NewEx()
        {
            nextBtn.Hide();
            btnClicked = false;
            int a = tmpsCheckedListBox1.CheckedItems.Count;

            int[] tmps = new int[a]; int j = 0;
            foreach (int indexChecked in tmpsCheckedListBox1.CheckedIndices)
            {
                tmps[j] = indexChecked;
                j++;
            }
            Random r = new Random();
            int    i = r.Next(tmps.Length);

            string[] sujet   = { "Je", "Tu", "Il/Elle/On", "Nous", "Vous", "Ils/Elles,On" };
            string[] tmpsArr = { "Present", "Passé composé", "Futur", "Imparfait" };
            int      suj     = r.Next(sujet.Length);

            try
            { comp = false;
              string trueAns = SearchFrs.Conjugaison(nextBtn.Tag.ToString(), tmps[i], suj);
              string choices = SearchFrs.VerbsChoix(nextBtn.Tag.ToString());
              choices = choices.Remove(choices.IndexOf(trueAns) - 1, trueAns.Length + 1).Trim();
              //MessageBox.Show(choices);
              string[] choiceArr = choices.Split(',');
              Button[] btn       = { choice1Btn, choice2Btn, choice3Btn, choice4Btn };
              foreach (Button b in btn)
              {
                  b.Enabled   = true;
                  b.BackColor = Color.LightGray;
                  b.Click    -= b_click;
                  b.Click    -= wrong_click;
              }
              int x = r.Next(4);

              btn[x].Text = verbLabel.Text = trueAns.ToLower();
              if ((suj == 0) && ((trueAns[0] == 'é') || (trueAns[0] == 'a') || (trueAns[0] == 'i')))
              {
                  sujet[suj] = "J'";
              }
              else if (suj == 0)
              {
                  sujet[suj] = "Je";
              }
              sujLabel.Text = sujet[suj];
              tmpLabel.Text = tmpsArr[tmps[i]];
              btn[x].Click += b_click;
              trueBtn       = btn[x];

              int      k;
              string[] randChoix = new string[3];
              do
              {
                  for (j = 0; j < 3; j++)
                  {
                      k            = r.Next(choiceArr.Length);
                      randChoix[j] = choiceArr[k];
                  }
              } while (randChoix[0] == randChoix[1] || randChoix[1] == randChoix[2] || randChoix[0] == randChoix[2]);
              j = 0; k = 0;
              while (j < 4)
              {
                  if (j == x)
                  {
                      j++;
                  }
                  else
                  {
                      btn[j].Text   = randChoix[k].ToLower();
                      btn[j].Click += wrong_click;
                      j++; k++;
                  }
              }
            }
            catch (Exception EX) { MessageBox.Show(EX.ToString()); };
        }
コード例 #2
0
        public void NewCompEx()
        {
            comp            = true;
            nextBtn.Visible = false;
            timer1.Start();
            btnClicked = false;
            Random r = new Random();
            int    tmps = r.Next(4), v = r.Next(5);

            string[] sujet    = { "Je", "Tu", "Il/Elle/On", "Nous", "Vous", "Ils/Elles,On" };
            string[] tmpsArr  = { "Present", "Passé composé", "Futur", "Imparfait" };
            string[] VerbsArr = { "avoir", "etre", "faire", "venir", "aller" };
            int      suj      = r.Next(sujet.Length);

            try
            {
                string trueAns = SearchFrs.Conjugaison(VerbsArr[v], tmps, suj);
                string choices = SearchFrs.VerbsChoix(VerbsArr[v]);
                choices = choices.Remove(choices.IndexOf(trueAns), trueAns.Length + 1).Trim();
                //MessageBox.Show(choices);
                string[] choiceArr = choices.Split(',');
                Button[] btn       = { choice1Btn, choice2Btn, choice3Btn, choice4Btn };
                foreach (Button b in btn)
                {
                    b.Enabled   = true;
                    b.BackColor = Color.LightGray;
                    b.Click    -= b_click;
                    b.Click    -= wrong_click;
                }
                int x = r.Next(4);

                btn[x].Text = verbLabel.Text = trueAns.ToLower();
                if ((suj == 0) && ((trueAns[0] == 'é') || (trueAns[0] == 'a') || (trueAns[0] == 'i')))
                {
                    sujet[suj] = "J'";
                }
                else if (suj == 0)
                {
                    sujet[suj] = "Je";
                }
                sujLabel.Text = sujet[suj];
                tmpLabel.Text = tmpsArr[tmps];
                btn[x].Click += b_click;
                trueBtn       = btn[x];

                int      k, j;
                string[] randChoix = new string[3];
                do
                {
                    for (j = 0; j < 3; j++)
                    {
                        k            = r.Next(choiceArr.Length);
                        randChoix[j] = choiceArr[k];
                    }
                } while (randChoix[0] == randChoix[1] || randChoix[1] == randChoix[2] || randChoix[0] == randChoix[2]);
                j = 0; k = 0;
                while (j < 4)
                {
                    if (j == x)
                    {
                        j++;
                    }
                    else
                    {
                        btn[j].Text   = randChoix[k].ToLower();
                        btn[j].Click += wrong_click;
                        j++; k++;
                    }
                }
            }
            catch (Exception) { };
        }