示例#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
     {
     }
 }
示例#2
0
        private void GenererDamier(Control.ControlCollection controls)
        {
            damier = new Damier();
            CaseDamier[,] cases = damier.casesDamier;
            int i, y;

            for (i = 0; i < cases.GetLength(0); i++)
            {
                for (y = 0; y < cases.GetLength(0); y++)
                {
                    Pion pion = null;
                    if (i % 2 == 0 && y % 2 == 0)
                    {
                        if (y < 4)
                        {
                            pion = new Pion(1);
                        }
                        else if (y > 5)
                        {
                            pion = new Pion(0);
                        }
                    }
                    else if (i % 2 != 0 && y % 2 != 0)
                    {
                        if (y < 4)
                        {
                            pion = new Pion(1);
                        }
                        else if (y > 5)
                        {
                            pion = new Pion(0);
                        }
                    }

                    if (pion != null)
                    {
                        pion.MouseClick += new MouseEventHandler(pion_Click);
                        pion.Location    = new Point(0, 0);
                        cases[i, y].Controls.Add(pion);
                    }

                    cases[i, y].Location    = new Point(i * cases[i, y].Width, y * cases[i, y].Height);
                    cases[i, y].MouseClick += new MouseEventHandler(caseDamier_Click);
                    controls.Add(cases[i, y]);
                }
            }
        }
示例#3
0
        static bool CheckMiddleLocation(Damier damier, Pion pionEnCours, int rapportX, int rapportY, int fromX, int fromY)
        {
            if (!damier.casesDamier[fromX + rapportX, fromY + rapportY].HaveChild())
            {
                if (rapportX < 0)
                {
                    rapportX += 1;
                }
                else
                {
                    rapportX -= 1;
                }
                if (rapportY < 0)
                {
                    rapportY += 1;
                }
                else
                {
                    rapportY -= 1;
                }

                var pion = (Pion)null;
                try
                {
                    pion = damier.casesDamier[fromX + rapportX, fromY + rapportY].Controls.OfType <Pion>().First();
                }
                catch (InvalidOperationException)
                {}

                if (pion != null && pion.couleurPion != pionEnCours.couleurPion)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        static bool RemoveMiddleLocation(Damier damier, Pion pionEnCours, int rapportX, int rapportY, int fromX, int fromY)
        {
            if (rapportX < 0)
            {
                rapportX += 1;
            }
            else
            {
                rapportX -= 1;
            }
            if (rapportY < 0)
            {
                rapportY += 1;
            }
            else
            {
                rapportY -= 1;
            }

            var pion = (Pion)null;

            try
            {
                pion = damier.casesDamier[fromX + rapportX, fromY + rapportY].Controls.OfType <Pion>().First();
            }
            catch (InvalidOperationException e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }

            if (pion != null && pion.couleurPion != pionEnCours.couleurPion)
            {
                damier.casesDamier[fromX + rapportX, fromY + rapportY].Controls.Remove(pion);
                return(true);
            }
            else
            {
                return(false);
            }
        }