我正在尝试编写Tic Tac Toe游戏。
目前,当有人赢得比赛时,我需要一些帮助。
我的鳕鱼看起来像这样:
public partial class Form1:Form { int skrivaut = 1; 按钮[,]数组; public Form1() { InitializeComponent(); array = new Button [,] {{button1,button2,button3}, {button4,button5,button6}, {button7,button8,button9}}; $ if(array [0,0] == array [0,1]&& array [0,1] == array [0,2]) { MessageBox.Show("游戏结束!我们有一个胜利者"); }¥b $ b 否则if(array [1,0] == array [1,1]&& array [1,1] == array [1,2]) { MessageBox.Show("游戏结束!我们有一个胜利者"); }¥b $ b 否则if(array [2,0] == array [2,1]&& array [2,1] == array [2,2]) { MessageBox.Show("游戏结束!我们有一个胜利者"); }¥b $ b else if(array [0,0] == array [1,1]&& array [0,0] == array [2,2]) { MessageBox.Show("游戏结束!我们有一个胜利者"); }¥b $ b 否则if(array [0,2] == array [1,1]&& array [0,2] == array [2,2]) { MessageBox.Show("游戏结束!我们有一个胜利者"); }¥b $ b } private void button1_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button1.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button1.Text =" X"; }¥b $ b } private void button2_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button2.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button2.Text =" X"; }¥b $ b } private void button3_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button3.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button3.Text =" X"; }¥b $ b } private void button6_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button6.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button6.Text =" X"; }¥b $ b } private void button5_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button5.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button5.Text =" X"; }¥b $ b } private void button4_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button4.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button4.Text =" X"; }¥b $ b } private void button9_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button9.Text =" O"; }¥b $ b if(skrivaut%2 == 1) { button9.Text =" X"; }¥b $ b } private void button8_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button8.Text =" O"; $ }¥b $ b if(skrivaut%2 == 1) { button8.Text =" X"; }¥b $ b } private void button7_Click(object sender,EventArgs e) { skrivaut + = 1; $ if(skrivaut%2 == 0) { button7.Text =" O"; }¥b $ b if(skrivaut%2 == 1) { button7.Text =" X"; }¥b $ b }
任何想法?
解决方案
我会查看以下示例,不要复制它,而是要从中学习。
www.codeproject/Articles/2400 /井字棋-在-C
I'm trying to cod the Tic Tac Toe game.
At the moment I need some help telling when someone have won the game.
My cod looks like this:
public partial class Form1 : Form { int skrivaut = 1; Button[,] array; public Form1() { InitializeComponent(); array = new Button[,] { {button1, button2, button3 }, {button4, button5, button6 }, {button7, button8, button9 }}; if (array[0, 0] == array[0, 1] && array[0, 1] == array[0, 2]) { MessageBox.Show("Game over! We have a winner"); } else if (array[1, 0] == array[1, 1] && array[1, 1] == array[1, 2]) { MessageBox.Show("Game over! We have a winner"); } else if (array[2, 0] == array[2, 1] && array[2, 1] == array[2, 2]) { MessageBox.Show("Game over! We have a winner"); } else if (array[0, 0] == array[1, 1] && array[0, 0] == array[2, 2]) { MessageBox.Show("Game over! We have a winner"); } else if (array[0, 2] == array[1, 1] && array[0, 2] == array[2, 2]) { MessageBox.Show("Game over! We have a winner"); } } private void button1_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button1.Text = "O"; } if (skrivaut % 2 == 1) { button1.Text = "X"; } } private void button2_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button2.Text = "O"; } if (skrivaut % 2 == 1) { button2.Text = "X"; } } private void button3_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button3.Text = "O"; } if (skrivaut % 2 == 1) { button3.Text = "X"; } } private void button6_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button6.Text = "O"; } if (skrivaut % 2 == 1) { button6.Text = "X"; } } private void button5_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button5.Text = "O"; } if (skrivaut % 2 == 1) { button5.Text = "X"; } } private void button4_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button4.Text = "O"; } if (skrivaut % 2 == 1) { button4.Text = "X"; } } private void button9_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button9.Text = "O"; } if (skrivaut % 2 == 1) { button9.Text = "X"; } } private void button8_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button8.Text = "O"; } if (skrivaut % 2 == 1) { button8.Text = "X"; } } private void button7_Click(object sender, EventArgs e) { skrivaut += 1; if (skrivaut % 2 == 0) { button7.Text = "O"; } if (skrivaut % 2 == 1) { button7.Text = "X"; } }
Any idea?
解决方案I would look to the following example, not to copy it but to learn from it.
www.codeproject/Articles/2400/Tic-Tac-Toe-in-C
更多推荐
如何检查我的按钮文本是否相同?
发布评论