c# - 如何更改 button.text 而不点击它?
问题描述
我正在做一个井字游戏,现在我想做一种“AI”作为对手。对手的“X”当然是自己产生的。我是初学者,如果不单击按钮,我不知道如何做到这一点。
解决方案
要更改 button.text,您必须做的所有事情是:
button.text = "something";
但是对于您的第二个问题,您的 Ai 必须是这样的:
try{
for(var k =-1;k<2;k++){ //k is the parameter responsible for previous and
//next also up and down cells and even also the upper right , bottom right,bottom left and bottom right cells.
for(var i =0;k<3;i++)
{
for(var j =0;k<3;j++)
{
if(x[i,j]==x[i+k,j+k] && ((i+k<3)&&(j+k<3)) //checks if there is two cells having the same "X" in a row.
{
button.text = "O"
}
}
}
}
}
catch(Exception e){
//nothing
}
我放置了 try catch 块以避免索引错误。
推荐阅读
- html - 使 main 占据主体的全部高度,除了标题 NextJS React
- python - 一旦在我的 for 循环中满足某个条件,如何用 1 填充 N x N 矩阵的第一列的其余部分?
- firebase - 如何将未来放入 initState 中?
- html - 网站上的 Facebook 赞按钮仅在访问者登录 FB 时有效
- forms - 导航反应本机
- r - 从 R 中的 zip 文件中读取数据时,它会破坏先前读取的数据
- linux - 运行可执行文件时的 Termux 错误
- python-3.x - Django rest 允许获取但不允许列出
- python - 从多个类、xpath 或 css 选择器中按索引提取文本
- ios - 我使用 cocoapods 制作静态框架