【发布时间】:2015-12-14 11:08:48
【问题描述】:
我正在为 Visual Basic 中的井字游戏制作程序。我特别难以检查获胜者。 O 可以正常工作,但程序说,当连续只有两个时(或者如果 x 放在中间),X 是赢家。
这是我的 CheckWin 子:
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
【问题讨论】:
标签: vb.net tic-tac-toe