用VB写一个和电脑猜石头剪刀布的小游戏(要代码)
建三个命令按钮,Caption分别为石头、剪刀、布一个label,显示电脑出的(显示石头、剪刀、或布)再建一个label,显示赢得次数分别是多少好的话追加20分!顺便解决...
建三个命令按钮,Caption分别为石头、剪刀、布
一个label,显示电脑出的(显示石头、剪刀、或布)
再建一个label,显示赢得次数分别是多少
好的话追加20分!
顺便解决一个问题,谁能用VB写一个给出QQ账号,然后开始试密码的程序,因为我的QQ密码忘了,只记得全用了阿拉伯数字。(要代码,谁回答了这个问题,在加那个问题,我追加25分!!!!!!!!!!!) hoyogoo,在回答这个问题,追加25分(多追加5分)!!!!!!!!!!!!!!
怎么用?二楼 展开
一个label,显示电脑出的(显示石头、剪刀、或布)
再建一个label,显示赢得次数分别是多少
好的话追加20分!
顺便解决一个问题,谁能用VB写一个给出QQ账号,然后开始试密码的程序,因为我的QQ密码忘了,只记得全用了阿拉伯数字。(要代码,谁回答了这个问题,在加那个问题,我追加25分!!!!!!!!!!!) hoyogoo,在回答这个问题,追加25分(多追加5分)!!!!!!!!!!!!!!
怎么用?二楼 展开
2个回答
展开全部
如你所说
1、建立三个按钮command1,command2,command3
2、建立两个标签label1,label2
3、复制代码,运行
Dim a As Long
Dim b As Long
Dim c As Long
Dim e As Long
Private Sub Command1_Click()
c = 1
Call check(c)
End Sub
Private Sub Command2_Click()
c = 2
Call check(c)
End Sub
Private Sub Command3_Click()
c = 3
Call check(c)
End Sub
Private Sub Form_Load()
Command1.Caption = "石头"
Command2.Caption = "剪刀"
Command3.Caption = "布"
Label1.Caption = ""
a = 0
b = 0
e = 0
Call printt(a, b, e, 0)
End Sub
Sub check(temp As Long)
Dim d As Long
Randomize
d = Int(Rnd * 3 + 1)
If d = temp Then
e = e + 1
Call printt(a, b, e, d)
Else
Select Case d
Case 1
If temp = 2 Then
a = a + 1
Call printt(a, b, e, d)
ElseIf temp = 3 Then
b = b + 1
Call printt(a, b, e, d)
End If
Case 2
If temp = 1 Then
b = b + 1
Call printt(a, b, e, d)
ElseIf temp = 3 Then
a = a + 1
Call printt(a, b, e, d)
End If
Case 3
If temp = 1 Then
a = a + 1
Call printt(a, b, e, d)
ElseIf temp = 2 Then
b = b + 1
Call printt(a, b, e, d)
End If
End Select
End If
End Sub
Sub printt(temp1 As Long, temp2 As Long, temp3 As Long, temp4 As Long)
Label2.Caption = "电脑赢" & temp1 & "次," & "你赢" & temp2 & "次," & "平局" & temp3 & "次。"
Select Case temp4
Case 1
Label1.Caption = "石头"
Case 2
Label1.Caption = "剪刀"
Case 3
Label1.Caption = "布"
Case 0
Label1.Caption = "电脑还未出"
End Select
End Sub
1、建立三个按钮command1,command2,command3
2、建立两个标签label1,label2
3、复制代码,运行
Dim a As Long
Dim b As Long
Dim c As Long
Dim e As Long
Private Sub Command1_Click()
c = 1
Call check(c)
End Sub
Private Sub Command2_Click()
c = 2
Call check(c)
End Sub
Private Sub Command3_Click()
c = 3
Call check(c)
End Sub
Private Sub Form_Load()
Command1.Caption = "石头"
Command2.Caption = "剪刀"
Command3.Caption = "布"
Label1.Caption = ""
a = 0
b = 0
e = 0
Call printt(a, b, e, 0)
End Sub
Sub check(temp As Long)
Dim d As Long
Randomize
d = Int(Rnd * 3 + 1)
If d = temp Then
e = e + 1
Call printt(a, b, e, d)
Else
Select Case d
Case 1
If temp = 2 Then
a = a + 1
Call printt(a, b, e, d)
ElseIf temp = 3 Then
b = b + 1
Call printt(a, b, e, d)
End If
Case 2
If temp = 1 Then
b = b + 1
Call printt(a, b, e, d)
ElseIf temp = 3 Then
a = a + 1
Call printt(a, b, e, d)
End If
Case 3
If temp = 1 Then
a = a + 1
Call printt(a, b, e, d)
ElseIf temp = 2 Then
b = b + 1
Call printt(a, b, e, d)
End If
End Select
End If
End Sub
Sub printt(temp1 As Long, temp2 As Long, temp3 As Long, temp4 As Long)
Label2.Caption = "电脑赢" & temp1 & "次," & "你赢" & temp2 & "次," & "平局" & temp3 & "次。"
Select Case temp4
Case 1
Label1.Caption = "石头"
Case 2
Label1.Caption = "剪刀"
Case 3
Label1.Caption = "布"
Case 0
Label1.Caption = "电脑还未出"
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询