怎么下vb游戏
Ⅰ VB编写小游戏的全过程谁告诉我
开始学vb时,并不知道vb可以做出动画,后来知道通过自编的子函数delay(c的库函数中的该函数)和cls可以做出许多动画,但有一个缺点就是太耗内存,就我个人认为构思应该比编程重要,因为一旦有了一个很好的构思剩下的问题都是技术问题,而我就是喜欢发现新的问题然后再想方设法解决它,通过发现问题和解决问题我可以学到许多很有用的知识和技巧。好了,现在有了一个好的构思就开始进入程序的编制。
第一步,要做成这个游戏的话必须能使小球有一个判断性的运动,然而如何处理小球的运动呢,很显然delay&cls的方法不再适用,因为整个程序运行时不停的清屏效果将很差,所以我想到了用shape控件来替代用circle命令画的小球,接着要使小球运动起来,这个问题很简单,因为 shape控件有left和top的属性,可以通过对这两个属性的控制可以很轻松的解决小球运动问题。
第二步,将对小球进行角度控制,角度可以通过shape的属性left和top来反映,通过timer控件使小球的left和top值不断加上一个值或减去一个值,小球的left和top同时改变之后就可以对小球的角度进行控制。到这里已经可以使小球运动起来,接下来的问题就是使小球能进行判断性运动。
第三步,可以这样对小球进行判断性控制,当小球的left大于窗体的scaleleft时小球的left改变成减去一个值,以此类推,小球的高度也可以进行类似的控制,现在已经很方便的对小球进行判断性运动,到这一步程序已经算是完成了一半。
第四步,既然小球可以自由的运动了,那就可以产生这样一个想法,当小球的top和left的砖块的top和left值接近到一定的范围的条件成立时使砖块的visible为false,然后小球的top和left加上接触前相应相反的值,就可以使砖块消失同时小球改变运动轨迹,这一步的实现需要解决很多技术性问题,可以在form的load事件里定义两个变量Dwd和Dhd以及两个Boolean量为Dw和Dh,通过Dwd和Dhd来控制小球向左和向上运动,当小球和窗体的边界或和砖块的的边界接触时使Dw和Dh的值进行相应的变化,通过对该两个值的控制可以使小球进行合乎反弹角度的运动,现在程序已经初步成型。
第五步,要做成这样的一个游戏,必须有一个良好的用户界面,为了使小球能接受用户的控制,我在窗体的下边界放置了一个命令按钮,该命令按钮可以通过方向键来控制,然后再加上一些判断语句使得小球command接触时产生相应的运动,这样一个用户界面就解决了。
第六步,现在只剩下程序的最后一步,就是生成砖块的排列,砖块可以用命令按钮来替代,然后用循环语句将设置好的command控件数组在程序运行时加载进来,好了,现在已经一切完成.
Ⅱ 如何设计一个很简单的VB程序小游戏
利用vb控件做个坦克大战类的游戏即可,炮弹和坦克都用控件实现就行。唯一难点是控制控件移动以及炮弹击中目标的碰撞检测判断。给你一个简单实现代码
这是一种碰撞检测方法,下述属于简化的矩形碰撞检测,若是需要复杂碰撞可以用一个数组来记录大量需要碰撞检测的物体
image1里读念则谨入坦克的图片
image2里读入地雷的图片
然后用下面代码即可实现
Private
Sub
Form_KeyPress(KeyAscii
As
Integer)
'按键盘A和D键控制猫图片image1左盯唤右移动
If
KeyAscii
=
97
Then
Image1.Left
=
Image1.Left
-
10
If
KeyAscii
=
100
Then
Image1.Left
=
Image1.Left
+
10
'如果坦克图片与地雷图片相遇则提示碰撞到了
If
Image1.Left
+
Image1.Width
>
Image2.Left
Then
If
Image1.Left
<
Image2.Left
+
Image2.Width
Then
If
Image1.Top
+
Image1.Height
>
Image2.Top
Then
If
Image1.Top
<
Image2.Top
+
Image2.Height
Then
MsgBox
"坦克碰到地雷,已经被炸毁了"仔基
End
If
End
If
End
If
End
If
End
Sub
Ⅲ 求VB小游戏,简单一点,越简单越好
数字排序小游戏
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(Rnd * 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与其他的元素值相区别
Next i
End 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
Command1.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
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
'获取空白控件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 (Label2Y = 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, 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 Single, y As Single)
Label2(Index).Drag 2 '结束拖动操作
End Sub
Private Sub Win()
Dim winner As Integer
Dim i As Integer
Dim answer As Integer
'对于给定的标签控件数组中的任一标签控件,可以落在符合要求(对应位置应显示对应数字)
'的八个位置中的任一位置
'利用循环语句对标签控件数组中的每个标签控件进行检查,如果其落在某一符号要求的位置,
'则变量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
winner = 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 Label2(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).Caption = 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, "提示")
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
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
If command1.Caption = "暂停" Then
command1.Caption = "继续"
Else
command1.Caption = "暂停"
End If
End Sub
Private Sub Form_Load()
x_step = 200
y_step = 200
End Sub
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
If Line1.X1 < 0 Then
Line1.X1 = 0: Line1.X2 = 2000
Else
Line1.X1 = Line1.X1 - 100: Line1.X2 = Line1.X2 - 100
End If
End If
If KeyCode = 39 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_Timer()
If Shape1.Top < 0 Then
Shape1.Top = 0: y_step = -y_step
End If
If Shape1.Left < 0 Then
Shape1.Left = 0
x_step = -x_step
End If
If Shape1.Left > Picture1.Width - Shape1.Width Then
Shape1.Left = Picture1.Width - Shape1.Width
x_step = -x_step
End If
If Shape1.Left >= Line1.X1 And Shape1.Left <= Line1.X2 And Shape1.Top >= 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 - Shape1.Height Then
MsgBox "游戏结束"
command1.Caption = "开始"
Timer1.Enabled = False
Shape1.Top = 1000
Label2.Caption = 0
End If
End Sub
打字游戏
Dim score As Integer
Dim speed As Integer
Dim typetime As Integer
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 Command1_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 Sub Command2_Click()
typetime = InputBox("请输入打字时间。", "时间设置")
If typetime <= 0 Then
lbltime.Text = 60
End If
lbltime.Text = typetime
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = lblletter1.Caption Then
score = score + 1
lblscore.Text = score
init
End If
If Chr(KeyAscii) = lblletter2.Caption Then
score = score + 1
lblscore.Text = score
init1
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
lblletter1.AutoSize = True
lblletter2.AutoSize = True
lblletter1.Caption = ""
lblletter2.Caption = ""
lblscore.Text = 0
lblspeed.Caption = 100
lbltime.Text = 60
HScroll1.Max = 200
HScroll1.Min = 20
HScroll1.SmallChange = 5
HScroll1.LargeChange = 20
HScroll1.Value = 100
End Sub
Private Sub HScroll1_Change()
lblspeed.Caption = HScroll1.Value
End Sub
Private Sub Timer1_Timer()
lblletter1.Top = lblletter1.Top + lblspeed.Caption
If lblletter1.Top >= 4335 Then
Call init
End If
lblletter2.Top = lblletter2.Top + lblspeed.Caption
If lblletter2.Top >= 4335 Then
Call init1
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 <= 40
MsgBox ("不要放弃再试一次!")
Case 40 To 80
MsgBox ("太棒了,继续努力!")
Case 80 To 120
MsgBox ("坚持下去,你将成为一个打字高手!")
Case Is > 120
MsgBox ("祝贺你!你已经是一个打字高手!")
End Select
Timer1 = False
Timer2 = False
HScroll1.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
HScroll1.Enabled = True
init
init1
End If
End Sub
点灯游戏
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, 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 <= 11 And Y >= 1 And Y <= 11 Then
Call fill_color(X, Y)
If X >= 1 And X <= 11 And Y + 1 >= 1 And Y + 1 <= 11 Then
Call fill_color(X, Y + 1)
End If
If X >= 1 And X <= 11 And Y - 1 >= 1 And Y - 1 <= 11 Then
Call fill_color(X, Y - 1)
End If
If X + 1 >= 1 And X + 1 <= 11 And Y >= 1 And Y <= 11 Then
Call fill_color(X + 1, Y)
End If
If X - 1 >= 1 And X - 1 <= 11 And Y >= 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 ("要猜的数是" & 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
End Sub
Private Sub Form_Load()
MsgBox ("计算机产生了一个1~100之间的整数," & Chr(10) & "请您猜出这个数是多少。" & Chr(10) & "如果输入-1,则停止猜数,并输出要猜的数。")
number = Int(100 * Rnd) + 1
End Sub
Private Sub Label1_Click()
End 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).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
Ⅳ vb小游戏源代码
Rem 窗体创建三个单选框按钮,Option1、Option2、Option3。
小游戏是一个较模糊的概念,它是相对于体积庞大的单机游戏及网络游戏而言的,泛指所有体积较小、玩法简单的游戏,通常这类游戏以休闲益智类为主,有单机版有网页版,在网页上嵌入的多为FLASH格式。
当下小游戏主要是指在线玩的flash版本游戏,统称小游戏,其实小游戏还包含单机游戏,小型游戏机等。一般游戏大小小于10m的游戏都统称为小游戏,一些街机类小游戏。因其游戏安装简便,耐玩性强,无依赖性而广受白领及小朋友的喜爱。
小游戏”这个词的型含义其实很简单,它不是一些大的游戏,不必花费更多的时间和精力。
小游戏是原始的游戏娱乐方式,小游戏本身是为了叫人们在工作,学习后的一种娱乐、休闲的一种方式,不是为了叫玩家为之花费金钱、花费精力,更不是叫玩家为他痴迷。
小游戏也可以理解为“Flash游戏”,是以SWF为后缀的游戏的总称.这些游戏是通过Flash软件和 Flash 编程语言 Flash ActionScript 制作而成。
由于Flash是矢量软件,所以小游戏放大后几乎不影响画面效果。Flash小游戏是一种新兴起的游戏形式,以游戏简单,操作方便,绿色,无需安装,文件体积小等优点渐渐被广大网友喜爱。