如何检查我的按钮文本是否相同?

编程入门 行业动态 更新时间:2024-10-12 05:48:12
本文介绍了如何检查我的按钮文本是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写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

更多推荐

如何检查我的按钮文本是否相同?

本文发布于:2023-11-10 14:38:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   文本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!