上面是电路板的图像
我发现很难弄清楚如何在不使用蛮力枚举的情况下连续检测 2 种颜色以确定获胜者。
我有一个算法,我一直在尝试实现它,但我似乎无法让它工作,任何人都知道如何做到这一点.. 会很有帮助,谢谢..
我想检测获胜者对角线垂直和水平..
ps 我通常不寻求解决方案,但这次我真的需要一些帮助。非常感谢
这是我为程序提供的代码,可让您放心
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Button[] btns;
private Button[] btns2;
private Button[] btns3;
public Color[] col;
// public var x;
public Form1()
{
InitializeComponent();
btns = new Button[2] { button2, button3 };
btns2 = new Button[2] { button4, button5 };
btns3 = new Button[2] { button9, button8 };
col = new Color[2] { Color.Red, Color.Yellow };
Color x = col[0];
Color y = col[1];
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var btn in btns)
{
btn.Enabled = false;
btn.BackColor = Color.LightCyan;
}
foreach (var btn in btns2)
{
btn.Enabled = false;
btn.BackColor = Color.LightCyan;
}
foreach (var btn in btns3)
{
btn.Enabled = false;
btn.BackColor = Color.LightCyan;
}
}
public int state;
int cc = 0;
private void button1_Click(object sender, EventArgs e)
{
foreach (var btn in btns)
{
{
if (!btn.Enabled)
{
btn.Enabled = true;
if (cc == 0)
{
cc = 1;
btn.BackColor = col[0];
}
else
{
cc = 0;
btn.BackColor = col[1];
}
return;
}
}
}
}
private void button6_Click(object sender, EventArgs e)
{
foreach (var btn in btns2)
{
if (!btn.Enabled)
{
btn.Enabled = true;
if (cc == 0)
{
cc = 1;
btn.BackColor = col[0];
}
else
{
cc = 0;
btn.BackColor = col[1];
}
return;
}
}
}
private void button7_Click(object sender, EventArgs e)
{
foreach (var btn in btns3)
{
if (!btn.Enabled)
{
btn.Enabled = true;
if (cc == 0)
{
cc = 1;
btn.BackColor = col[0];
}
else
{
cc = 0;
btn.BackColor = col[1];
}
return;
}
}
}
}
}