Ejemplo n.º 1
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]);
                }
            }
        }
Ejemplo n.º 2
0
 public void pion_Click(object sender, EventArgs e)
 {
     pionEnCours = (Pion)sender;
     if (pionEnCours.couleurPion == 0 && user.myTurn)
     {
         damier.RestaurerBordures();
         isPionEnCours = true;
         BorderPossibilities();
     }
     else if (iA.myTurn)
     {
         isPionEnCours = true;
     }
     else
     {
         pionEnCours = null;
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }