vb.net小游戏代码 vb游戏代码大全( 二 )


k = 0
For i = 1 To 8
For j = 1 To 8
If cbText(k).Text = "" Then ChessBoard(i, j) = 0
If cbText(k).Text = "101" Then ChessBoard(i, j) = 101
If cbText(k).Text = "201" Then ChessBoard(i, j) = 201
If cbText(k).Text = "102" Then ChessBoard(i, j) = 102
If cbText(k).Text = "202" Then ChessBoard(i, j) = 202
k = k + 1
Next j
Next i
End Sub
Rem 显示(将ChessBoard数组的内容显示到屏幕后)
Private Sub Display()
Dim i As Integer, j As Integer, k As Integer
k = 0
For i = 1 To 8
For j = 1 To 8
If ChessBoard(i, j) = 0 Then
cbText(k).Text = ""
Else
cbText(k).Text = ChessBoard(i, j)
End If
k = k + 1
Next j
Next i
Call 胜负判断
End Sub
Rem 胜负判断
Private Sub 胜负判断()
Dim i As Integer, j As Integer
Dim a As Integer, b As Integer
a = 0: b = 0
For i = 1 To 8
For j = 1 To 8
If Int(ChessBoard(i, j) / 100) = 1 Then a = a + 1''计算玩家的棋子数
If Int(ChessBoard(i, j) / 100) = 2 Then b = b + 1''计算电脑的棋子数
Next j
Next i
If a = 0 Then Call MsgBox("我赢了!", vbOKOnly + 32, "提示:"): Exit Sub
If b = 0 Then Call MsgBox("我认输了!", vbOKOnly + 32, "提示:"): Exit Sub
End Sub
Rem 返回估值
Private Function CurrentValue(Cer As Byte) As Integer
Dim i As Integer, j As Integer
CurrentValue = https://www.04ip.com/post/0
For i = 1 To 8
For j = 1 To 8
If Int(ChessBoard(i, j) / 100) = Cer Then _
CurrentValue = https://www.04ip.com/post/CurrentValue + ChessBoard(i, j) Mod 100 * 100 + 100''是我方的棋子,棋子为1加100分,棋子为2加200分
If Int(ChessBoard(i, j) / 100) = NextCer(Cer) Then _
CurrentValue = https://www.04ip.com/post/CurrentValue - (ChessBoard(i, j) Mod 100 * 100 + 100)''对方的棋子,棋子为1减100分,棋子为2减200分
Next j
Next i
End Function
Rem 如果Cer方i,j的棋子还可以吃子则返回True
Private Function IsLine(Cer As Byte, i As Byte, j As Byte) As Boolean
Dim x As Byte, y As Byte, x1 As Byte, y1 As Byte
IsLine = False
''开始搜索棋盘
''如果是Cer方的棋子
If Int(ChessBoard(i, j) / 100) = Cer Then
''吃子式走法1:即如果基本走法的位置有对方的棋子则可以跳吃(走法限制:Cer为1或棋子为加强棋才可走)
If Int(ChessBoard(i - 1, j - 1) / 100) = NextCer(Cer) And (Cer = 1 Or ChessBoard(i, j) Mod 100 = 2) Then
x = (i - 1) - 1''目标坐标
y = (j - 1) - 1
x1 = i - 1''吃子坐标
y1 = j - 1
If x0 And y0 And x9 And y9 And ChessBoard(x, y) = 0 Then IsLine = True'有可吃子,返回True
End If
''吃子式走法2
If Int(ChessBoard(i - 1, j + 1) / 100) = NextCer(Cer) And (Cer = 1 Or ChessBoard(i, j) Mod 100 = 2) Then
x = (i - 1) - 1
y = (j + 1) + 1
x1 = i - 1
y1 = j + 1
If x0 And y0 And x9 And y9 And ChessBoard(x, y) = 0 Then IsLine = True'有可吃子,返回True
End If
''吃子式走法3
If Int(ChessBoard(i + 1, j - 1) / 100) = NextCer(Cer) And (Cer = 2 Or ChessBoard(i, j) Mod 100 = 2) Then
x = (i + 1) + 1
y = (j - 1) - 1
x1 = i + 1
y1 = j - 1
If x0 And y0 And x9 And y9 And ChessBoard(x, y) = 0 Then IsLine = True'有可吃子 , 返回True
End If
''吃子式走法4
If Int(ChessBoard(i + 1, j + 1) / 100) = NextCer(Cer) And (Cer = 2 Or ChessBoard(i, j) Mod 100 = 2) Then
x = (i + 1) + 1
y = (j + 1) + 1
x1 = i + 1
y1 = j + 1
If x0 And y0 And x9 And y9 And ChessBoard(x, y) = 0 Then IsLine = True'有可吃子,返回True
End If
End If
End Function
Rem 如果Cer方的棋子还可以吃子则返回True
Private Function IsLine2(Cer As Byte) As Boolean

推荐阅读