Skip to content

Instantly share code, notes, and snippets.

@reyman
Created December 28, 2011 22:29
Show Gist options
  • Save reyman/1530144 to your computer and use it in GitHub Desktop.
Save reyman/1530144 to your computer and use it in GitHub Desktop.
Do Until t_emptyCase.Count = 0
'Strategie pour choisir la prochaine case
index = choisiIndex(t_emptyCase.Count)
'renvoie un objet XY
Set myXY = t_emptyCase.Item(index + 1)
t_nextDirection = randomizeArray(t_direction)
tempAffichage = ""
For i = 0 To UBound(t_nextDirection) - 1
tempAffichage = tempAffichage + CStr(t_nextDirection(i))
Next i
'MsgBox (tempAffichage)
'Pour chaque direction on
' On part du bord en haut a gauche
Dim valueDirection As Integer
valueDirection = 0
For Each myDirection In t_nextDirection
If myDirection = "E" Then
nx = myXY.x + 1
valueDirection = cE
'MsgBox ("x+1")
ElseIf myDirection = "W" Then
nx = myXY.x - 1
valueDirection = cW
'MsgBox ("x-1")
Else
nx = myXY.x
End If
If myDirection = "S" Then
ny = myXY.y + 1
valueDirection = cS
'MsgBox ("y + 1")
ElseIf myDirection = "N" Then
ny = myXY.y - 1
valueDirection = cN
'MsgBox ("y - 1")
Else
ny = myXY.y
End If
'MsgBox (CStr(nx) + " " + CStr(ny) + " => " + CStr(nx >= 0 And ny >= 0))
Dim valueDirection2 As Integer
valueDirection2 = 0
If (nx >= 0 And ny >= 0 And nx < i_size And ny < i_size) Then
If (t_world(ny, nx) = cEmpty) Then
t_world(myXY.y, myXY.x) = (t_world(myXY.y, myXY.x) Or valueDirection)
't_path(myXY.y, myXY.x) = numPath
'numPath = numPath + 1
'Test for Opposite direction
If myDirection = "E" Then
valueDirection2 = cW
ElseIf myDirection = "W" Then
valueDirection2 = cE
End If
If myDirection = "S" Then
valueDirection2 = cN
ElseIf myDirection = "N" Then
valueDirection2 = cS
End If
t_world(ny, nx) = (t_world(ny, nx) Or valueDirection2)
Set coord = New XY
Call coord.create(nx, ny)
t_emptyCase.Add coord
index = -255
Exit For
End If
End If
Next
'Si index existe alors on le supprime car la case n'a plus de voisin interessant/vide (cf break n'a pas été executé !)
If (index <> -255) Then
t_emptyCase.Remove (index + 1)
End If
Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment