用VB编写一个人与电脑玩剪刀布锤的游戏
编一个程序,让计算机和人一起玩剪刀,锤,布游戏。如果人输了。就输出“LOSE";人赢了,就输出“WIN”;人与计算机平了,就输出“DEUCE".在FORM窗体上建一个La...
编一个程序,让计算机和人一起玩剪刀,锤,布游戏。如果人输了。就输出“LOSE"; 人赢了,就输出“WIN”;人与计算机平了,就输出“DEUCE".在FORM窗体上建一个Label,capion为开始游戏 在建一个Text 在Text
里输入要出的一种 展开
里输入要出的一种 展开
3个回答
展开全部
'在窗体上添加3个按钮,分别代表石头剪子布,加一个Label,添加代码就好了
'1为石头,2为剪刀,3为布
Private Sub Command1_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "DEUCE"
ElseIf computer = 2 Then
Label1.Caption = "WIN"
ElseIf computer = 3 Then
Label1.Caption = "LOSE"
End If
End Sub
Private Sub Command2_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "LOSE"
ElseIf computer = 2 Then
Label1.Caption = "DEUCE"
ElseIf computer = 3 Then
Label1.Caption = "WIN"
End If
End Sub
Private Sub Command3_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "WIN"
ElseIf computer = 2 Then
Label1.Caption = "LOSE"
ElseIf computer = 3 Then
Label1.Caption = "DEUCE"
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "石头"
Command2.Caption = "剪刀"
Command3.Caption = "布"
Label1.Caption = "猜拳"
End Sub
'1为石头,2为剪刀,3为布
Private Sub Command1_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "DEUCE"
ElseIf computer = 2 Then
Label1.Caption = "WIN"
ElseIf computer = 3 Then
Label1.Caption = "LOSE"
End If
End Sub
Private Sub Command2_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "LOSE"
ElseIf computer = 2 Then
Label1.Caption = "DEUCE"
ElseIf computer = 3 Then
Label1.Caption = "WIN"
End If
End Sub
Private Sub Command3_Click()
Randomize
Dim computer As Long
computer = Int(Rnd() * 3) + 1
If computer = 1 Then
Label1.Caption = "WIN"
ElseIf computer = 2 Then
Label1.Caption = "LOSE"
ElseIf computer = 3 Then
Label1.Caption = "DEUCE"
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "石头"
Command2.Caption = "剪刀"
Command3.Caption = "布"
Label1.Caption = "猜拳"
End Sub
展开全部
Private Sub Form_Load()
Label1.FontSize = 18
Label1.FontBold = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim JiQi As Integer
Label1.Caption = ""
If KeyAscii = 13 Then
If Text1.Text = "剪刀" Or Text1.Text = "石头" Or Text1.Text = "布" Then
Randomize
JiQi = Int(Rnd * 3 + 1)
Label2.Caption = (JiQi)
If (JiQi) = 1 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "DEUCE"
ElseIf Text1.Text = "布" Then
Label1.Caption = "LOSE"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "WIN"
End If
ElseIf (JiQi) = 2 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "LOSE"
ElseIf Text1.Text = "布" Then
Label1.Caption = "WIN"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "DEUCE"
End If
ElseIf (JiQi) = 3 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "WIN"
ElseIf Text1.Text = "布" Then
Label1.Caption = "DEUCE"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "LOSE"
End If
End If
End If
End If
End Sub
Label1.FontSize = 18
Label1.FontBold = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim JiQi As Integer
Label1.Caption = ""
If KeyAscii = 13 Then
If Text1.Text = "剪刀" Or Text1.Text = "石头" Or Text1.Text = "布" Then
Randomize
JiQi = Int(Rnd * 3 + 1)
Label2.Caption = (JiQi)
If (JiQi) = 1 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "DEUCE"
ElseIf Text1.Text = "布" Then
Label1.Caption = "LOSE"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "WIN"
End If
ElseIf (JiQi) = 2 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "LOSE"
ElseIf Text1.Text = "布" Then
Label1.Caption = "WIN"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "DEUCE"
End If
ElseIf (JiQi) = 3 Then
If Text1.Text = "剪刀" Then
Label1.Caption = "WIN"
ElseIf Text1.Text = "布" Then
Label1.Caption = "DEUCE"
ElseIf Text1.Text = "石头" Then
Label1.Caption = "LOSE"
End If
End If
End If
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
srand(time(0));
这个只需要运行一次就行了,放在循环体前边就行了
这个只需要运行一次就行了,放在循环体前边就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询