vb小游戏自己做

 时间:2026-02-13 12:43:30

1、打开vb6.0,如图设计Form1界面

Form1 的 BorderStyle属性设为3-……

Command1 为 开始游戏/重置

Command2 为 确定

Command3 为 退出

Command4 为 显示答案

Command5 为 清除数字

Command6 为 清空提示框

Text1至4 为 依次从左到右的4个输入框,设Font属性为宋体,加粗,四号

Text5 为 大提示框,Scrollbars属性设置为2-Vertical,MultiLine 属性为true

Label1 为 显示答案的提示框

vb小游戏自己做

2、添加Form2

Form1 的 BorderStyle属性设为3-……

Label1的Caption改为 请输入数字

             Font属性为宋体,加粗,一号

vb小游戏自己做

3、Form1中输入代码

Private Sub Command2_Click()

Dim h As Integer, j As Integer

h = 0

j = 0

If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then

Form2.Show

Else

Open "C:\Users\Administrator\Documents\游戏.txt" For Input As #1

d = Input(1, #1)

e = Input(1, #1)

f = Input(1, #1)

g = Input(1, #1)

If d <> Text1.Text Then

h = h

Else: h = h + 1

End If

If e <> Text2.Text Then

h = h

Else: h = h + 1

End If

If f <> Text3.Text Then

h = h

Else: h = h + 1

End If

If g <> Text4.Text Then

h = h

Else: h = h + 1

End If

If d = Text1.Text Or d = Text2.Text Or d = Text3.Text Or d = Text4.Text Then

j = j + 1

End If

If e = Text1.Text Or e = Text2.Text Or e = Text3.Text Or e = Text4.Text Then

j = j + 1

End If

If f = Text1.Text Or f = Text2.Text Or f = Text3.Text Or f = Text4.Text Then

j = j + 1

End If

If g = Text1.Text Or g = Text2.Text Or g = Text3.Text Or g = Text4.Text Then

j = j + 1

End If

Text5.Text = Text5.Text & "有" & h & "个位置对了," & "包含" & j & "个相同数字" & vbCrLf

End If

Close

End Sub

Private Sub Command3_Click()

End

End Sub

Private Sub Command1_Click()

Dim w As Integer

Dim x As Integer

Dim y As Integer

Dim z As Integer

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Label1 = ""

Text5.Text = ""

Dim b As String

a = a + 1

Randomize

If a = 0 Then

Command2.Enabled = False

Else

Command2.Enabled = True

End If

w = Int(Rnd() * 9 + 1)

x = Int(Rnd() * 9 + 1)

y = Int(Rnd() * 9 + 1)

z = Int(Rnd() * 9 + 1)

Do While w = x Or w = y Or w = z Or x = y Or x = z Or y = z

w = Int(Rnd() * 9 + 1)

x = Int(Rnd() * 9 + 1)

y = Int(Rnd() * 9 + 1)

z = Int(Rnd() * 9 + 1)

Loop

b = w * 1000 + x * 100 + y * 10 + z

Open "C:\Users\Administrator\Documents\游戏.txt" For Output As #1

Print #1, b

Close

End Sub

Private Sub Command4_Click()

Dim i As Single

Open "C:\Users\Administrator\Documents\游戏.txt" For Input As #1

i = Input(4, #1)

Label1 = i

Close

End Sub

Private Sub Command5_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

End Sub

Private Sub Command6_Click()

Label1 = ""

Text5.Text = ""

End Sub

Private Sub Form_Load()

Dim a As Integer

If a = 0 Then

Command2.Enabled = False

Else

Command2.Enabled = True

End If

End Sub

4、打开“文档”,新建txt文档,重命名“游戏”

  • vb的inputbox函数怎么用?玩转inputbox函数
  • 打开VB代码窗口的几种方法
  • VB入门教程:[21]显示日期
  • vb中array函数用法
  • vb组合框设计时怎么添加列表
  • 热门搜索
    鳄龟怎么养 老打嗝怎么办 微信红包怎么撤回 大便拉不出来怎么办 生了暴君反派的崽怎么破 显卡驱动怎么安装 罗汉果怎么泡水喝 宫颈糜烂是怎么引起的 我的世界胡萝卜怎么得 河蚌怎么养