无图,请使用您自己的代码替代。
创建三个命令按钮,分别代表石头、剪刀和布。
在Form_Load中,将这三个命令按钮名称更改为:
Command1.Caption = "石头" Command2.Caption = "剪刀" Command3.Caption = "布"
私有Sub Command1_Click()函数:
Dim CPU As Integer Dim a As String CPU = Int(Rnd * 3) + 1 ``` 将CPU值更改为大于0小于1之间的随机数,这里是生成1-3的随机数。
If CPU = 1 Then a = "石头,平局" ```
如果CPU为1,则弹出提示框:"玩家出石头,电脑出"
If CPU = 2 Then a = "剪刀,玩家赢" ``` 如果CPU为2,则弹出提示框:"玩家出剪刀,电脑出"
If CPU = 3 Then a = "布,玩家赢" ```
如果CPU为3,则弹出提示框:"玩家出布,电脑出"
Private Sub Command1_Click()
Dim CPU As Integer Dim a As String CPU = Int(Rnd * 3) + 1 ```
If CPU = 1 Then a = "石头,电脑赢" ```
If CPU = 2 Then a = "剪刀,平局" ```
If CPU = 3 Then a = "布,玩家赢" ```
MsgBox "玩家出石头,电脑出" & a ```
Private Sub Command2_Click()
Dim CPU As Integer Dim a As String CPU = Int(Rnd * 3) + 1 ```
If CPU = 1 Then a = "石头,玩家赢" ```
If CPU = 2 Then a = "剪刀,平局" ```
If CPU = 3 Then a = "布,电脑赢" ```
MsgBox "玩家出剪刀,电脑出" & a ```
Private Sub Command3_Click()
Dim CPU As Integer Dim a As String CPU = Int(Rnd * 3) + 1 ```
If CPU = 1 Then a = "石头,玩家赢" ```
If CPU = 2 Then a = "剪刀,电脑赢" ```
If CPU = 3 Then a = "布,平局" ```
MsgBox "玩家出布,电脑出" & a ```
``vbnet
``
0