Skip to content

Instantly share code, notes, and snippets.

@reyman
Created December 28, 2011 22:29
Show Gist options
  • Save reyman/1530145 to your computer and use it in GitHub Desktop.
Save reyman/1530145 to your computer and use it in GitHub Desktop.
Private t_world() As Integer
Const cEmpty As Integer = 0
Const cWall As Integer = -1
Const cN As Integer = 1
Const cS As Integer = 2
Const cE As Integer = 4
Const cW As Integer = 8
... etc ...
Do Until t_emptyCase.Count = 0
'Choose cell index
index = choisiIndex(t_emptyCase.Count)
'return XT cell
Set myXY = t_emptyCase.Item(index + 1)
'shuffle direction
t_nextDirection = randomizeArray(t_direction)
Dim valueDirection As Integer
valueDirection = 0
For Each myDirection In t_nextDirection
'ValueDirectation contain the result direction for nx and ny here
If myDirection = "E" Then
nx = myXY.x + 1
valueDirection = cE
ElseIf myDirection = "W" Then
nx = myXY.x - 1
valueDirection = cW
Else
nx = myXY.x
End If
If myDirection = "S" Then
ny = myXY.y + 1
valueDirection = cS
ElseIf myDirection = "N" Then
ny = myXY.y - 1
valueDirection = cN
Else
ny = myXY.y
End If
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
'save neighboors direction on current cell
t_world(myXY.y, myXY.x) = (t_world(myXY.y, myXY.x) Or valueDirection)
'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
'save opposite direction on nx,ny cell
t_world(ny, nx) = (t_world(ny, nx) Or valueDirection2)
Set coord = New XY
Call coord.create(nx, ny)
'add the coord to emptyCase array
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