Witam
Za zadanie mam zrobic grę kółko i krzyżyk w c# w visualu i napotkałem pewien problem. Od razu ostrzegę że mamy tylko trochę go liznąć bo inna specjalizacja ale do meritum. Chciałbym dla mojego kodu stworzyć funkcję lub tablicę przycisków, aby nie był on tak powtarzalny jak widać to w kodzie, ale nie znajac dobrze c# i przeszukując internet nie natrafiłem na nic pomocnego. Także liczę na to że znajdzie się ktoś tutaj kto mi pomoże, beż niemiłych docinek.
namespace Kolko_i_krzyzyk
{
public partial class Form1 : Form
{
int runda;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button1.Text = "X";
runda++;
}
else if (runda == 1)
{
button1.Text = "O";
runda--;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button2.Text = "X";
runda++;
}
else if (runda == 1)
{
button2.Text = "O";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button3.Text = "X";
runda++;
}
else if (runda == 1)
{
button3.Text = "O";
}
}
private void button4_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button4.Text = "X";
runda++;
}
else if (runda == 1)
{
button4.Text = "O";
}
}
private void button5_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button5.Text = "X";
runda++;
}
else if (runda == 1)
{
button5.Text = "O";
}
}
private void button6_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button6.Text = "X";
runda++;
}
else if (runda == 1)
{
button6.Text = "O";
}
}
private void button7_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button7.Text = "X";
runda++;
}
else if (runda == 1)
{
button7.Text = "O";
}
}
private void button8_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button8.Text = "X";
runda++;
}
else if (runda == 1)
{
button8.Text = "O";
}
}
private void button9_Click(object sender, EventArgs e)
{
if (runda == 0)
{
button9.Text = "X";
runda++;
}
else if (runda == 1)
{
button9.Text = "O";
}
}
}
}