Esempio n. 1
0
 public void Jouer(JeuDeDamesForm form, Damier damier)
 {
     myTurn = true;
     if (isIA)
     {
         CaseDamier caseDamier = damier.casesDamier[i, y];
         var        pion       = (Pion)null;
         try
         {
             pion = caseDamier.Controls.OfType <Pion>().First();
         }
         catch (InvalidOperationException e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
         }
         if (pion != null)
         {
             form.pion_Click(pion, null);
             form.caseDamier_Click(damier.casesDamier[i + 1, y + 1], null);
             i++;
             y++;
         }
     }
     else
     {
     }
 }
Esempio n. 2
0
        public void caseDamier_Click(object sender, EventArgs e)
        {
            caseCible = (CaseDamier)sender;
            if (isPionEnCours && caseCible.couleurCase == 1)
            {
                damier.RestaurerBordures();
                int cc_positionX = caseCible.Location.X / 45;
                int cc_positionY = caseCible.Location.Y / 45;
                int pec_positionX = pionEnCours.Parent.Location.X / 45;
                int pec_positionY = pionEnCours.Parent.Location.Y / 45;
                int rapportX = (cc_positionX - pec_positionX);
                int rapportY = (cc_positionY - pec_positionY);
                int pRapportX = rapportX, pRapportY = rapportY;
                if (rapportX < 0)
                {
                    pRapportX *= -1;
                }
                if (rapportY < 0)
                {
                    pRapportY *= -1;
                }

                if (pRapportX == 1 && ((user.myTurn && rapportY < 0) || (iA.myTurn && rapportY > 0)))
                {
                    caseCible.Controls.Add(pionEnCours);
                    compteurTours++;
                }
                else if (pRapportX == 2 && pRapportY == 2)
                {
                    if (CheckMiddleLocation(damier, pionEnCours, rapportX, rapportY, pec_positionX, pec_positionY))
                    {
                        RemoveMiddleLocation(damier, pionEnCours, rapportX, rapportY, pec_positionX, pec_positionY);
                        caseCible.Controls.Add(pionEnCours);
                        compteurTours++;
                    }
                }
                isPionEnCours = false;
            }
        }
Esempio n. 3
0
        private void BorderPossibilities()
        {
            if (isPionEnCours)
            {
                try
                {
                    CaseDamier caseDamier = (CaseDamier)pionEnCours.Parent;
                    if (!damier.casesDamier[caseDamier.Location.X / 45 + 1, caseDamier.Location.Y / 45 - 1].HaveChild())
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 + 1, caseDamier.Location.Y / 45 - 1].BackColor = Color.Red;
                    }
                    if (!damier.casesDamier[caseDamier.Location.X / 45 - 1, caseDamier.Location.Y / 45 - 1].HaveChild())
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 - 1, caseDamier.Location.Y / 45 - 1].BackColor = Color.Red;
                    }

                    if (CheckMiddleLocation(damier, pionEnCours, -2, -2, caseDamier.Location.X / 45, caseDamier.Location.Y / 45))
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 - 2, caseDamier.Location.Y / 45 - 2].BackColor = Color.Red;
                    }
                    if (CheckMiddleLocation(damier, pionEnCours, 2, 2, caseDamier.Location.X / 45, caseDamier.Location.Y / 45))
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 + 2, caseDamier.Location.Y / 45 + 2].BackColor = Color.Red;
                    }
                    if (CheckMiddleLocation(damier, pionEnCours, -2, 2, caseDamier.Location.X / 45, caseDamier.Location.Y / 45))
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 - 2, caseDamier.Location.Y / 45 + 2].BackColor = Color.Red;
                    }
                    if (CheckMiddleLocation(damier, pionEnCours, 2, -2, caseDamier.Location.X / 45, caseDamier.Location.Y / 45))
                    {
                        damier.casesDamier[caseDamier.Location.X / 45 + 2, caseDamier.Location.Y / 45 - 2].BackColor = Color.Red;
                    }
                }
                catch (NullReferenceException) { }
                catch (IndexOutOfRangeException) { }
            }
        }
Esempio n. 4
0
        public Damier()
        {
            casesDamier = new CaseDamier[10, 10];
            int i, y;

            for (i = 0; i < casesDamier.GetLength(0); i++)
            {
                for (y = 0; y < casesDamier.GetLength(0); y++)
                {
                    if (i % 2 == 0 && y % 2 != 0)
                    {
                        casesDamier[i, y] = new CaseDamier(0);
                    }
                    else if (i % 2 != 0 && y % 2 == 0)
                    {
                        casesDamier[i, y] = new CaseDamier(0);
                    }
                    else
                    {
                        casesDamier[i, y] = new CaseDamier(1);
                    }
                }
            }
        }