private void Form1_Load(object sender, EventArgs e) { this.Size = new Size(1200, 1200); for (int x = 0; x < 12; x++) { for (int y = 0; y < 12; y++) { plateau[x, y] = new ButtonPerso(x, y); if ((x >= 2 && x <= 9) && (y >= 2 && y <= 9)) { plateau[x, y].Size = new Size(99, 99); plateau[x, y].Location = new Point((x) * 100, ((y - 2) * 100) + 200); plateau[x, y].Visible = true; plateau[x, y].Click += new EventHandler(this.ButtonClik); } else { plateau[x, y].Visible = false; plateau[x, y].Size = new Size(0, 0); plateau[x, y].Enabled = false; plateau[x, y].cliqué = true; } this.Controls.Add(this.plateau[x, y]); if ((x + y) % 2 != 0) { plateau[x, y].BackColor = Color.Black; } } } }
public void replay() { ButtonPerso max = plateau[2, 2]; cavalier = new ButtonPerso(0, 0); int test; int maximum = 0; for (int i = 2; i <= 9; i++) { for (int j = 2; j <= 9; j++) { if (Int32.TryParse(plateau[i, j].Text, out test)) { if (test >= maximum) { maximum = test; max = plateau[i, j]; } } else { ; } } } for (int i = 2; i <= 9; i++) { for (int j = 2; j <= 9; j++) { if (Int32.TryParse(plateau[i, j].Text, out test)) { if (test == maximum - 1) { cavalier = plateau[i, j]; } } } } max.cliqué = false; refreshPlateau(); compteurCoup--; max.Text = ""; afficherCoups(cavalier.x, cavalier.y); }
private void ButtonClik(object sender, EventArgs e) { ButtonPerso b = (ButtonPerso)sender; if (compteurCoup == 1 || b.BackColor == Color.Green) { if (!b.cliqué) { if (compteurCoup == 1) { ii = b.x; ij = b.y; } b.cliqué = true; cavalier = b; refreshPlateau(); b.BackColor = Color.Red; b.Text = "" + compteurCoup++; afficherCoups(b.x, b.y); if (endGame() && aGagné()) { MessageBox.Show("Vous avez Gagné"); } else if (endGame()) { MessageBox.Show("Vous avez perdu"); } } else { MessageBox.Show("Vous avez deja joué ici"); } } else { MessageBox.Show("Coup invalide"); } }