vb小游戏自己做
1、打开vb6.0,如图设计Form1界面Form1 的 BorderStyle属性设为3-……Command1 为开始游戏/重置C泠贾高框ommand2 为 确定Command3 为 退出Command4 为 显示答案Command5 为 清除数字Command6 为 清空提示框Text1至4 为 依次从左到右的4个输入框,设Font属性为宋体,加粗,四号Text5 为 大提示框,Scrollbars属性设置为2-Vertical,MultiLine 属性为trueLabel1 为 显示答案的提示框
2、添加Form2Form1 的 BorderStyle属性设为3-……Label1的Caption改为 请输入数字 Font属性为宋体,加粗,一号
3、Form1中输入代码Private Sub Command2_Click()Dim h As Integer, j As Int髫潋啜缅egerh = 0j = 0If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" ThenForm2.ShowElseOpen "C:\Users\Administrator\Documents\游戏.txt" For Input As #1d = Input(1, #1)e = Input(1, #1)f = Input(1, #1)g = Input(1, #1)If d <> Text1.Text Thenh = hElse: h = h + 1End IfIf e <> Text2.Text Thenh = hElse: h = h + 1End IfIf f <> Text3.Text Thenh = hElse: h = h + 1End IfIf g <> Text4.Text Thenh = hElse: h = h + 1End IfIf d = Text1.Text Or d = Text2.Text Or d = Text3.Text Or d = Text4.Text Thenj = j + 1End IfIf e = Text1.Text Or e = Text2.Text Or e = Text3.Text Or e = Text4.Text Thenj = j + 1End IfIf f = Text1.Text Or f = Text2.Text Or f = Text3.Text Or f = Text4.Text Thenj = j + 1End IfIf g = Text1.Text Or g = Text2.Text Or g = Text3.Text Or g = Text4.Text Thenj = j + 1End IfText5.Text = Text5.Text & "有" & h & "个位置对了," & "包含" & j & "个相同数字" & vbCrLfEnd IfCloseEnd SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Command1_Click()Dim w As IntegerDim x As IntegerDim y As IntegerDim z As IntegerText1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Label1 = ""Text5.Text = ""Dim b As Stringa = a + 1RandomizeIf a = 0 ThenCommand2.Enabled = FalseElseCommand2.Enabled = TrueEnd Ifw = 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 = zw = Int(Rnd() * 9 + 1)x = Int(Rnd() * 9 + 1)y = Int(Rnd() * 9 + 1)z = Int(Rnd() * 9 + 1)Loopb = w * 1000 + x * 100 + y * 10 + zOpen "C:\Users\Administrator\Documents\游戏.txt" For Output As #1Print #1, bCloseEnd SubPrivate Sub Command4_Click()Dim i As SingleOpen "C:\Users\Administrator\Documents\游戏.txt" For Input As #1i = Input(4, #1)Label1 = iCloseEnd SubPrivate Sub Command5_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Command6_Click()Label1 = ""Text5.Text = ""End SubPrivate Sub Form_Load()Dim a As IntegerIf a = 0 ThenCommand2.Enabled = FalseElseCommand2.Enabled = TrueEnd IfEnd Sub
4、打开“文档”,新建txt文档,重命名“游戏”