لكي تبدأ في برمجة الألعاب اليك الكود التالي في تحريك صورة و إذا لامست صورة أخري تخرج رسالة معينة
Public Class Form1
Dim x As Integer
Private Sub P1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles P1.Click
End Sub
Private Sub Form1_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim loc
As Point
If
e.KeyCode = Windows.Forms.Keys.Left Then
If Not P1.Location.X - 5 < 0 Then
loc = New
Point(P1.Location.X - 5, P1.Location.Y)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Right Then
If Not P1.Location.X + 5 > Me.Width
- P1.Width - 5 Then
loc = New
Point(P1.Location.X + 5, P1.Location.Y)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Up Then
If Not P1.Location.Y - 5 < 0 Then
loc = New
Point(P1.Location.X, P1.Location.Y - 5)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Down Then
If Not P1.Location.Y + 5 > Me.Width
- P1.Width - 5 Then
loc = New
Point(P1.Location.X, P1.Location.Y + 5)
P1.Location = loc
End
If
End If
If
P1.Bounds.IntersectsWith(Me.PictureBox1.Bounds)
Then
P3.Visible = True
x = x + 1
Me.Label1.Text
= x.ToString()
loc = New
Point(0, 100)
P1.Location = loc
End If
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
x = 0
End Sub
End Class
Public Class Form1
Dim x As Integer
Private Sub P1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles P1.Click
End Sub
Private Sub Form1_KeyDown(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim loc
As Point
If
e.KeyCode = Windows.Forms.Keys.Left Then
If Not P1.Location.X - 5 < 0 Then
loc = New
Point(P1.Location.X - 5, P1.Location.Y)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Right Then
If Not P1.Location.X + 5 > Me.Width
- P1.Width - 5 Then
loc = New
Point(P1.Location.X + 5, P1.Location.Y)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Up Then
If Not P1.Location.Y - 5 < 0 Then
loc = New
Point(P1.Location.X, P1.Location.Y - 5)
P1.Location = loc
End
If
End If
If
e.KeyCode = Windows.Forms.Keys.Down Then
If Not P1.Location.Y + 5 > Me.Width
- P1.Width - 5 Then
loc = New
Point(P1.Location.X, P1.Location.Y + 5)
P1.Location = loc
End
If
End If
If
P1.Bounds.IntersectsWith(Me.PictureBox1.Bounds)
Then
P3.Visible = True
x = x + 1
Me.Label1.Text
= x.ToString()
loc = New
Point(0, 100)
P1.Location = loc
End If
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
x = 0
End Sub
End Class