Public Class Form1
Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Keys) As Short
Dim up1, down1, up2, down2 As Short
Dim y1 As Integer = 10
Dim x As Integer = 5
Dim y As Integer = 5
Dim player1 As Integer = 0
Dim player2 As Integer = 0
Dim s As Boolean = True
Dim pause As Boolean = False
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
up1 = GetAsyncKeyState(Keys.Up)
down1 = GetAsyncKeyState(Keys.Down)
If Button1.Top >= Me.Height - Button1.Height - 50 Then
Button1.Top -= 1
Exit Sub
ElseIf Button1.Top <= 25 Then
Button1.Top += 1
Exit Sub
End If
If down1 < 0 Then Button1.Top += 10
If up1 < 0 Then Button1.Top -= 10
If Not ToolStripTextBox1.Focused Then
Button1.Select()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OvalShape1.Top += y
OvalShape1.Left += x
If OvalShape1.Top >= Me.Height - OvalShape1.Height - 50 Then
y = -y '-Val(ToolStripTextBox1.Text)
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
End If
If OvalShape1.Top <= 27 Then
y = -y 'Val(ToolStripTextBox1.Text)
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
End If
If OvalShape1.Left + OvalShape1.Width > Button1.Left And OvalShape1.Top > Button1.Top And OvalShape1.Top + OvalShape1.Height < Button1.Top + Button1.Height Then
x = -x 'Val(ToolStripTextBox1.Text)
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
End If
If OvalShape1.Left < Button2.Left + Button2.Width And OvalShape1.Top > Button2.Top And OvalShape1.Top + OvalShape1.Height < Button2.Top + Button2.Height Then
x = -x 'Val(ToolStripTextBox1.Text)
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
End If
If OvalShape1.Left >= Me.Width - OvalShape1.Width Then
x = -Val(ToolStripTextBox1.Text)
Timer2.Enabled = False
Label3.Visible = True
player2 += 1
Label2.Text = "player2= " & player2
OvalShape1.Left = 800
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
End If
If OvalShape1.Left <= 0 Then
x = Val(ToolStripTextBox1.Text)
Timer2.Enabled = False
Label3.Visible = True
player1 += 1
Label1.Text = "player1= " & player1
OvalShape1.Left = 200
If s Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
up2 = GetAsyncKeyState(Keys.W)
down2 = GetAsyncKeyState(Keys.S)
If Button2.Top >= Me.Height - Button2.Height - 50 Then
Button2.Top -= 1
Exit Sub
ElseIf Button2.Top <= 25 Then
Button2.Top += 1
Exit Sub
End If
If down2 < 0 Then Button2.Top += 10
If up2 < 0 Then Button2.Top -= 10
End Sub
Private Sub RicominciaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RicominciaToolStripMenuItem.Click
player1 = 0
player2 = 0
Label1.Text = "player1=0"
Label2.Text = "player2=0"
End Sub
Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
End
End Sub
Private Sub ToolStripTextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Enter
Timer2.Enabled = False
Label3.Visible = True
End Sub
Private Sub ToolStripTextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Leave
If IsNumeric(ToolStripTextBox1.Text) = False Then
ToolStripTextBox1.Text = Math.Abs(x)
Exit Sub
End If
If ToolStripTextBox1.Text < 5 Or ToolStripTextBox1.Text > 15 Then ToolStripTextBox1.Text = 10
If x < 0 Then
x = -Val(ToolStripTextBox1.Text)
Else
x = Val(ToolStripTextBox1.Text)
End If
If y < 0 Then
y = -Val(ToolStripTextBox1.Text)
Else
y = Val(ToolStripTextBox1.Text)
End If
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
If e.Button = Windows.Forms.MouseButtons.Left Then
Timer2.Enabled = True
Label3.Visible = False
End If
End Sub
Private Sub sound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sound.Click
If s Then
sound.Image = My.Resources.nosound
s = False
sound.ToolTipText = "add sound"
Else
sound.Image = My.Resources.sound
s = True
sound.ToolTipText = "remove sound"
End If
End Sub
Private Sub istruzioni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles istruzioni.Click
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")
End Sub
End Class