计算机vb小游戏,vb6做的游戏,用vb做简单小游戏代码,vb小游戏程序代码,vb游戏,vb怎么编写,vb有什么用:小游戏vb【VB编写小游戏】-南开游戏网...

小游戏vb【VB编写小游戏】

2020-11-20 05:12:57

广告

VB编写小游戏

窗体放两个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 "这局了"

您可能还会对下面的文章感兴趣:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值