Bonjour les Developpez,
Je suis un débutant et je ne suis pas calé en programmation.
Prière m'apportez votre aide pour l'avancement de mon projet.
Bref, Je suis entrain de faire le jeu OXO en C#
Depuis un bon bout je suis bloqué au niveau des conditions.
Mon objectif est de faire ressortir un messageBox lorsque les A ou B sont alignées en lignes ou en diagonales (A A A / B B B), en plus que le jeu recommence en cliquant sur le messageBox.
Lorsque j'écris les conditions sur le joueur A, il ne reconnait pas la lettre A pourtant cette lettre s'affiche sur mes buttons après un clic. Comme sous l'image ci dessous.
voici aussi mon Code:
"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Games
{
public partial class Form1 : Form
{
int i;
public Form1()
{
InitializeComponent();
}
/*private void button1_Click(object sender, EventArgs e)
{
}
*/
private void Form1_Load(object sender, EventArgs e)
{
//if (button1.Text == button2.Text && button2.Text == button3.Text && button1.Text == "A")
if (button1.Text == A && button2.Text == A && button3.Text == A )
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
//if (button6.Text == button5.Text && button5.Text == button4.Text && button6.Text == A)
if (button4.Text == A && button5.Text == A && button6.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
//if (button9.Text == button8.Text && button8.Text == button7.Text && button9.Text == A)
if (button7.Text == A && button8.Text == A && button9.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
// if (button1.Text == button4.Text && button4.Text == button7.Text && button1.Text == A)
if (button1.Text == A && button4.Text == A && button7.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
//if (button2.Text == button5.Text && button5.Text == button8.Text && button2.Text == A)
if (button2.Text == A && button5.Text == A && button8.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
//if (button3.Text == button6.Text && button6.Text == button9.Text && button3.Text == A)
if (button3.Text == A && button6.Text == A && button9.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
// if (button1.Text == button5.Text && button5.Text == button9.Text && button1.Text == A)
if (button1.Text == A && button5.Text == A && button9.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
//if (button3.Text == button5.Text && button5.Text == button7.Text && button3.Text == A)
if (button3.Text == A && button5.Text == A && button7.Text == A)
{
MessageBox.Show("Joueur" + A + "à GAGNER");
NewJeu();
}
else if (i == 9)
{
MessageBox.Show("Jeu Perdu");
NewJeu();
}
}
private void button10_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button11_Click (object sender, EventArgs e)
{
button1.Text = button2.Text =
button3.Text = button4.Text =
button5.Text = button6.Text =
button7.Text = button8.Text =
button9.Text = "";
i = 0;
}
public void NewJeu()
{
button1.Text = button2.Text =
button3.Text = button4.Text =
button5.Text = button6.Text =
button7.Text = button8.Text =
button9.Text = "";
i = 0;
MessageBox.Show("Jeu Perdu");
NewJeu();
}
private void labelScoreA_Click(object sender, EventArgs e)
{
}
private void labelScoreB_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (i < 9 && button1.Text == "")
if (i % 2 == 0)
button1.Text = "A";
else
button1.Text = "B";
i++;
}
private void button2_Click_1(object sender, EventArgs e)
{
if (i < 9 && button2.Text == "")
if (i % 2 == 0)
button2.Text = "A";
else
button2.Text = "B";
i++;
}
private void button3_Click_1(object sender, EventArgs e)
{
if (i < 9 && button3.Text == "")
if (i % 2 == 0)
button3.Text = "A";
else
button3.Text = "B";
i++;
}
private void button4_Click_1(object sender, EventArgs e)
{
if (i < 9 && button4.Text == "")
if (i % 2 == 0)
button4.Text = "A";
else
button4.Text = "B";
i++;
}
private void button5_Click_1(object sender, EventArgs e)
{
if (i < 9 && button5.Text == "")
if (i % 2 == 0)
button5.Text = "A";
else
button5.Text = "B";
i++;
}
private void button6_Click_1(object sender, EventArgs e)
{
if (i < 9 && button6.Text == "")
if (i % 2 == 0)
button6.Text = "A";
else
button6.Text = "B";
i++;
}
private void button7_Click_1(object sender, EventArgs e)
{
if (i < 9 && button7.Text == "")
if (i % 2 == 0)
button7.Text = "A";
else
button7.Text = "B";
i++;
}
private void button8_Click_1(object sender, EventArgs e)
{
if (i < 9 && button8.Text == "")
if (i % 2 == 0)
button8.Text = "A";
else
button8.Text = "B";
i++;
}
private void button9_Click_1(object sender, EventArgs e)
{
if (i < 9 && button9.Text == "")
if (i % 2 == 0)
button9.Text = "A";
else
button9.Text = "B";
i++;
}
}
}
"
Merci d'avance pour votre votre aide
Partager