帮忙用vb语言编一个剪刀石头布游戏
- 提问者网友:巴黎塔下许过得承诺
- 2021-03-20 18:54
- 二级知识专家网友:高冷不撩人
- 2021-03-20 19:33
'-1石头
'0剪刀
'1布
Private Sub Command1_Click()
Dim a, b As Integer
Randomize
a = -1
b = Int(Rnd * (-3) + 2)
Label1.Caption = "石头"
Select Case a - b
Case -2: Label2.Caption = "布": MsgBox "电脑胜"
Case 0: Label2.Caption = "石头": MsgBox "平"
Case -1: Label2.Caption = "剪刀": MsgBox "玩家胜"
End Select
End Sub
Private Sub Command2_Click()
Dim a, b As Integer
Randomize
a = 0
b = Int(Rnd * (-3) + 2)
Label1.Caption = "剪刀"
Select Case a - b
Case 1: Label2.Caption = "布": MsgBox "玩家胜"
Case 0: Label2.Caption = "剪刀": MsgBox "平"
Case -1: Label2.Caption = "石头": MsgBox "电脑胜"
End Select
End Sub
Private Sub Command3_Click()
Dim a, b As Integer
Randomize
a = 1
b = Int(Rnd * (-3) + 2)
Label1.Caption = "布"
Select Case a - b
Case 2: Label2.Caption = "石头": MsgBox "玩家胜"
Case 0: Label2.Caption = "布": MsgBox "平"
Case 1: Label2.Caption = "剪刀": MsgBox "电脑胜"
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "石头"
Command2.Caption = "剪刀"
Command3.Caption = "布"
End Sub
- 1楼网友:猖狂的痴情人
- 2021-03-20 19:53
控件,label1上边,label2,command(0-2)下排,command4(0-2) 上排,复制一下代码即可运行
dim myy as integer '我赢得次数 dim myp as integer '平的次数 dim mys as integer '我输的次数,下边是电脑的相同 dim couy as integer dim coup as integer dim cous as integer private sub command1_click(index as integer) dim str as integer
command4(0).visible = false command4(1).visible = false command4(2).visible = false str = int(rnd * 3) command4(str).visible = true if index = 0 then if str = 0 then myp = myp + 1 coup = coup + 1 elseif str = 1 then cous = cous + 1 myy = myy + 1 elseif str = 2 then couy = couy + 1 mys = mys + 1 end if end if if index = 1 then if str = 0 then mys = mys + 1 couy = couy + 1 elseif str = 1 then coup = coup + 1 myp = myp + 1 elseif str = 2 then cous = cous + 1 myy = myy + 1 end if end if if index = 2 then if str = 0 then myy = myy + 1 cous = cous + 1 elseif str = 1 then couy = couy + 1 mys = mys + 1 elseif str = 2 then couy = couy + 1 myy = myy + 1 end if end if label1.caption = "电脑:" & "赢: " & couy & "平: " & coup & "输:" & cous label2.caption = "我:" & "赢: " & myy & "平: " & myp & "输:" & mys end sub