用VB2005编一个五子棋程序 有错误不能编译完成
问题出现在 第三个模块,
-------------------------这是第三个模块 whowin-----------------------------------------
'重新声明对方获胜表
Dim pwTab(10, 10, 192) As Boolean
Dim cwTab(10, 10, 192) As Boolean
'重新声明棋盘方块状态
Dim myBoard(10, 10) As Boolean
'重新声明双方使用棋数
Dim chessNum(2) As Integer
'重新声明可能获胜组合
Dim win(2, 192) As Integer
'初始化游戏
Public Sub gameInit()
'设定双方获胜表
Dim count As Integer
count = 0
'水平方向
For i = 0 To 9
For j = 0 To 5
For k = 0 To 4
pwTab(i, j + k, count) = True
cwTab(i, j + k, count) = True
Next
count = count + 1
Next
Next
'垂直方向
For i = 0 To 9
For j = 0 To 5
For k = 0 To 4
pwTab(j + k, i, count) = True
cwTab(j + k, i, count) = True
Next
count = count + 1
Next
Next
'正对角线方向
For i = 0 To 5
For j = 0 To 5
For k = 0 To 4
pwTab(j + k, i + k, count) = True
cwTab(j + k, i + k, count) = True
Next
count = count + 1
Next
Next
'反对角
For i = 0 To 5
For j = 9 To 4 Step -1
For k = 0 To 4
pwTab(j - k, i + k, count) = True
cwTab(j - k, i + k, count) = True
Next
count = count + 1
Next
Next
'设定棋盘方块信息
For i = 0 To 9
For j = 0 To 9
myBoard(i, j) = True
Next
Next
'设定双方使用棋数
chessNum(0) = chessNum(1) = 10
'获胜组合
For i = 0 To 191
win(0, i) = 0
win(1, i) = 0
Next
'初始化游戏状态变量
Form1.isOver = False
Form1.isTurn = True
End Sub
'玩家下棋
Public Sub playerTurn(Index As Integer)
'转换图像索引数组值
Dim board_X, board_Y
board_X = Index Mod Form1.MAP_Y
board_Y = Index \ Form1.MAP_Y
'判断是否可以下棋
If myBoard(board_X, board_Y) Then
chessNum(0) = chessNum(0) + 1
Form1.lblMessage = "目前玩家累计棋数: " & chessNum(0)
myBoard(board_X, board_Y) = False
Set Form1.MyImage(Index).Picture = Form1.myIList.ListImages(3).Picture
Call playSound
Else
Form1.lblMessage = "抱歉你不能下那里!!此方格已有棋子..."
Exit Sub
End If
'获胜组合
For k = 0 To 191
If pwTab(board_X, board_Y, k) Then
win(0, k) = win(0, k) + 1
cwTab(board_X, board_Y, k) = False
win(1, k) = 7
'检查是否获胜
If win(0, k) = 5 Then
Form1.isOver = True
Form1.lblMessage.Caption = "游戏结束!!玩家胜利!!"
Exit Sub
End If
End If
Next
'让电脑下棋
Form1.isTurn = False
'显示信息
Form1.lblMessage.Caption = "电脑思考中!!请稍候..."
Call comTurn
End Sub
'电脑下棋
Public Sub comTurn()
Dim score(2, 10, 10) As Integer
Dim max, l, m As Integer
max = 0
'计算获胜组合
For i = 0 To 9 Step 1
For j = 0 To 9 Step 1
'分数组
score(0, i, j) = 0
score(1, i, j) = 0
'当为空方格时
If myBoard(i, j) Then
For k = 0 To 191 Step 1
'计算玩家在此的获胜组合
If (pwTab(i, j, k) = True And win(0, k) <> 7) Then
Select Case win(0, k)
Case 0
score(0, i, j) = score(0, i, j) + 1
Case 1
score(0, i, j) = score(0, i, j) + 200
Case 2
score(0, i, j) = score(0, i, j) + 400
Case 3
score(0, i, j) = score(0, i, j) + 2000
Case 4
score(0, i, j) = score(0, i, j) + 10000
End Select
End If
'计算电脑在此的获胜组合
If (cwTab(i, j, k) = True And win(1, k) <> 7) Then
Select Case win(1, k)
Case 0
score(1, i, j) = score(1, i, j) + 1
Case 1
score(1, i, j) = score(1, i, j) + 210
Case 2
score(1, i, j) = score(1, i, j) + 420
Case 3
score(1, i, j) = score(1, i, j) + 2100
Case 4
score(1, i, j) = score(1, i, j) + 12000
End Select
End If
'当玩家分数大于max值时
If (score(0, i, j) > max) Then
max = score(0, i, j)
'电脑的最佳防守位置
l = i
m = j
ElseIf (score(0, i, j) = max) Then
If (score(1, i, j) > score(1, l, m)) Then
'防守位置
l = i
m = j
End If
End If
'当电脑分数大于max值时
If (score(1, i, j) > max) Then
max = score(1, i, j)
'电脑的攻击位置
l = i
m = j
'电脑分数大于max值时
ElseIf (score(1, i, j) = max) Then
If (score(0, i, j) > score(0, l, m)) Then
'电脑的最佳攻击位置
l = i
m = j
End If
End If
Next
End If
Next
Next
'执行电脑下棋程序
myBoard(l, m) = False
chessNum(1) = chessNum(1) + 1
Set Form1.MyImage(m * Form1.MAP_Y + l).Picture = Form1.myIList.ListImages(2).Picture
Call playSound
'检查是否达到平手条件
If chessNum(0) = 50 And chessNum(1) = 50 Then
Form1.whoWin=2 -------------------------------->运行的时候,会提示这句出错:编译错误:未找到方法与数据成员
Form1.isOver = True
Form1.lblMessage.Caption = "达到平手条件!!双方平手!!"
Exit Sub
Else
'获胜组合
For k = 0 To 191
If cwTab(l, m, k) Then
win(1, k) = win(1, k) + 1
pwTab(l, m, k) = False
win(0, k) = 7
'获胜条件
If win(1, k) = 5 Then
Form1.whoWin = 1
Form1.isOver = True
Form1.lblMessage.Caption = "电脑获胜!!游戏结束!!"
Exit Sub
End If
End If
Next
End If
'将游戏主导权交给玩家
Form1.isTurn = True
Form1.lblMessage.Caption = "换你下了!! " & "目前玩家累计棋数: " & chessNum(0)
End Sub
------------第三个模块结束-------------
为了什么按F5的时候,会出现 编译错误:未找到方法与数据成员呢????? 大奇怪啊,请教大侠们啦,VB6指出出错在第三个模块主这段中:
'检查是否达到平手条件
If chessNum(0) = 50 And chessNum(1) = 50 Then
Form1.whoWin=2 -------------------------------->运行的时候,会提示这句出错:编译错误:未找到方法与数据成员
Form1.isOver = True
Form1.lblMessage.Caption = "达到平手条件!!双方平手!!"
Exit Sub
[解决办法]
whoWin这个应该是窗体的一个自定义属性或方法,你看看窗体里有没有这个属性或方法.