Vb.net tic-tac-toe程序有问题
我正在用visualbasic为tic-tac-toe做一个程序。我很难找到赢家。O工作正常,但是程序说当一行中只有两个时(或者如果一个X放在中间),X是赢家 这是我的CheckWin sub:Vb.net tic-tac-toe程序有问题,vb.net,tic-tac-toe,Vb.net,Tic Tac Toe,我正在用visualbasic为tic-tac-toe做一个程序。我很难找到赢家。O工作正常,但是程序说当一行中只有两个时(或者如果一个X放在中间),X是赢家 这是我的CheckWin sub: Sub CheckWin() If ctr < 9 And board(0, 0) = 2 Or board(0, 1) = 2 Or board(1, 0) = 2 Or board(1, 1) = 2 Or board(1, 2) = 2 Or board(2, 1) = 2 Or
Sub CheckWin()
If ctr < 9 And board(0, 0) = 2 Or board(0, 1) = 2 Or board(1, 0) = 2 Or board(1, 1) = 2 Or board(1, 2) = 2 Or board(2, 1) = 2 Or board(2, 2) = 2 Then
If board(0, 0) = 0 And board(1, 1) = 0 And board(2, 2) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 0) = 1 And board(1, 1) = 1 And board(2, 2) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 2) = 0 And board(1, 1) = 0 And board(2, 0) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 2) = 1 And board(1, 1) = 1 And board(2, 0) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 0) = 0 And board(1, 0) = 0 And board(2, 0) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 0) = 1 And board(1, 0) = 1 And board(2, 0) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 0) = 0 And board(0, 1) = 0 And board(0, 2) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 0) = 1 And board(0, 1) = 1 And board(0, 2) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 1) = 0 And board(1, 1) = 0 And board(2, 1) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 1) = 1 And board(1, 1) = 1 And board(2, 1) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 2) = 0 And board(1, 2) = 0 And board(2, 2) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(0, 2) = 1 And board(1, 2) = 1 And board(2, 2) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(1, 0) = 0 And board(1, 1) = 0 And board(1, 2) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(1, 0) = 1 And board(1, 1) = 1 And board(1, 2) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(2, 0) = 0 And board(2, 1) = 0 And board(2, 2) = 0 Then
MsgBox("X is the winner.", MsgBoxStyle.Exclamation)
Call disable()
ElseIf board(2, 0) = 1 And board(2, 1) = 1 And board(2, 2) = 1 Then
MsgBox("O is the winner.", MsgBoxStyle.Exclamation)
Call disable()
End If
End If
If ctr = 9 Then
MsgBox("The game is a tie.", MsgBoxStyle.Exclamation)
Call disable()
End If
End Sub
Sub disable()
Pic00.Enabled = False
Pic01.Enabled = False
Pic02.Enabled = False
Pic10.Enabled = False
Pic11.Enabled = False
Pic12.Enabled = False
Pic20.Enabled = False
Pic21.Enabled = False
Pic22.Enabled = False
End Sub
Sub CheckWin()
如果ctr<9且电路板(0,0)=2或电路板(0,1)=2或电路板(1,0)=2或电路板(1,1)=2或电路板(1,2)=2或电路板(2,1)=2,则
如果电路板(0,0)=0,电路板(1,1)=0,电路板(2,2)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,0)=1,电路板(1,1)=1,电路板(2,2)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,2)=0,电路板(1,1)=0,电路板(2,0)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,2)=1,电路板(1,1)=1,电路板(2,0)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
其他板(0,0)=0,板(1,0)=0,板(2,0)=0
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,0)=1,电路板(1,0)=1,电路板(2,0)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,0)=0,电路板(0,1)=0,电路板(0,2)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,0)=1,电路板(0,1)=1,电路板(0,2)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,1)=0,电路板(1,1)=0,电路板(2,1)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,1)=1,电路板(1,1)=1,则电路板(2,1)=1
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,2)=0,电路板(1,2)=0,电路板(2,2)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(0,2)=1,电路板(1,2)=1,电路板(2,2)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(1,0)=0,电路板(1,1)=0,电路板(1,2)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(1,0)=1,电路板(1,1)=1,电路板(1,2)=1,则
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(2,0)=0,电路板(2,1)=0,电路板(2,2)=0,则
MsgBox(“X是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果电路板(2,0)=1,电路板(2,1)=1,那么电路板(2,2)=1
MsgBox(“O是赢家。”,MsgBoxStyle.感叹号)
调用禁用()
如果结束
如果结束
如果ctr=9,则
MsgBox(“比赛打成平局。”,MsgBoxStyle.感叹号)
调用禁用()
如果结束
端接头
子禁用()
Pic00.Enabled=False
Pic01.Enabled=False
Pic02.Enabled=False
Pic10.Enabled=False
Pic11.Enabled=False
Pic12.Enabled=False
Pic20.Enabled=False
Pic21.Enabled=False
Pic22.Enabled=False
端接头
你正在做的事情是不必要的复杂。我愿意完全重写,而不是调试你所拥有的。让board(i,j)=0
表示一个空正方形,board(i,j)=-1
表示一个X
,board(i,j)=1
表示和O
。然后使用循环计算行、列和对角和。如果任何总和为-3,X
获胜,如果任何总和为3,O
获胜