Sie sind auf Seite 1von 2

Imports System

Imports System.Drawing
Imports System.Drawing.Graphics

Public Class Form1


Dim g As Graphics
Dim intFirstDraw As Integer = 0
Dim intsnake(20) As Rectangle
Dim intaddsnake As Integer = 0
Dim downkey As Boolean
Dim pic As New PictureBox()
Dim upkey As Boolean
Dim leftkey As Boolean
Dim rightkey As Boolean
Dim x As Integer, y As Integer, xstep As Integer = 5, ystep As Integer
= 5

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Timer1.Start()
g = Me.CreateGraphics

For Me.x = 0 To 20
intsnake(Me.x) = New Rectangle(Me.x * 10, y, 10, 10)

Next

x = 300
y = 400

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick
g.Clear(Me.BackColor)
'y = y + ystep

pic = PictureBox1

For intCount = 0 To intaddsnake


If intsnake(intCount).IntersectsWith(pic.Bounds) Then
intaddsnake = intaddsnake + 1

pic.Hide()
pic.Location = New Point((Me.Width + 200), (Me.Height +
200))
pic.Show()

intsnake(intCount) = New Rectangle(x, y, 10 + intaddsnake


* 2, 10)
g.DrawRectangle(Pens.Black, intsnake(intCount))
g.FillRectangle(Brushes.Blue, intsnake(intCount))
Else
intsnake(intCount) = New Rectangle(x, y, 10, 10)
g.DrawRectangle(Pens.Black, intsnake(intCount))
g.FillRectangle(Brushes.Blue, intsnake(intCount))
End If
Next

End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

Dim mykey As String, mydata As Object


mykey = Chr(e.KeyCode)
mydata = e.KeyData 'to figure out which key is
pressed
'Label1.Text = mykey & " was pressed. The code for the " &
mydata.ToString & " key is " & e.KeyCode

'x = x + xstep
'Y = Y + ystep

If e.KeyCode = Keys.Down Then


y = ystep + y
downkey = True
End If

If e.KeyCode = Keys.Right Then


x = xstep + x
rightkey = True
End If

If e.KeyCode = Keys.Left Then


x = x - xstep
leftkey = True
End If

If e.KeyCode = Keys.Up Then


y = y - ystep
upkey = True
End If

End Sub

Private Sub EndToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles EndToolStripMenuItem.Click
End
End Sub
End Class