I have a problem, in the third sub "AutoRedraw" in undeclared. How should this variable be declared?
Code:
Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class Form1
Inherits System.Windows.Forms.Form
'
' Snake
'
' By Jamie Plenderleith
' plenderj@tcd.ie
' http://www.coolground.com/plenderj
'
Private Const vbGameSpeed As Integer = 50
Private Const vbBackground As Integer = &HC0E0FF
'UPGRADE_NOTE: vbGridColour was changed from a Constant to a Variable. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C54B49D7-5804-4D48-834B-B3D81E4C2F13"'
Private vbGridColour As Integer = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black)
'UPGRADE_NOTE: vbWallColour was changed from a Constant to a Variable. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C54B49D7-5804-4D48-834B-B3D81E4C2F13"'
Private vbWallColour As Integer = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
'UPGRADE_NOTE: vbBonusColour was changed from a Constant to a Variable. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C54B49D7-5804-4D48-834B-B3D81E4C2F13"'
Private vbBonusColour As Integer = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue)
'UPGRADE_NOTE: vbSnakeColour was changed from a Constant to a Variable. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C54B49D7-5804-4D48-834B-B3D81E4C2F13"'
Private vbSnakeColour As Integer = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Lime)
Private facingUp, doLoop, gotBonus, facingDown As Boolean
Private facingLeft, facingRight As Boolean
Private lastTickCount As Integer
Private occupiedSquares() As Integer
Private Declare Function GetTickCount Lib "kernel32" () As Integer
Private Sub Form1_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim KeyCode As Short = eventArgs.KeyCode
Dim Shift As Short = eventArgs.KeyData \ &H10000
Select Case KeyCode
Case System.Windows.Forms.Keys.Left
If facingRight Then Exit Sub
facingLeft = True : facingRight = False : facingUp = False : facingDown = False
Case System.Windows.Forms.Keys.Right
If facingLeft Then Exit Sub
facingRight = True : facingLeft = False : facingUp = False : facingDown = False
Case System.Windows.Forms.Keys.Up
If facingDown Then Exit Sub
facingUp = True : facingDown = False : facingLeft = False : facingRight = False
Case System.Windows.Forms.Keys.Down
If facingUp Then Exit Sub
facingDown = True : facingUp = False : facingLeft = False : facingRight = False
End Select
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim i As Integer : BackColor = System.Drawing.ColorTranslator.FromOle(vbGridColour) : box(0).BackColor = System.Drawing.ColorTranslator.FromOle(vbBackground)
'UPGRADE_ISSUE: Form property Form1.AutoRedraw was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
AutoRedraw = True : loadBoard() : facingDown = True : ReDim occupiedSquares(4)
For i = 0 To 4
occupiedSquares(i) = 50 + (5 - i)
box(occupiedSquares(i)).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
Next
Me.Show() : Activate() : doGameLoop()
End Sub
Private Sub addBonus()
Dim n As Integer
lblRetry:
n = (Int((1560 - 39 + 1) * Rnd() + 39))
If (System.Drawing.ColorTranslator.ToOle(box(n).BackColor) = vbWallColour) Or (System.Drawing.ColorTranslator.ToOle(box(n).BackColor) = vbSnakeColour) Then GoTo lblRetry
box(n).BackColor = System.Drawing.ColorTranslator.FromOle(vbBonusColour)
End Sub
Private Sub loadBoard()
Dim i As Integer
For i = 1 To 1599
box.Load(i)
With box(i)
'UPGRADE_WARNING: Shape method box.Move has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
.SetBounds(9 + (Int((i Mod 40) * .Width)), 9 + (Int(i / 40) * .Height), .Width, .Height)
.Visible = True
End With
Next
For i = 0 To 1599
If (i <= 39) Or (i >= 1560) Then box(i).BackColor = System.Drawing.ColorTranslator.FromOle(vbWallColour)
If (i Mod 40) = 0 Then box(i).BackColor = System.Drawing.ColorTranslator.FromOle(vbWallColour)
If (i Mod 40) = 39 Then box(i).BackColor = System.Drawing.ColorTranslator.FromOle(vbWallColour)
Next
addBonus()
End Sub
Private Sub doGameLoop()
doLoop = True
Do While doLoop
System.Windows.Forms.Application.DoEvents()
If (GetTickCount - lastTickCount) >= vbGameSpeed Then
lastTickCount = GetTickCount
Select Case True
Case facingUp
If (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 40).BackColor) = vbWallColour) And (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 40).BackColor) = vbSnakeColour) Then
If Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 40).BackColor) = vbBonusColour Then
doodleBackSquare()
Else
ReDim Preserve occupiedSquares(UBound(occupiedSquares) + 1)
gotBonus = True
End If
box(occupiedSquares(0) - 40).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
shiftDownArray(occupiedSquares, occupiedSquares(0) - 40)
If gotBonus Then
gotBonus = False
box(occupiedSquares(UBound(occupiedSquares))).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
addBonus()
End If
Else
doLoop = False
doDead()
End If
Case facingDown
If (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 40).BackColor) = vbWallColour) And (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 40).BackColor) = vbSnakeColour) Then
If Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 40).BackColor) = vbBonusColour Then
doodleBackSquare()
Else
ReDim Preserve occupiedSquares(UBound(occupiedSquares) + 1)
gotBonus = True
End If
box(occupiedSquares(0) + 40).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
shiftDownArray(occupiedSquares, occupiedSquares(0) + 40)
If gotBonus Then
gotBonus = False
box(occupiedSquares(UBound(occupiedSquares))).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
addBonus()
End If
Else
doLoop = False
doDead()
End If
Case facingLeft
If (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 1).BackColor) = vbWallColour) And (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 1).BackColor) = vbSnakeColour) Then
If Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) - 1).BackColor) = vbBonusColour Then
doodleBackSquare()
Else
ReDim Preserve occupiedSquares(UBound(occupiedSquares) + 1)
gotBonus = True
End If
box(occupiedSquares(0) - 1).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
shiftDownArray(occupiedSquares, occupiedSquares(0) - 1)
If gotBonus Then
gotBonus = False
box(occupiedSquares(UBound(occupiedSquares))).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
addBonus()
End If
Else
doLoop = False
doDead()
End If
Case facingRight
If (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 1).BackColor) = vbWallColour) And (Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 1).BackColor) = vbSnakeColour) Then
If Not System.Drawing.ColorTranslator.ToOle(box(occupiedSquares(0) + 1).BackColor) = vbBonusColour Then
doodleBackSquare()
Else
ReDim Preserve occupiedSquares(UBound(occupiedSquares) + 1)
gotBonus = True
End If
box(occupiedSquares(0) + 1).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
shiftDownArray(occupiedSquares, occupiedSquares(0) + 1)
If gotBonus Then
gotBonus = False
box(occupiedSquares(UBound(occupiedSquares))).BackColor = System.Drawing.ColorTranslator.FromOle(vbSnakeColour)
addBonus()
End If
Else
doLoop = False
doDead()
End If
End Select
End If
Loop
End Sub
Private Sub doodleBackSquare()
box(occupiedSquares(UBound(occupiedSquares))).BackColor = System.Drawing.ColorTranslator.FromOle(vbBackground)
End Sub
Private Sub shiftDownArray(ByRef arr() As Integer, ByVal newTopIndexValue As Integer)
Dim i As Integer
Dim x() As Integer : x = VB6.CopyArray(arr)
For i = 1 To UBound(arr)
arr(i) = x(i - 1)
Next
arr(0) = newTopIndexValue
End Sub
Private Sub doDead()
MsgBox("Oh boo-hoo you're dead.", MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly, "Snake")
End
End Sub
Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
doLoop = False
End
End Sub
End Class