Lc_KiT : 個人主頁 - 相簿 - 訂閱  [ QOOZA - 論壇 - 登入 ]
406 - Not Acceptable
 
2011 年 10 月 13 日  星期四 2011-10-13 09:14 PM


[VB2010]常玩的, 接水果遊戲, Full Code, Cheap版
Public Class MainFrm
    'Background Controls
    Friend WithEvents tmr As New Timer

    'Data
    Public gScore As Double = 0

    Private FallingObjs As New List(Of PictureBox)
    Private HandledObjs As New List(Of PictureBox) 'storing which obj has arrived the line. And remove them.
    'But in this demo, it's no need to use it as there will be only one object arrived the goal in a single detection.
    'Unless, you give each objects a different velocity or acceleration.

    Private Sub Project_OnLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initialize the Timer
        tmr.Interval = 120 'It indicates the falling speed of all objects.
        tmr.Enabled = False

    'Initialize Setting - These code will be generated by VB.Net.

    'You may create these three controls yourself.
    'Friend WithEvents pnlObjContainer As New Panel
    'Friend WithEvents pnlHandlingLine As New Panel
    'Friend WithEvents picPicker As New PictureBox

    'And discomment the code below
    'Me.BackColor = System.Drawing.Color.White
    'Me.KeyPreview = True

    'pnlObjContainer.BorderStyle = BorderStyle.FixedSingle
    'pnlObjContainer.Size = New Size(700, 600)
    'Me.Controls.Add(pnlObjContainer)

    'pnlHandlingLine.Location = New Point(0, 500)
    'pnlHandlingLine.Size = New Size(700, 100)
    'pnlHandlingLine.BackColor = Color.Transparent
    'pnlObjContainer.Controls.Add(pnlHandlingLine)

    'picPicker.BackColor = Color.Black
    'picPicker.Size = New Size(100, 82)
    'picPicker.Location = New Point(300, 0)
    'pnlHandlingLine.Controls.Add(picPicker)

    End Sub

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
        'Handling Form.KeyDown of Command-Keys including arrow keys.
        Select Case keyData
            Case Keys.Left
                If picPicker.Left > 0 Then picPicker.Left -= 20 'Move the objPicker
            Case Keys.Right
                If picPicker.Left < 600 Then picPicker.Left += 20 'Move the objPicker
        End Select
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click
        If tmr.Enabled Then 'If (True) Then
            tmr.Stop()
            sender.text = "Start"
        Else
            tmr.Start()
            sender.text = "Stop"
        End If
    End Sub

    Private Sub FallingCheck(ByVal sender As Timer, ByVal e As System.EventArgs) Handles tmr.Tick
        For Each Obj As PictureBox In FallingObjs
            Obj.Top += 8 'Falling velocity

            'Check
            If Obj.Top > pnlHandlingLine.Top Then 'If the object has 
                'Marking
                Dim Pos As UShort = Obj.Left + (Obj.Width / 2)
                If (Pos > picPicker.Left) And (Pos < (picPicker.Left + picPicker.Width)) Then 'Detect the 
                    gScore += 2
                Else
                    gScore -= 1
                End If

                'Display Mark
                lbScoreDisplay.Text = gScore

                'Ready to remove the object
                HandledObjs.Add(Obj)
            End If
        Next

        'Remove Handled Objects
        For Each Obj As PictureBox In HandledObjs
            FallingObjs.Remove(Obj)
            Obj.Dispose()
            'Memory Manage
            GC.Collect(GC.GetGeneration(Obj))
        Next
        HandledObjs.Clear()

        'If FillingObjs.Count > 30 Then Return 'Exit Sub 'Limit the number of FallingObject to advoid hanging.

        Randomize()
        Select Case Rnd()
            Case Is < 0.1 '1% Do this

                Dim nwFallingObj As New PictureBox
                With nwFallingObj
                    '.ImageLocation = "/img/fobj" & Fix(Rnd * 10) & ".png" '
                    '.SizeMode = PictureBoxSizeMode.AutoSize

                    'REM this two lines if you have images
                    .Size = New System.Drawing.Size(20, 20)
                    .BorderStyle = BorderStyle.FixedSingle

                    'you must set the size before you set the location as the location should be set based on the size of the object.
                    .Location = New Point(Fix(Rnd() * (pnlObjContainer.Width - nwFallingObj.Width)), -10)
                End With
                FallingObjs.Add(nwFallingObj)
                pnlObjContainer.Controls.Add(nwFallingObj)
        End Select
    End Sub
    'Run
End Class


★Kit↘..

 [ 訪客留言(0) ] [ 編輯日誌 ] [ 分享至FACEBOOK ]  
MySelf
暱稱: Tikwal
性別: 男
國家: 香港
地區: 元朗區
++水晶音樂盒++
Mariage D'Amour
最近訪客
最近沒有訪客
訪客留言
最近三個月尚無任何留言
最新文章
贏到請飲野 lol
[VB.Net] 中國象棋
[.Net] Classes / Imp...
[轉][API]4個keybd 模...
[VB2010]常玩的, 接水...
文章分類
全部 (32)
API (5)
雜談 (2)
DataBase (2)
M$ (9)
php (1)
VB.Net (5)
純粹搞笑 (4)
網頁 (5)
未分類 (1)
日誌統計
文章總數: 32
留言總數: 28
今日人氣: 0
累積人氣: 1826