Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
gioco pong - Form1.vb

Form1.vb

Caricato da: Walker93
Scarica il programma completo

  1. Public Class Form1
  2.     Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Keys) As Short
  3.     Dim up1, down1, up2, down2 As Short
  4.     Dim y1 As Integer = 10
  5.     Dim x As Integer = 5
  6.     Dim y As Integer = 5
  7.     Dim player1 As Integer = 0
  8.     Dim player2 As Integer = 0
  9.     Dim s As Boolean = True
  10.     Dim pause As Boolean = False
  11.  
  12.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  13.         up1 = GetAsyncKeyState(Keys.Up)
  14.         down1 = GetAsyncKeyState(Keys.Down)
  15.         If Button1.Top >= Me.Height - Button1.Height - 50 Then
  16.             Button1.Top -= 1
  17.             Exit Sub
  18.         ElseIf Button1.Top <= 25 Then
  19.             Button1.Top += 1
  20.             Exit Sub
  21.         End If
  22.         If down1 < 0 Then Button1.Top += 10
  23.         If up1 < 0 Then Button1.Top -= 10
  24.         If Not ToolStripTextBox1.Focused Then
  25.             Button1.Select()
  26.         End If
  27.     End Sub
  28.  
  29.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  30.         OvalShape1.Top += y
  31.         OvalShape1.Left += x
  32.  
  33.         If OvalShape1.Top >= Me.Height - OvalShape1.Height - 50 Then
  34.             y = -y '-Val(ToolStripTextBox1.Text)
  35.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
  36.         End If
  37.         If OvalShape1.Top <= 27 Then
  38.             y = -y 'Val(ToolStripTextBox1.Text)
  39.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
  40.         End If
  41.  
  42.  
  43.         If OvalShape1.Left + OvalShape1.Width > Button1.Left And OvalShape1.Top > Button1.Top And OvalShape1.Top + OvalShape1.Height < Button1.Top + Button1.Height Then
  44.             x = -x 'Val(ToolStripTextBox1.Text)
  45.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
  46.         End If
  47.         If OvalShape1.Left < Button2.Left + Button2.Width And OvalShape1.Top > Button2.Top And OvalShape1.Top + OvalShape1.Height < Button2.Top + Button2.Height Then
  48.             x = -x 'Val(ToolStripTextBox1.Text)
  49.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
  50.         End If
  51.  
  52.  
  53.         If OvalShape1.Left >= Me.Width - OvalShape1.Width Then
  54.             x = -Val(ToolStripTextBox1.Text)
  55.             Timer2.Enabled = False
  56.             Label3.Visible = True
  57.             player2 += 1
  58.             Label2.Text = "player2= " & player2
  59.             OvalShape1.Left = 800
  60.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
  61.         End If
  62.         If OvalShape1.Left <= 0 Then
  63.             x = Val(ToolStripTextBox1.Text)
  64.             Timer2.Enabled = False
  65.             Label3.Visible = True
  66.             player1 += 1
  67.             Label1.Text = "player1= " & player1
  68.             OvalShape1.Left = 200
  69.             If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
  70.         End If
  71.     End Sub
  72.  
  73.     Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
  74.         up2 = GetAsyncKeyState(Keys.W)
  75.         down2 = GetAsyncKeyState(Keys.S)
  76.         If Button2.Top >= Me.Height - Button2.Height - 50 Then
  77.             Button2.Top -= 1
  78.             Exit Sub
  79.         ElseIf Button2.Top <= 25 Then
  80.             Button2.Top += 1
  81.             Exit Sub
  82.         End If
  83.         If down2 < 0 Then Button2.Top += 10
  84.         If up2 < 0 Then Button2.Top -= 10
  85.  
  86.     End Sub
  87.  
  88.     Private Sub RicominciaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RicominciaToolStripMenuItem.Click
  89.         player1 = 0
  90.         player2 = 0
  91.         Label1.Text = "player1=0"
  92.         Label2.Text = "player2=0"
  93.     End Sub
  94.  
  95.     Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
  96.         End
  97.     End Sub
  98.  
  99.     Private Sub ToolStripTextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Enter
  100.         Timer2.Enabled = False
  101.         Label3.Visible = True
  102.     End Sub
  103.  
  104.     Private Sub ToolStripTextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Leave
  105.         If IsNumeric(ToolStripTextBox1.Text) = False Then
  106.             ToolStripTextBox1.Text = Math.Abs(x)
  107.             Exit Sub
  108.         End If
  109.         If ToolStripTextBox1.Text < 5 Or ToolStripTextBox1.Text > 15 Then ToolStripTextBox1.Text = 10
  110.         If x < 0 Then
  111.             x = -Val(ToolStripTextBox1.Text)
  112.         Else
  113.             x = Val(ToolStripTextBox1.Text)
  114.         End If
  115.         If y < 0 Then
  116.             y = -Val(ToolStripTextBox1.Text)
  117.         Else
  118.             y = Val(ToolStripTextBox1.Text)
  119.         End If
  120.  
  121.     End Sub
  122.  
  123.     Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  124.         If e.Button = Windows.Forms.MouseButtons.Left Then
  125.             Timer2.Enabled = True
  126.             Label3.Visible = False
  127.         End If
  128.     End Sub
  129.  
  130.     Private Sub sound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sound.Click
  131.         If s Then
  132.             sound.Image = My.Resources.nosound
  133.             s = False
  134.             sound.ToolTipText = "add sound"
  135.         Else
  136.             sound.Image = My.Resources.sound
  137.             s = True
  138.             sound.ToolTipText = "remove sound"
  139.         End If
  140.     End Sub
  141.  
  142.     Private Sub istruzioni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles istruzioni.Click
  143.         MsgBox("Questo è il gioco chiamato Pong" & Chr(13) & "il primo giocatore usera i tasti freccia SU e GIÙ" & Chr(13) & "il secondo i tasti W e S" & Chr(13) & "by Walker93", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "istruzioni")
  144.     End Sub
  145. End Class