VB小游戏石头剪刀布设置代码?

刚刚阅读1回复0
fayouxi
fayouxi
  • 管理员
  • 注册排名1
  • 经验值1024700
  • 级别管理员
  • 主题204940
  • 回复0
楼主

无图,请使用您自己的代码替代。

创建三个命令按钮,分别代表石头、剪刀和布。

在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
回帖 返回小游戏

VB小游戏石头剪刀布设置代码? 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息