2022年vb小游戏代码 .pdf

上传人:Che****ry 文档编号:35293617 上传时间:2022-08-21 格式:PDF 页数:13 大小:523.41KB
返回 下载 相关 举报
2022年vb小游戏代码 .pdf_第1页
第1页 / 共13页
2022年vb小游戏代码 .pdf_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《2022年vb小游戏代码 .pdf》由会员分享,可在线阅读,更多相关《2022年vb小游戏代码 .pdf(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、1 数字排序小游戏Option Explicit Dim Label2X As Integer 记录标签控件数组中要移动的标签控件左上角X 的位置Dim Label2Y As Integer 记录标签控件数组中要移动的标签控件左上角Y 的位置让标签数组中的每个标签控件上显示的数字是随机的,无重复的Private Sub Init() Randomize Dim a(7) As Integer Dim i As Integer, k As Integer Label1.Caption = For i = 0 To 7 a(i) = i Next For i = 0 To 7 k = Int(Rn

2、d * 8) Do While a(k) = -1 a(k)=-1 表示该数组元素对应的数字已经被使用过了k = Int(Rnd * 8) 重新生成 k 的值,直到a(k)的值不等于 -1 Loop Label2(i).Caption = Trim(Str(a(k) a(k) = -1 a(k)的值已经使用了,不能再用,重新赋值为-1 与其他的元素值相区别名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 13 页 - - - - - - - - - 2 Next i End

3、 Sub Private Sub Command1_Click() Dim x As Integer, y As Integer Dim z As Integer Init Picture1.Enabled = True 让空白标签Label1 出现的位置随机Randomize 记录下空白标签Label1 的位置x = Label1.Left y = Label1.Top z = Int(Rnd * 8) 将空白标签Label1 和标签控件数组任一控件交换位置Label1.Move Label2(z).Left, Label2(z).Top Label2(z).Move x, y Comman

4、d1.Enabled = False End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() Dim i As Integer Picture1.Enabled = False 在标签中显示游戏说明信息Label3.Caption = 如左图所示,将数字按0-7 顺 & vbCrLf & vbCrLf & 序依次排列,即取得胜利。 在标签中显示排列规则后的数字顺序Label1.Caption = 0 For i = 0 To 6 Label2(i).Caption = i + 1 Next End Sub

5、 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 13 页 - - - - - - - - - 3 Private Sub Label1_DragDrop(Source As Control, x As Single, y As Single) Dim Label1X As Integer 记录空白控件Label1 左上角 X 的位置Dim Label1Y As Integer 记录空白控件Label1 左上角 Y 的位置Dim flag(3) As Boolean 获取

6、空白控件Label1 的位置Label1X = Label1.Left Label1Y = Label1.Top 要移动的控件位于空白控件Label1 的正左侧flag(0) = (Label2X = Label1X - Source.Width) And (Label2Y = Label1Y) 要移动的控件位于空白控件Label1 的正右侧flag(1) = (Label2X = Label1X + Source.Width) And (Label2Y = Label1Y) 要移动的控件位于空白控件Label1 的正上方flag(2) = (Label2X = Label1X) And (L

7、abel2Y = Label1Y - Source.Height) 要移动的控件位于空白控件Label1 的正下方flag(3) = (Label2X = Label1X) And (Label2Y = Label1Y + Source.Height) If flag(0) Or flag(1) Or flag(2) Or flag(3) Then Label1.Move Label2X, Label2Y Source.Move Label1X, Label1Y End If Win End Sub Private Sub Label2_MouseDown(Index As Integer,

8、Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then 如果按下鼠标左键记录下要拖动控件的位置Label2X = Label2(Index).Left Label2Y = Label2(Index).Top Label2(Index).Drag 1 启动拖动操作End If End Sub Private Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Si

9、ngle, y As Single) Label2(Index).Drag 2 结束拖动操作名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 13 页 - - - - - - - - - 4 End Sub Private Sub Win() Dim winner As Integer Dim i As Integer Dim answer As Integer 对于给定的标签控件数组中的任一标签控件,可以落在符合要求(对应位置应显示对应数字)的八个位置中的任一位置利用循环

10、语句对标签控件数组中的每个标签控件进行检查,如果其落在某一符号要求的位置,则变量 winner 的值加 1,如果所有标签控件都落在符号要求的位置,则变量winner 的值应为 8 For i = 0 To 7 If Label2(i).Left = 0 And Label2(i).Top = 0 And _ Label2(i).Caption = 0 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 1 Then win

11、ner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 2 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 3 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Labe

12、l2(i).Top = Label2(i).Height And _ Label2(i).Caption = 4 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 5 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).C

13、aption = 6 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 7 Then winner = winner + 1 End If Next i If winner = 8 Then MsgBox 恭喜您,胜利了!, 0 + 64 + 0, 提示 Picture1.Enabled = False answer = MsgBox( 还继续吗? , 4 + 32 + 0, 提示

14、) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 13 页 - - - - - - - - - 5 If answer = vbYes Then Command1.Enabled = True Else End End If End If End Sub 弹球游戏Dim x_step As Integer Dim y_step As Integer Private Sub command1_Click() If Timer1.Enabled = True Then Ti

15、mer1.Enabled = False Else Timer1.Enabled = True End If If command1.Caption = 暂停 Then command1.Caption = 继续 Else command1.Caption = 暂停 End If End Sub 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 13 页 - - - - - - - - - 6 Private Sub Form_Load() x_step = 200 y_s

16、tep = 200 End Sub Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 37 Then If Line1.X1 Picture1.Width Then Line1.X1 = Picture1.Width - 2000: line2.X2 = Picture.Width Else Line1.X1 = Line1.X1 + 100: Line1.X2 = Line1.X2 + 100 End If End If End Sub Private Sub Timer1_Time

17、r() If Shape1.Top 0 Then Shape1.Top = 0: y_step = -y_step End If If Shape1.Left Picture1.Width - Shape1.Width Then Shape1.Left = Picture1.Width - Shape1.Width x_step = -x_step End If 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 13 页 - - - - - - - - - 7 If Sha

18、pe1.Left = Line1.X1 And Shape1.Left = Line1.Y1 - Shape1.Height Then Shape1.Top = Line1.Y1 - Shape1.Height y_step = -y_step * 1.01 x_step = x_step * 1.01 Label2.Caption = Label2.Caption + 1 End If Shape1.Top = Shape1.Top + y_step Shape1.Left = Shape1.Left + x_step If Shape1.Top = Picture1.Height - Sh

19、ape1.Height Then MsgBox 游戏结束 command1.Caption = 开始 Timer1.Enabled = False Shape1.Top = 1000 Label2.Caption = 0 End If End Sub 打字游戏Dim score As Integer 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 13 页 - - - - - - - - - 8 Dim speed As Integer Dim typetime As I

20、nteger Private Sub init() Randomize lblletter1.Caption = Chr(Int(Rnd * 42) + 48) lblletter1.Left = Int(Rnd * 2800) + 1 lblletter1.Top = 0 End Sub Private Sub init1() Randomize lblletter2.Caption = Chr(Int(Rnd * 25) + 97) lblletter2.Left = Int(Rnd * 2800) + 1 lblletter2.Top = 0 End Sub Private Sub Co

21、mmand1_Click() score = Int(lblscore.Text) init init1 Timer1 = True Timer2 = True HScroll1.Enabled = False Command1.Enabled = False Command2.Enabled = False HScroll1.Enabled = False If lbltime.Text = 0 Then Timer1 = False Timer2 = False lblletter1.Caption = lblletter2.Caption = End If End Sub Private

22、 Sub Command2_Click() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 13 页 - - - - - - - - - 9 typetime = InputBox( 请输入打字时间。, 时间设置 ) If typetime = 4335 Then Call init End If lblletter2.Top = lblletter2.Top + lblspeed.Caption If lblletter2.Top = 4335 Then Call in

23、it1 End If End Sub Private Sub Timer2_Timer() If lbltime.Text 0 Then lbltime.Text = lbltime.Text - 1 Else: Select Case score / (typetime / 60) Case Is 120 MsgBox ( 祝贺你!你已经是一个打字高手!) End Select Timer1 = False Timer2 = False HScroll1.Enabled = True Command1.Enabled = True Command2.Enabled = True HScrol

24、l1.Enabled = True init init1 End If End Sub 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 13 页 - - - - - - - - - 11 点灯游戏Private Sub Form_Load() Form1.Scale (0, 12)-(12, 0) For i = 1 To 11 Line (1, i)-(11, i) Line (i, 1)-(i, 11) Next i End Sub Sub fill_color(X

25、, Y) If Point(X, Y) = vbWhite Then Line (Int(X), Int(Y)-(Int(X + 1), Int(Y + 1), vbBlack, BF Else Line (Int(X), Int(Y)-(Int(X + 1), Int(Y + 1), vbWhite, BF End If End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If X = 1 And X = 1 And Y = 1 And X = 1

26、And Y + 1 = 1 And X = 1 And Y - 1 = 1 And X + 1 = 1 And Y = 1 And X - 1 = 1 And Y = 11 Then Call fill_color(X - 1, Y) End If End If Call Form_Load End Sub 猜数字Dim number As Integer Private Sub Command1_Click() Dim guess As Integer, diff As Integer guess = Val(Text1.Text) If guess = -1 Then MsgBox ( 要

27、猜的数是 & number) Text1.Text = Text1.SetFocus Exit Sub End If diff = Abs(number - guess) Select Case diff Case 0 MsgBox ( 恭喜你猜对了!) Case 2, Is 2 MsgBox ( 接近了,再努力!) Case 10, Is 12 MsgBox ( 有些远,再努力!) Case Else MsgBox ( 太远了,继续努力!) End Select Select Case diff Case Is 0 Text1.Text = Text1.SetFocus End Select

28、 End Sub Private Sub Form_Load() MsgBox ( 计算机产生了一个1100 之间的整数, & Chr(10) & 请您猜出这个数是多少。 & Chr(10) & 如果输入 -1,则停止猜数,并输出要猜的数。) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 13 页 - - - - - - - - - 13 number = Int(100 * Rnd) + 1 End Sub Private Sub Label1_Click() En

29、d Sub 猜笑脸Private Sub Command1_Click(Index As Integer) Dim a As Integer, i As Integer Randomize a = Int(Rnd * 4) Command1(a).Enabled = False Command1(a).DisabledPicture = LoadPicture(267.gif) If a = Index Then Label1.Caption = 你猜对啦,真棒! Else Label1.Caption = 你猜错啦,我在这哩! End If For i = 0 To 3 Command1(i

30、).Enabled = False Next i End Sub Private Sub Command2_Click() Dim i As Integer For i = 0 To 3 Command1(i).Enabled = True Command1(i).DisabledPicture = LoadPicture() Next i Label1.Caption = 猜猜我在哪儿? End Sub Private Sub Command3_Click() End End Sub 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 13 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁