Exemple #1
0
        private void Form2_Load(object sender, EventArgs e)
        {
            for (int x = 2; x < 10; x++)
            {
                for (int y = 2; y < 10; y++)
                {
                    BoutonCavalier b = new BoutonCavalier(x, y);
                    plateau[x, y]        = b;
                    plateau[x, y].Click += new EventHandler(this.Bouton_Click);
                    b.Location           = new System.Drawing.Point(60 * x, 60 + 60 * y);
                    b.Size = new System.Drawing.Size(60, 60);

                    if (x % 2 == 0 && y % 2 == 0)
                    {
                        b.BackColor = Color.LightCyan;
                    }
                    else if (x % 2 == 1 && y % 2 == 1)
                    {
                        b.BackColor = Color.LightCyan;
                    }
                    else if (x % 2 == 1 && y % 2 == 0)
                    {
                        b.BackColor = Color.IndianRed;
                    }
                    else if (x % 2 == 0 && y % 2 == 1)
                    {
                        b.BackColor = Color.IndianRed;
                    }
                    this.Controls.Add(b);
                }
            }
        }
Exemple #2
0
        private void Boutons_Click(object sender, EventArgs e)
        {
            if (sender is BoutonCavalier)
            {
                BoutonCavalier b = (BoutonCavalier)sender;
                if (cpt == 0)
                {
                    b.BackgroundImage = Image.FromFile(@"images\cavalier.png");
                    cpt++;
                }
                else
                {
                    BoutonCavalier b1 = coups[cpt - 1];
                    b1.BackgroundImage = null;
                    b1.Text            = cpt.ToString();
                    b.BackgroundImage  = Image.FromFile(@"images\cavalier.png");
                    cpt++;
                }

                coups.Add(b);

                for (int x = 2; x < 10; x++)
                {
                    for (int y = 2; y < 10; y++)
                    {
                        plateau[x, y].Enabled = false;
                        if (x % 2 == 0 && y % 2 == 0)
                        {
                            plateau[x, y].BackColor = Color.LightCyan;
                        }
                        else if (x % 2 == 1 && y % 2 == 1)
                        {
                            plateau[x, y].BackColor = Color.LightCyan;
                        }
                        else if (x % 2 == 1 && y % 2 == 0)
                        {
                            plateau[x, y].BackColor = Color.IndianRed;
                        }
                        else if (x % 2 == 0 && y % 2 == 1)
                        {
                            plateau[x, y].BackColor = Color.IndianRed;
                        }
                    }
                }
                for (int depl = 0; depl < 8; depl++)
                {
                    if (b.getX() + depi[depl] >= 2 && b.getY() + depj[depl] >= 2 && b.getX() + depi[depl] < 10 && b.getY() + depj[depl] < 10)
                    {
                        if (plateau[b.getX() + depi[depl], b.getY() + depj[depl]].Text == "")
                        {
                            plateau[b.getX() + depi[depl], b.getY() + depj[depl]].BackColor = Color.CadetBlue;
                            plateau[b.getX() + depi[depl], b.getY() + depj[depl]].Enabled   = true;
                        }
                    }
                }
            }
        }
Exemple #3
0
 private void Bouton_Click(object sender, EventArgs e)
 {
     if (sender is BoutonCavalier)
     {
         BoutonCavalier b = (BoutonCavalier)sender;
         grille[i, j]       = 0;
         i                  = b.getX();
         j                  = b.getY();
         grille[i, j]       = 1;
         b.BackgroundImage  = Image.FromFile(@"images\cavalier.png");
         plateau[i, j].Text = "1";
         //b.BackColor = Color.DarkTurquoise;
         b.Enabled = false;
     }
 }