02-18-2024, 11:34 PM
(02-18-2024, 08:34 PM)bplus Wrote: Sets up a board with no dead end tracks, might be used for race track or city roads layout or just nice designs.
Code: (Select All)Option _Explicit
_Title "Little game Circuit game space" 'b+ 2024-02-18
Randomize Timer
Dim Shared SW, SH: SW = 800: SH = 600
Screen _NewImage(SW, SH, 32)
_ScreenMove 200, 60
Dim As Long UbX, UbY, cx, cy, lastTarget, targets, tx, ty, dx, dy
UbX = 80: UbY = 60 ' the max width and height of board cells
Do ' test board layouts
Cls: ReDim board$(1 To UbX, 1 To UbY) 'resets
cx = UbX \ 2: cy = UbY \ 2: lastTarget = 30
For targets = 1 To lastTarget
tryAgain: ' to avoid dead end streets
If targets <> lastTarget Then ' stay off the edges
tx = 2 * Int((Rnd * (UbX - 3) \ 2)) + 2: ty = 2 * Int(Rnd * (UbY - 3) \ 2) + 2
Else
tx = UbX \ 2: ty = UbY \ 2
End If
If tx = cx Or ty = cy Then GoTo tryAgain ' to avoid dead end streets
dx = tx - cx: dy = ty - cy ' the distance and direction we have to go
While cx <> tx: cx = cx + Sgn(dx): GoSub MakeWay: Wend
While cy <> ty: cy = cy + Sgn(dy): GoSub MakeWay: Wend
Next
Sleep
Loop Until _KeyDown(27)
End
MakeWay: board$(cx, cy) = "S": Line ((cx - 1) * 10, (cy - 1) * 10)-Step(9, 9), , BF: Return
Nice one!
If I may, I'd like to use this as a starter for a train game or similar (yes, I know it's been done, but it should be a good exercise).
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/