Advertisement
jhnksr

...

Dec 4th, 2023 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     Dim playerAcceleration As Integer = 0
  3.     Dim playerSpeed As Integer = 0
  4.  
  5.     Dim opponentAccelerations As New List(Of Integer)()
  6.     Dim opponentSpeeds As New List(Of Integer)()
  7.  
  8.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9.         Timer1.Interval = 50
  10.         Timer1.Start()
  11.  
  12.  
  13.         For i As Integer = 0 To 2
  14.             opponentAccelerations.Add(0)
  15.             opponentSpeeds.Add(0)
  16.         Next
  17.     End Sub
  18.  
  19.     Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
  20.         playerAcceleration += 5
  21.     End Sub
  22.  
  23.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  24.         playerSpeed += playerAcceleration
  25.         PictureBox1.Left += playerSpeed
  26.  
  27.         For i As Integer = 0 To 2
  28.             opponentSpeeds(i) = CInt(Math.Floor((10 * Rnd()) + 1))
  29.             opponentAccelerations(i) = 0
  30.             Me.Controls("PictureBoxOpponent" & (i + 1)).Left += opponentSpeeds(i)
  31.  
  32.             If Me.Controls("PictureBoxOpponent" & (i + 1)).Right >= Me.ClientRectangle.Right Then
  33.                 Timer1.Stop()
  34.                 MessageBox.Show($"Opponent {i + 1} won!")
  35.                 Me.Close()
  36.             End If
  37.         Next
  38.  
  39.         If PictureBox1.Right >= Me.ClientRectangle.Right Then
  40.             Timer1.Stop()
  41.             MessageBox.Show("You won!")
  42.             Me.Close()
  43.         End If
  44.     End Sub
  45. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement