vb怎么制作剪刀石头布游戏,按钮要有下拉菜单的和点击按钮可进入游戏说明,点击另一个按钮可进入游戏的 5
vb怎么制作剪刀石头布游戏,按钮要有下拉菜单的和点击按钮可进入游戏说明,点击另一个按钮可进入游戏的,求vb高手发下代码和制作图片,谢谢...
vb怎么制作剪刀石头布游戏,按钮要有下拉菜单的和点击按钮可进入游戏说明,点击另一个按钮可进入游戏的,求vb高手发下代码和制作图片,谢谢
展开
3个回答
展开全部
完整的工程在附件当中,请下载附件后查看。下面给出代码,不过不能直接用。需要对相应的控件设置属性值才能使用。具体内容,请打开附件中的"工程1.vbp"文件。
Option Explicit
Private Sub CmdOK_Click()
Dim computer As Integer
Dim player As Integer
player = 0
Randomize
If OptSelect(0).Value Then
Picture2.Picture = LoadPicture(App.Path & "\1.jpg") '石头
player = 1
End If
If OptSelect(1).Value Then
Picture2.Picture = LoadPicture(App.Path & "\2.jpg") '石头
player = 2
End If
If OptSelect(2).Value Then
Picture2.Picture = LoadPicture(App.Path & "\3.jpg") '石头
player = 3
End If
If player Then
computer = Int(3 * Rnd + 1) '产生一个1~3的随机数
Select Case computer
Case 1
Picture1.Picture = LoadPicture(App.Path & "\10.jpg") '电脑出石头
Case 2
Picture1.Picture = LoadPicture(App.Path & "\20.jpg") '电脑出剪刀
Case 3
Picture1.Picture = LoadPicture(App.Path & "\30.jpg") '电脑出布
End Select
ShowWinner Winner(computer, player)
Else
MsgBox "你还没选择手势!", vbOKOnly, "游戏提示"
End If
End Sub
Private Function ShowWinner(ByVal Winner As Integer)
Select Case Winner
Case 1
MsgBox "电脑胜!", vbOKOnly, "游戏提示"
Case 2
MsgBox "你赢了!", vbOKOnly, "游戏提示"
Case 3
MsgBox "平手!", vbOKOnly, "游戏提示"
End Select
Picture1.Picture = Nothing
Picture2.Picture = Nothing
Dim i As Integer
For i = 0 To 2
OptSelect(i).Value = False
Next i
End Function
'返回1表示P1胜出,返回2表示P2胜出,返回3表示平手
Private Function Winner(ByVal P1 As Integer, ByVal P2 As Integer) As Integer
Select Case P1
Case 1 '石头
Select Case P2
Case 1 '石头
Winner = 3
Case 2 '剪刀
Winner = 1
Case 3 '布
Winner = 2
End Select
Case 2 '剪刀
Select Case P2
Case 1 '石头
Winner = 2
Case 2 '剪刀
Winner = 3
Case 3 '布
Winner = 1
End Select
Case 3 '布
Select Case P2
Case 1 '石头
Winner = 1
Case 2 '剪刀
Winner = 2
Case 3 '布
Winner = 3
End Select
End Select
End Function
Private Sub Menu_Game_Exit_Click()
Unload Me
End Sub
Private Sub Menu_Game_Help_Click()
MsgBox "在单选框上点击石头、剪刀或布,然后点击确定按钮!" & Chr(13) & "温馨提示:电脑是随机出的。", vbOKOnly, "游戏说明"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询