多语言展示
当前在线:1863今日阅读:84今日分享:32

vb小游戏自己做

这款猜数字小游戏的游戏规则:点击“开始游戏/重置”随机生成四位数(各位上的数互不相同),在四个输入框中输入你猜的数字,点击“确定”,会显示提示,根据提示继续奋斗吧!
工具/原料
1

电脑

2

vb6.0

方法/步骤
1

打开vb6.0,如图设计Form1界面Form1 的 BorderStyle属性设为3-……Command1 为 开始游戏/重置Command2 为 确定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 Integerh = 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文档,重命名“游戏”

注意事项

一定要新建txt文档

推荐信息