⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applebug.vb

📁 Bug Game in Visual C++
💻 VB
字号:
Public MustInherit Class AppleBug
    Protected m_p As PictureBox
    Public MustOverride Function Create(ByVal left As Integer, ByVal top As Integer) As PictureBox
    Public MustOverride Function getObject() As PictureBox
    Public MustOverride Sub Destroy()

End Class

Public Class Bug
    Inherits AppleBug
    Public Overrides Function Create(ByVal left As Integer, ByVal top As Integer) As PictureBox
        m_p = New PictureBox
        m_p.Left = left
        m_p.Top = top
        m_p.ImageLocation = "bug.gif"
        m_p.SizeMode = PictureBoxSizeMode.AutoSize
        m_p.Visible = True
        Return m_p
    End Function
    Public Overrides Function getObject() As System.Windows.Forms.PictureBox
        Return m_p
    End Function
    Public Overrides Sub Destroy()
        m_p.Visible = False
        m_p.Dispose()
    End Sub

    Public Sub MoveTo(ByVal left As Integer, ByVal top As Integer)
        If m_p Is Nothing Then
            Create(left, top)
        Else
            m_p.Left = left
            m_p.Top = top
        End If
    End Sub
End Class

Public Class Apple
    Inherits AppleBug

    Public Overrides Function Create(ByVal left As Integer, ByVal top As Integer) As PictureBox
        m_p = New PictureBox
        m_p.Left = left
        m_p.Top = top
        m_p.ImageLocation = "apple.gif"
        m_p.SizeMode = PictureBoxSizeMode.AutoSize
        m_p.Visible = True
        Return m_p
    End Function
    Public Overrides Function getObject() As System.Windows.Forms.PictureBox
        Return m_p
    End Function
    Public Overrides Sub Destroy()
        m_p.Visible = False
        m_p.Dispose()
    End Sub
End Class

Public Class Utilities
    'initialize random number generator
    Private Shared _r As New Random(System.DateTime.Now.Millisecond)
    Public Shared Function RandomNumber(ByVal UpperRange As Integer, Optional ByVal LowerRange As Integer = 0) As Integer
        If LowerRange > UpperRange Then
            Dim t As Integer = LowerRange
            LowerRange = UpperRange
            UpperRange = t
        End If
        Return _r.Next(LowerRange, UpperRange)
    End Function

    Public Shared Function CheckOverlap(ByVal bug1 As Bug, ByVal apple1 As Apple) As Boolean
        If bug1.getObject().Left >= apple1.getObject().Left And _
                bug1.getObject().Top >= apple1.getObject().Top And _
                (bug1.getObject().Left + bug1.getObject().Width) <= (apple1.getObject().Left + apple1.getObject().Width) And _
                (bug1.getObject().Top + bug1.getObject().Height) <= (apple1.getObject().Top + apple1.getObject().Height) Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -