當前位置:編程學習大全網 - 網站源碼 - VB編寫小遊戲

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 "這局對準了" & n & "次黃方塊"

Unload Me

End Sub

  • 上一篇:請各位彩票高手幫忙組個三組生日的號碼 福彩雙色球的謝了
  • 下一篇:求基於RLS算法和LMS的自適應濾波器的MATLAB程序``
  • copyright 2024編程學習大全網