Dim V1, V2, V3 As Integer
'石头按钮触发
Private Sub CommandButton1_Click()
Label4.Caption = "石"
Call run(1)
End Sub
'剪刀按钮触发
Private Sub CommandButton2_Click()
Label4.Caption = "剪み"
Call run(2)
End Sub
'布按钮触发
Private Sub CommandButton3_Click()
Label4.Caption = "布"
Call run(3)
End Sub
'逻辑处理共通
Private Sub run(obj)
'胜率初期化
If V1 = Empty Then
V1 = 0
End If
If V2 = Empty Then
V2 = 0
End If
If V3 = Empty Then
V3 = 0
End If
'計算逻辑
Dim temp As Integer
'随机数
temp = Rnd(3) * 3 + 1
If temp = 1 Then
Label5.Caption = "石"
If obj = 1 Then
Label3.Caption = "平局"
V3 = V3 + 1
ElseIf obj = 3 Then
Label3.Caption = "人勝利"
V1 = V1 + 1
Else
Label3.Caption = "電脳勝利"
V2 = V2 + 1
End If
ElseIf temp = 2 Then
Label5.Caption = "剪み"
If obj = 2 Then
Label3.Caption = "平局"
V3 = V3 + 1
ElseIf obj = 1 Then
Label3.Caption = "人勝利"
V1 = V1 + 1
Else
Label3.Caption = "電脳勝利"
V2 = V2 + 1
End If
Else
Label5.Caption = "布"
If obj = 3 Then
Label3.Caption = "平局"
V3 = V3 + 1
ElseIf obj = 2 Then
Label3.Caption = "人勝利"
V1 = V1 + 1
Else
Label3.Caption = "電脳勝利"
V2 = V2 + 1
End If
End If
'输出胜率
Label6.Caption = "人:" & V1 & " 電脳:" & V2 & " 平局:" & V3 & " 総合:" & (V1 + V2 + V3)
End Sub
VBA做的简易猜拳(增加胜率统计)
最新推荐文章于 2024-03-27 22:09:05 发布