VBA做的简易猜拳(增加胜率统计)


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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值