VB编写小游戏

来自:    更新日期:早些时候
怎样用vb编写贪吃蛇游戏~

1、向上前进的时候,对代码进行一个详解。

2、向上前进时,x坐标不动,y坐标-1,如果下一个有食物 下一个位置的坐标和食物的坐标相同。把食物转化成蛇的身体。

3、如果蛇吃到了食物,就开始加速,并且食物的得分+2。

4、如果没有吃到食物,蛇可以正常往前走,恢复原来的方块。

5、向下前进时,x坐标不动,y坐标+1。

6、如果有食物就把食物转化为身体。


7、如果没有吃到食物,蛇可以正常往前走,恢复原来的方块。

Private Sub Command0_Click()
Dim x As String
x = "●"
If Command2.Caption = x Then
Command2.Caption = "○"
Else
Command2.Caption = "●"
End If
If Command4.Caption = x Then
Command4.Caption = "○"
Else
Command4.Caption = "●"
End If
If Command6.Caption = x Then
Command6.Caption = "○"
Else
Command6.Caption = "●"
End If
If Command8.Caption = x Then
Command8.Caption = "○"
Else
Command8.Caption = "●"
End If
End Sub
Private Sub Command1_Click()
Dim x As String
x = "●"
If Command8.Caption = x Then
Command8.Caption = "○"
Else
Command8.Caption = "●"
End If
If Command2.Caption = x Then
Command2.Caption = "○"
Else
Command2.Caption = "●"
End If
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
End Sub
Private Sub Command2_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command1.Caption = x Then
Command1.Caption = "○"
Else
Command1.Caption = "●"
End If
If Command3.Caption = x Then
Command3.Caption = "○"
Else
Command3.Caption = "●"
End If
End Sub
Private Sub Command3_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command2.Caption = x Then
Command2.Caption = "○"
Else
Command2.Caption = "●"
End If
If Command4.Caption = x Then
Command4.Caption = "○"
Else
Command4.Caption = "●"
End If
End Sub
Private Sub Command4_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command3.Caption = x Then
Command3.Caption = "○"
Else
Command3.Caption = "●"
End If
If Command5.Caption = x Then
Command5.Caption = "○"
Else
Command5.Caption = "●"
End If
End Sub
Private Sub Command5_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command4.Caption = x Then
Command4.Caption = "○"
Else
Command4.Caption = "●"
End If
If Command6.Caption = x Then
Command6.Caption = "○"
Else
Command6.Caption = "●"
End If
End Sub
Private Sub Command6_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command5.Caption = x Then
Command5.Caption = "○"
Else
Command5.Caption = "●"
End If
If Command7.Caption = x Then
Command7.Caption = "○"
Else
Command7.Caption = "●"
End If
End Sub
Private Sub Command7_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command6.Caption = x Then
Command6.Caption = "○"
Else
Command6.Caption = "●"
End If
If Command8.Caption = x Then
Command8.Caption = "○"
Else
Command8.Caption = "●"
End If
End Sub
Private Sub Command8_Click()
Dim x As String
x = "●"
If Command0.Caption = x Then
Command0.Caption = "○"
Else
Command0.Caption = "●"
End If
If Command7.Caption = x Then
Command7.Caption = "○"
Else
Command7.Caption = "●"
End If
If Command1.Caption = x Then
Command1.Caption = "○"
Else
Command1.Caption = "●"
End If
End Sub
Private Sub yun_Click()
If Command0.Caption = x & Command1.Caption = x And Command2.Caption = x And Command3.Caption = x And Command4.Caption = x And Command5.Caption = x And Command6.Caption = x And Command7.Caption = x And Command8.Caption = x Then
Label2.Caption = "成功了~~~~!!!祝贺啊!!!"
Else
Label2.Caption = "又没完成!乱点个嘛啊。。"
End If
End Sub

窗体放两个Label控件,一个Timer控件:
Dim n As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
If Label1.Top > 0 Then Label1.Top = Label1.Top - 50
Case vbKeyDown
If Label1.Top < ScaleHeight - Label1.Height Then Label1.Top = Label1.Top + 50
Case vbKeyLeft
If Label1.Left > 0 Then Label1.Left = Label1.Left - 50
Case vbKeyRight
If Label1.Left < ScaleWidth - Label1.Width Then Label1.Left = Label1.Left + 50
End Select
Call check
End Sub
Private Sub check()
If Abs(Label1.Top - Label2.Top) <= 50 And Abs(Label1.Left - Label2.Left) <= 50 Then
n = n + 1
Label2.Move Rnd * ScaleWidth, Rnd * ScaleHeight
End If
End Sub
Private Sub Form_Load()
KeyPreview = True
Randomize
With Label1
.Caption = ""
.BackColor = vbWhite
.Move (ScaleWidth - .Width) / 2, (ScaleHeight - .Height) / 2, 500, 500
End With
With Label2
.Caption = ""
.BackColor = vbYellow
.Move Rnd * ScaleWidth, Rnd * ScaleHeight, 500, 500
End With
Timer1.Interval = 60000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
MsgBox "这局对准了" & n & "次黄方块"
Unload Me
End Sub


VB编写小游戏视频

相关评论:
  • 17262041650VB制作小游戏源代码
    袁詹新猜数字 建一个文本文档,输入以下代码,后缀改为.frm用vb打开就可以了 以下是程序源码:VERSION 5.00 Begin VB.Form Form1 BorderStyle = 3 'Fixed Dialog Caption = "猜数游戏"ClientHeight = 3900 ClientLeft = 45 ClientTop = 435 ClientWidth = 4680 ...

  • 17262041650求一个VB小游戏编程,要有代码的。。
    袁詹新Set Timer1 = Controls.Add("VB.Timer", "Timer1")Set Label1 = Controls.Add("VB.Label", "Label1")Label1.AutoSize = True Label1.BackStyle = 0 Label1 = "暂停"Label1.ForeColor = RGB(255, 255, 0)Label1.FontSize = 50 ChuShiHua End Sub Private Sub Form_Resize()On Error...

  • 17262041650谁能帮我做一份VB6.0作业,内容为小游戏,最好是自己写的,代码要稍微多一...
    袁詹新很简单,做一个打地鼠的游戏,放9个按钮,然后int(RND*10)select case判断,然后command.enable=1,然后当点击command.enable=0,需要有个Timer控件,用来设定打地鼠的延迟,如果你为了更好一下,你可以收集一些图片的素材,然后给按钮设置

  • 17262041650vb制作, 我用vb制作了一个小游戏 打怪升级类
    袁詹新'插入3个text,一个command Private Sub form_load()Text1.Text = "1000" '血量 Text2.Text = "500" '魔 Text3.Text = "400" '对手 End Sub Private Sub command1_click()If Text1.Text = "0" Or Text2.Text = "0" Then MsgBox "无法攻击!"Else:Do Text1.Text = Text1.Text ...

  • 17262041650急!求高手制作VB连连看小游戏
    袁詹新4、每次通关或者game over记录分数和用户名到文件,查看排行榜时调出文件把分数做从大到小排列,然后显示用户名,就成排行榜了。5、难度体现在图标的个数、限制时间的长短等 6、两个图标能否消除的判断在于:是否相同图案、连线中间是否有其它图标隔着。以上思路希望给你启发,自娱自乐够了,要做高端游...

  • 17262041650用VB制作个小游戏。急急急急急~!!!马上就要交了,随便什么都行,简单的小...
    袁詹新我是个初学者,期末要交个用VB制作简单的小游戏,拜托先将完整代码写出来,下面再补充说明代码中的步骤注意事项,例如要设置的窗口,按键等,请不要将属性设置也写进代码中!(最好我... 我是个初学者,期末要交个用VB制作简单的小游戏,拜托先将完整代码写出来,下面再补充说明代码中的步骤注意事项,例如要设置的窗口,...

  • 17262041650我想用VB和3DSMAX一起做一个简单的3D小游戏,请问怎么做?
    袁詹新Mesh.SetPosition 0, 0, 10 'Z越小,图像越大 Form1.Show Do '开始进入游戏循环 DoEvents '用DoEvents函数,让Windows空出来作别的事 TV.Clear '清除缓冲区的内容 Mesh.Render '渲染Mesh(3D物件)TV.RenderToScreen '把缓冲区的内容渲染到屏幕上 Loop Until InputE.IsKeyPressed(TV_KEY_ESCAPE)...

  • 17262041650怎么用vb制作俄罗斯方块游戏啊,简单点的。
    袁詹新我们这个小游戏也可以用C语言来实现,在程序的编程上没有VB语言方便实用,C语言和VB语言之间存在很多的共同点,虽然语法方面有点差异,但是在编程思路上完全一样,VB能够实现很多C#不能做到的功能,如When语句、Optional参数、局部Static变量、对象实例访问静态方法、Handles绑定事件、On Error处理异常、Object直接后期绑定等等...

  • 17262041650如何用VB程序设计打地鼠游戏
    袁詹新X = MsgBox("是否真的退出?", vbYesNo, "退出游戏框")If X = 6 Then tt = MsgBox("退出游戏之前,是否保存", vbYesNo, "保存提示") If tt = 6 Then If flags1 = True Then End Else If Timer1.Interval = 1000 Then Open "C:\\Users\\Administrator\\Desktop\\打地鼠\\primary...

  • 17262041650VB可以做什么游戏
    袁詹新开发游戏你需要解决四个技术问题:1:图像绘制。2:声音播放。3:用户输入控制。4:文件的读写。其中2、3、4基本可以用VB的基础语言功能和操作系统提供的API解决,唯独绘图需要引擎来解决。除非是很小的小游戏,否则你不太可能用系统控件去做一个游戏,你也不能天才到啥都自己实现出来,你就算有那么...

  • 相关主题精彩

    版权声明:本网站为非赢利性站点,内容来自于网络投稿和网络,若有相关事宜,请联系管理员

    Copyright © 喜物网