I am having trouble finding a way to complete my Snake Game in VB.
Here are my problems:
1. coding the randomly placed object for the snake to eat and then get longer
2. snake can run over itself and leave the screen
Any help at all in the next few days would be greatly appreciated.
thanks much, pilzheare
Here is my code sofar:
Code:
Public Class Form2 Dim m As Integer = 10 Dim p(m) As Point Dim k As Keys Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim b As New Bitmap(256, 256) Dim g As Graphics = Graphics.FromImage(b) If k = Keys.Left Then p(m).X -= 10 End If If k = Keys.Right Then p(m).X += 10 End If If k = Keys.Up Then p(m).Y -= 10 End If If k = Keys.Down Then p(m).Y += 10 End If For i As Integer = 0 To m - 1 p(i) = p(i + 1) g.FillRectangle(Brushes.Blue, New Rectangle(p(i), New Size(8, 8))) Next g.FillRectangle(Brushes.Blue, New Rectangle(p(m), New Size(8, 8))) g.Dispose() Me.BackgroundImage = b Me.ClientSize = b.Size Me.Refresh() End Sub Private Sub Form2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Left Then k = Keys.Left End If If e.KeyCode = Keys.Right Then k = Keys.Right End If If e.KeyCode = Keys.Up Then k = Keys.Up End If If e.KeyCode = Keys.Down Then k = Keys.Down End If End Sub End Class
Edited by Roger, 09 January 2011 - 11:14 AM.
added code block


Sign In
Create Account

Back to top









