• 0

VB.NEt... whats wrong with this?


Question

Hey guys,can someone tell me whats wrong with this code? I am trying to make it so, when all of the picture boxes are gone, they reappear, with the next level showing up.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim intSpeedX As Integer = 2
    Dim intSpeedy As Integer = -2
    Dim intscore As Integer
    Dim intlives As Integer = 3
    Dim intAllGone As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        CheckCollisions()
        If AllGone = 1 Then
            NextLevel()
        End If

        BallX += Speedx
        If BallX < 3 Or ballx + Ball.Width > Me.Width - 5 Then
            SpeedX = -speedx
        End If
        BallY += SpeedY
        If BallY < 3 Then
            SpeedY = -SpeedY
        End If

        If BallY + Ball.Height > Me.Height - 5 Then
            Timer1.Enabled = False
            UpdateLives()
            BallX = 232
            BallY = 376
            SpeedX = 2
            SpeedY = -2
            If Lives < 1 Then
                MsgBox("You have lost the game.", , "Oh NO!")
            Else
                MsgBox("You missed!", , "OH NO!")
                Timer1.Enabled = True
            End If
        End If

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles MyBase.MouseMove
        Paddle.Left = e.X - Paddle.Width / 3
    End Sub
    Public Sub CheckCollisions()
        Checkcollision(Paddle, False)
        Checkcollision(Red1)
        Checkcollision(Red2)
        Checkcollision(Red3)
        Checkcollision(Red4)
        Checkcollision(red5)
        Checkcollision(Blue1)
        Checkcollision(Blue2)
        Checkcollision(Blue3)
        Checkcollision(Blue4)
        Checkcollision(Blue5)
        Checkcollision(Black1)
        Checkcollision(black2)
        Checkcollision(black3)
        Checkcollision(black4)
        Checkcollision(black5)
        Checkcollision(brown1)
        Checkcollision(brown2)
        Checkcollision(brown3)
        Checkcollision(brown4)
        Checkcollision(brown5)

    End Sub

    Public Sub Checkcollision(ByVal src As PictureBox, ByVal Hide As Boolean)
        If src.Visible = True Then
            If BallX > src.Location.X And _
            BallX < src.Location.X + src.Size.Width And _
            Ball.Location.Y > src.Location.Y And _
            Ball.Location.Y < src.Location.Y + src.Size.Height Then
                SpeedY = -SpeedY
                updateScore()
                If Hide Then
                    src.Visible = False
                End If
            End If
        End If
        AllGone += 1
    End Sub

    'declare the overloadedversion of CheckCollision
    Public Sub checkcollision(ByVal src As PictureBox)
        'call the original version
        Checkcollision(src, True)
    End Sub

    Public Sub updateScore()
        Score += 10
        Label2.Text = "SCORE: " & Score
    End Sub
    Public Sub UpdateLives()
        Lives -= 1
        Label1.Text = "LIVES: " & Lives
    End Sub

    Public Property BallX() As Integer
        Get
            Return Ball.Left
        End Get
        Set(ByVal Value As Integer)
            Ball.Left = Value
        End Set
    End Property
    Public Property BallY() As Integer
        Get
            Return Ball.Top
        End Get
        Set(ByVal Value As Integer)
            Ball.Top = Value
        End Set
    End Property

    Public Property Lives() As Integer
        Get
            Return intlives
        End Get
        Set(ByVal Value As Integer)
            intlives = Value
        End Set
    End Property

    Public Property SpeedX() As Integer
        Get
            Return intSpeedX
        End Get
        Set(ByVal Value As Integer)
            intSpeedX = Value
        End Set
    End Property

    Public Property SpeedY() As Integer
        Get
            Return intSpeedy
        End Get
        Set(ByVal Value As Integer)
            intSpeedy = Value
        End Set
    End Property

    Public Property Score() As Integer
        Get
            Return intscore
        End Get
        Set(ByVal Value As Integer)
            intscore = Value
        End Set
    End Property

    Public Property AllGone() As Integer
        Get
            Return intscore
        End Get
        Set(ByVal Value As Integer)
            intAllGone = Value
        End Set
    End Property

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        MenuItem2.Checked = True
        MenuItem3.Checked = False
        Timer1.Enabled = True
    End Sub

    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        MenuItem3.Checked = True
        MenuItem2.Checked = False
        Timer1.Enabled = False
    End Sub

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

    End Sub

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

        resetgame()
    End Sub

    Private Sub resetgame()
        Label1.Text = "LIVES: 3"
        Label2.Text = "SCORE: 0"
        intscore = 0
        AllGone = 0
        Red1.Visible = True
        Red2.Visible = True
        Red3.Visible = True
        Red4.Visible = True
        red5.Visible = True
        Blue1.Visible = True
        Blue2.Visible = True
        Blue3.Visible = True
        Blue4.Visible = True
        Blue5.Visible = True
        Black1.Visible = True
        black2.Visible = True
        black3.Visible = True
        black4.Visible = True
        black5.Visible = True
        brown1.Visible = True
        brown2.Visible = True
        brown3.Visible = True
        brown4.Visible = True
        brown5.Visible = True


    End Sub

    Private Sub NextLevel()
        intSpeedX += 2
        intSpeedy -= 2
        Red1.Visible = True
        Red2.Visible = True
        Red3.Visible = True
        Red4.Visible = True
        red5.Visible = True
        Blue1.Visible = True
        Blue2.Visible = True
        Blue3.Visible = True
        Blue4.Visible = True
        Blue5.Visible = True
        Black1.Visible = True
        black2.Visible = True
        black3.Visible = True
        black4.Visible = True
        black5.Visible = True
        brown1.Visible = True
        brown2.Visible = True
        brown3.Visible = True
        brown4.Visible = True
        brown5.Visible = True


    End Sub
    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
        resetgame()
    End Sub

    Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
        resetgame()
        End
    End Sub
End Class

Thanks!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

You are declaring "intAllGone As Integer", but using "AllGone", which is a different variable, in your code.

Make sure you add "Option Explicit" at the top of your modules to get around problems like these in the future.

Link to comment
Share on other sites

  • 0

You're right, I haven't seen the AllGone() property. And I think that's where the problem is:

? Public Property AllGone() As Integer
 ? ? ? Get
 ? ? ? ? ? Return intscore ' FIX THIS
 ? ? ? End Get
 ? ? ? Set(ByVal Value As Integer)
 ? ? ? ? ? intAllGone = Value
 ? ? ? End Set
 ? End Property

Shouldn't you return intAllGone?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.