Thursday, July 29, 2010

Public Class Form1
    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As Byte(), ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Dim apples As New List(Of PictureBox)
    'Dim apple As PictureBox

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim txt As TextBox
        'For i = 0 To 9
        '    txt = New TextBox
        '    txt.BackColor = Color.AliceBlue
        '    txt.Location = New Point(100, i * 50)
        '    Me.Controls.Add(txt)
        '    txtboxes(i) = txt
        'Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        For Each apple In apples
            ' check if apple hit the ground
            If apple.Location.Y + apple.Size.Height >= theGround.Location.Y Then
                ' play a sound

                ' remove the item and penalize the player
                removeAnApple(apple)
                Label1.Text = Label1.Text - 500
                Exit For
            Else
                ' animate it
                apple.Location = New Point(apple.Location.X, apple.Location.Y + 4)
            End If
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PlaySound("C:\Users\Public\Music\Sample Music\Kalimba.mp3", 1, 0)

        addAnApple()
        Timer1.Enabled = True

    End Sub

    Sub removeAnApple(ByVal apple As PictureBox)
        Me.Controls.Remove(apple)
        apples.Remove(apple)
    End Sub


    Private Sub apple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        removeAnApple(sender)

        Label1.Text = Label1.Text + 100
        addAnApple()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        addAnApple()
    End Sub

    Sub addAnApple()
        Dim r As New Random

        Dim apple As PictureBox
        apple = New PictureBox
        ' Me.Width(-90)
        apple.Location = New Point(r.Next(0, Me.Width - 90), 12)
        apple.ImageLocation = "C:\Users\joshwaxman.CSDEPT.000\Pictures\APPLE.jpg"
        apple.SizeMode = PictureBoxSizeMode.StretchImage
        apple.Size = New Point(90, 90)
        AddHandler apple.Click, AddressOf apple_Click

        Me.Controls.Add(apple)
        apples.Add(apple)
    End Sub
End Class

No comments:

Post a Comment