I need to make my Computer Paddle defeatable. Right now i have everything coded it is just impossible to win.
Pong Code:
  1. Public Class uipongform
  2. #Region "End Game on Escape Press"
  3.     ' Escape the game when escape has been pressed.
  4.     Private Sub pongMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  5.         If e.KeyValue = Keys.Escape Then
  6.             Me.Close()
  7.         End If
  8.     End Sub
  9. #End Region
  10. #Region "Globals"
  11.     Dim speed As Single = 10 ' Ball Speed
  12.     Dim rndInst As New Random() ' Random instance
  13.     Dim xVel As Single = Math.Cos(rndInst.Next(5, 10)) * speed
  14.     Dim yVel As Single = Math.Sin(rndInst.Next(5, 10)) * speed
  15.     ' The player's scores.
  16.     Dim compScore As Integer = 0
  17.     Dim plrScore As Integer = 0
  18.  
  19. #End Region
  20.  
  21.  
  22.  
  23. #Region "Move the paddle according to the mouse"
  24.     ' Move the paddle according to the mouse position.
  25.     Private Sub pongMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
  26.  
  27.         If e.Y > 5 And e.Y < Me.Height - 40 - paddlePlayer.Height Then _
  28.         paddlePlayer.Location = New Point(paddlePlayer.Location.X, e.Y)
  29.  
  30.     End Sub
  31. #End Region
  32.  
  33. #Region "Main Timer"
  34.     Private Sub gameTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameTimer.Tick
  35.         'Set the computer player to move according to the ball's position."
  36.         If gameBall.Location.Y > 5 And gameBall.Location.Y < Me.Height - 40 _
  37.         - paddlePlayer.Height Then _
  38.         paddleComputer.Location = New Point(paddleComputer.Location.X, gameBall.Location.Y)
  39.         ' Move the game ball.
  40.         gameBall.Location = New Point(gameBall.Location.X + xVel, gameBall.Location.Y + yVel)
  41.         ' Check for top wall.
  42.         If gameBall.Location.Y < 0 Then
  43.             gameBall.Location = New Point(gameBall.Location.X, 0)
  44.             yVel = -yVel
  45.         End If
  46.         ' Check for bottom wall.
  47.         If gameBall.Location.Y > Me.Height - gameBall.Size.Height - 45 Then
  48.             gameBall.Location = New Point(gameBall.Location.X, Me.Height - gameBall.Size.Height - 45)
  49.             yVel = -yVel
  50.         End If
  51.         ' Check for player paddle.
  52.         If gameBall.Bounds.IntersectsWith(paddlePlayer.Bounds) Then
  53.             gameBall.Location = New Point(paddlePlayer.Location.X - gameBall.Size.Width, _
  54.             gameBall.Location.Y)
  55.             xVel = -xVel
  56.         End If
  57.         ' Check for computer paddle.
  58.         If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then
  59.             gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _
  60.             gameBall.Location.Y)
  61.             xVel = -xVel
  62.         End If
  63.         ' Check for left wall.
  64.         If gameBall.Location.X < 0 Then
  65.             plrScore += 1
  66.             gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
  67.             plrScoreDraw.Text = Convert.ToString(plrScore)
  68.         End If
  69.         ' Check for right wall.
  70.         If gameBall.Location.X > Me.Width - gameBall.Size.Width - paddlePlayer.Width Then
  71.             compScore += 1
  72.             gameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
  73.             compScoreDraw.Text = Convert.ToString(compScore)
  74.         End If
  75.     End Sub
  76. #End Region
  77.  
  78.  
  79.     Private Sub uiexitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiexitbutton.Click
  80.         Me.Close()
  81.     End Sub
  82.  
  83. End Class