Author Topic: Pipes Puzzle by Dav & bplus  (Read 13404 times)

0 Members and 1 Guest are viewing this topic.

Offline Junior Librarian

  • Moderator
  • Newbie
  • Posts: 19
    • View Profile
Pipes Puzzle by Dav & bplus
« on: September 30, 2021, 06:06:46 am »
Pipes Puzzle

Author: @Dav
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=4232.0
Version: 1

Description:
This is a Maze puzzler.  To play you click on the pipes to rotate them and connect them to the flow, making the pipes all connected and one color.

Source Code (for reference only: use the zip file):
Code: QB64: [Select]
  1.     '================
  2.     'PIPES.BAS v1.0
  3.     '================
  4.     'Connect the pipes puzzle game
  5.     'Coded by Dav for QB64-GL 1.5 in SEP/2021
  6.      
  7.     'NOTE: Formally called MazeConnect Prototype on the forum.
  8.      
  9.     '============
  10.     'HOW TO PLAY:
  11.     '============
  12.      
  13.     'Click on pipes to rotate them and connect them as one.
  14.     'Object is to make all pipes on board connected to leader.
  15.     'Top left pipe is always on, the leader, so start from it.
  16.     'When pipes are all connected, you advance to next level.
  17.     'There are currently 20 levels.  ESC key exits game.
  18.      
  19.     'SPACE  = restarts level
  20.     'RIGHT ARROW = goto next level
  21.     'LEFT ARROW = go back a level
  22.     'ESC = Quits game
  23.      
  24.     '         VVVVVVV     blus fixed next line to work from his downloaded zip
  25.     $ExeIcon:'.\icon.ico'
  26.     _Icon
  27.      
  28.      
  29.      
  30.     Dim Shared GridSize, Level, MaxLevel, LD$, LU$, RD$, RU$, HZ$, VT$, BM$
  31.      
  32.     Level = 1: MaxLevel = 13
  33.      
  34.     GridSize = 3 'default starting GridSize is 3x3 (its level 1)
  35.     MaxGridSize = 15 'The last GridSize level so far (13 levels right now)
  36.      
  37.     'Declare image names: angle characters, right up, left up, etc
  38.     LD$ = "ld": LU$ = "lu"
  39.     RD$ = "rd": RU$ = "ru"
  40.     HZ$ = "hz": VT$ = "vt"
  41.     BM$ = "bm"
  42.      
  43.     'Sound files
  44.     new& = _SndOpen("sfx_magic.ogg")
  45.     move& = _SndOpen("sfx_click1.mp3"):
  46.     click& = _SndOpen("sfx_click2.mp3"):
  47.     clap& = _SndOpen("sfx_clap.ogg")
  48.      
  49.     'image file
  50.     Dim Shared Solved&
  51.     Solved& = _LoadImage("solved.png", 32) '<  thank bplus for this
  52.      
  53.     'For game state saving...to be added later
  54.     loaded = 0: fil$ = "pipe.dat"
  55.     If _FileExists(fil$) Then
  56.         loaded = 1
  57.     End If
  58.      
  59.     '=======
  60.     newlevel:
  61.     '=======
  62.      
  63.     Screen _NewImage(640, 640, 32)
  64.     'Do: Loop Until _ScreenExists ' <<<<<<<<<< sorry Dav this aint working on my system
  65.     _Delay .25 ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<< does this work for you?
  66.     '            No? increase delay time really nice to have centered on screen
  67.     _ScreenMove _Middle ' <  thank bplus for this , ahhhh that's better
  68.     Cls ', _RGB(32, 32, 77)
  69.      
  70.     If Level = 1 Then
  71.         back& = _LoadImage("hz-grn.png")
  72.         _PutImage (0, 0)-(640, 640), back&
  73.         _FreeImage back&
  74.         title& = _LoadImage("title.png")
  75.         _PutImage (84, 140), title&
  76.         _FreeImage title&
  77.         w$ = Input$(1)
  78.         For a = 0 To 64
  79.             Line (0, 0)-(640, 640), _RGBA(0, 0, 0, a), BF
  80.             _Delay .02
  81.         Next
  82.     End If
  83.      
  84.     PPRINT 100, 300, 30, _RGB(200, 200, 200), 0, "Level:" + Str$(Level) + " of" + Str$(MaxLevel)
  85.     _Delay 2
  86.      
  87.     _SndPlay new&
  88.      
  89.     Title$ = "Pipes: Level " + Str$(Level) + " of" + Str$(MaxLevel)
  90.     _Title Title$
  91.      
  92.     'Make space for variables
  93.     ReDim Shared TileVal$(GridSize * GridSize)
  94.     ReDim Shared TileX(GridSize * GridSize), TileY(GridSize * GridSize)
  95.     ReDim Shared TileClr(GridSize * GridSize), TileClr2(GridSize * GridSize)
  96.      
  97.     TileSize = Int(640 / GridSize) 'The width/height of tiles, in pixels
  98.      
  99.     'set tile values, and generate x/y values...
  100.     bb = 1
  101.     For r = 1 To GridSize
  102.         For c = 1 To GridSize
  103.             x = (r * TileSize): y = (c * TileSize)
  104.             If Rnd(GridSize * 2) = GridSize Then br = 0
  105.             TileX(bb) = x - TileSize: TileY(bb) = y - TileSize
  106.             TileVal$(bb) = RD$
  107.             TileClr(bb) = 0
  108.             TileClr2(bb) = 0
  109.             bb = bb + 1
  110.         Next c
  111.     Next r
  112.      
  113.     TileClr(1) = 1 'turn on top left leader tile
  114.     TileClr2(1) = 1 'make a copy
  115.      
  116.     setmaze 'Load level maze data, it's already scrambled up
  117.      
  118.     firstdraw = 1
  119.     GoSub updatebuttons
  120.      
  121.     Do
  122.      
  123.         _Limit 300
  124.      
  125.         'wait until mouse button up to continue
  126.         While _MouseButton(1) <> 0: n = _MouseInput: Wend
  127.      
  128.         trap = _MouseInput
  129.         If _MouseButton(1) Then
  130.             mx = _MouseX: my = _MouseY
  131.      
  132.             For b = 1 To (GridSize * GridSize)
  133.      
  134.                 tx = TileX(b): tx2 = TileX(b) + TileSize
  135.                 ty = TileY(b): ty2 = TileY(b) + TileSize
  136.      
  137.                 If mx >= tx And mx <= tx2 Then
  138.                     If my >= ty And my <= ty2 Then
  139.                         'skip any black blocks clicked on
  140.                         If TileVal$(b) = BM$ Then GoTo skip
  141.      
  142.                         _SndPlay move&
  143.      
  144.                         bv2$ = TileVal$(b) 'see what tile it is
  145.      
  146.                         'rotate right angle tiles
  147.                         If bv2$ = RD$ Then TileVal$(b) = LD$
  148.                         If bv2$ = LD$ Then TileVal$(b) = LU$
  149.                         If bv2$ = LU$ Then TileVal$(b) = RU$
  150.                         If bv2$ = RU$ Then TileVal$(b) = RD$
  151.      
  152.                         'rotate horiz/vert lines
  153.                         If bv2$ = HZ$ Then TileVal$(b) = VT$
  154.                         If bv2$ = VT$ Then TileVal$(b) = HZ$
  155.      
  156.                         'show tile
  157.                         If TileClr(b) = 1 Then
  158.                             tag$ = "-grn.png"
  159.                         Else
  160.                             tag$ = "-wht.png"
  161.                         End If
  162.      
  163.                         SHOW TileVal$(b) + tag$, TileX(b), TileY(b), TileX(b) + TileSize, TileY(b) + TileSize
  164.      
  165.                         GoSub updatebuttons
  166.                         GoSub checkforwin
  167.      
  168.                     End If
  169.                 End If
  170.             Next b
  171.         End If
  172.         skip:
  173.      
  174.         ink$ = UCase$(InKey$)
  175.      
  176.         If ink$ = Chr$(32) Then GoTo newlevel
  177.      
  178.         'Right arrows advance to next level
  179.         If ink$ = Chr$(0) + Chr$(77) Then
  180.             GridSize = GridSize + 1
  181.             Level = Level + 1
  182.             If Level > MaxLevel Then Level = 1
  183.             If GridSize > MaxGridSize Then
  184.                 GridSize = 3 'MaxGridSize  'restart
  185.             End If
  186.             GoTo newlevel
  187.         End If
  188.      
  189.         'Left Arrows go back a level
  190.         If ink$ = Chr$(0) + Chr$(75) Then
  191.             GridSize = GridSize - 1
  192.             If GridSize < 3 Then GridSize = MaxGridSize
  193.             Level = Level - 1
  194.             If Level < 1 Then Level = MaxLevel
  195.             GoTo newlevel
  196.         End If
  197.      
  198.     Loop Until ink$ = Chr$(27)
  199.      
  200.     System
  201.      
  202.     '============
  203.     updatebuttons:
  204.     '============
  205.      
  206.     'first tile always on, draw it green
  207.     SHOW TileVal$(1) + "-grn.png", TileX(1), TileY(1), TileX(1) + TileSize, TileY(1) + TileSize
  208.      
  209.      
  210.     'turn all off tile colors first, except 1st
  211.     For g = 2 To GridSize * GridSize
  212.         TileClr(g) = 0
  213.     Next g
  214.      
  215.      
  216.     'set leader tile flow direction
  217.     If TileVal$(1) = HZ$ Then direction = 1 'going right
  218.     If TileVal$(1) = VT$ Then direction = 2 'going down
  219.      
  220.     cur = 1 'start with 1st tile always
  221.      
  222.     'do until can't flow anymore (direction blocked)
  223.     Do
  224.      
  225.         If direction = 1 Then 'heading right
  226.             'see if already on the right edge of board
  227.             'if so, it can't go right anymore, so end flow...
  228.             For j = (GridSize * GridSize) - GridSize + 1 To GridSize * GridSize
  229.                 If cur = j Then GoTo flowdone
  230.             Next j
  231.             'now see if one to the right can connect with it.
  232.             'if not connectable, end flow here.
  233.             con = 0 'default is not connectable
  234.             nv$ = TileVal$(cur + GridSize)
  235.             If nv$ = HZ$ Then con = 1
  236.             If nv$ = LU$ Then con = 1
  237.             If nv$ = LD$ Then con = 1
  238.             'if not, end flow here
  239.             If con = 0 Then GoTo flowdone
  240.             'looks like it is connectable, so turn it on
  241.             TileClr(cur + GridSize) = 1 'turn piece to the right on.
  242.             'Make new pieve the new current flow position
  243.             tc = (cur + GridSize): cur = tc
  244.             'find/set new direction based on that character
  245.             If nv$ = HZ$ Then direction = 1 'right
  246.             If nv$ = LU$ Then direction = 4 'up
  247.             If nv$ = LD$ Then direction = 2 'down
  248.         End If
  249.      
  250.         If direction = 2 Then 'heading down
  251.             'see if this one is on the bottom edge
  252.             For j = GridSize To (GridSize * GridSize) Step GridSize
  253.                 If cur = j Then GoTo flowdone
  254.             Next j
  255.             'now see if new one can connect with this one.
  256.             'if not, end flow here.
  257.             con = 0 'default is not connectable
  258.             nv$ = TileVal$(cur + 1)
  259.             If nv$ = VT$ Then con = 1
  260.             If nv$ = LU$ Then con = 1
  261.             If nv$ = RU$ Then con = 1
  262.             'if not, end flow here
  263.             If con = 0 Then GoTo flowdone
  264.             'looks like it must be connectable
  265.             TileClr(cur + 1) = 1 'turn the next piece on too
  266.             'Make it the new current char position
  267.             tc = (cur + 1): cur = tc
  268.             'find/set new direction based on character
  269.             If nv$ = LU$ Then direction = 3 'left
  270.             If nv$ = RU$ Then direction = 1 'right
  271.             If nv$ = VT$ Then direction = 2 'down
  272.         End If
  273.      
  274.         If direction = 3 Then 'heading left
  275.             'see if this one is on the bottom edge
  276.             For j = 1 To GridSize
  277.                 If cur = j Then GoTo flowdone
  278.             Next j
  279.      
  280.             'now see if new one can connect with this one.
  281.             'if not, end flow here.
  282.             con = 0 'default is not connectable
  283.             nv$ = TileVal$(cur - GridSize)
  284.             If nv$ = HZ$ Then con = 1
  285.             If nv$ = RU$ Then con = 1
  286.             If nv$ = RD$ Then con = 1
  287.             'if not, end flow here
  288.             If con = 0 Then GoTo flowdone
  289.             'looks like it must be connectable
  290.             TileClr(cur - GridSize) = 1 'turn the next piece on too
  291.             'Make it the new current char position
  292.             tc = (cur - GridSize): cur = tc
  293.             'find/set new direction based on character
  294.             If nv$ = HZ$ Then direction = 3 'left
  295.             If nv$ = RU$ Then direction = 4 'up
  296.             If nv$ = RD$ Then direction = 2 'down
  297.         End If
  298.      
  299.         If direction = 4 Then 'going up
  300.             'see if this one is on the edge of board
  301.             'if so, it can't go up, so end flow...
  302.             For j = 1 To (GridSize * GridSize) Step GridSize
  303.                 If cur = j Then GoTo flowdone
  304.             Next j
  305.             'now see if new one can connect with this one.
  306.             'if not, end flow here.
  307.             con = 0 'default is not connectable
  308.             nv$ = TileVal$(cur - 1)
  309.             If nv$ = VT$ Then con = 1
  310.             If nv$ = LD$ Then con = 1
  311.             If nv$ = RD$ Then con = 1
  312.             'if not, end flow here
  313.             If con = 0 Then GoTo flowdone
  314.             'looks like it must be connectable
  315.             TileClr(cur - 1) = 1 'turn the next piece on too
  316.             'Make it the new current char position
  317.             tc = (cur - 1): cur = tc
  318.             'find/set new direction based on character
  319.             If nv$ = VT$ Then direction = 4 'up
  320.             If nv$ = LD$ Then direction = 3 'left
  321.             If nv$ = RD$ Then direction = 1 'right
  322.         End If
  323.      
  324.     Loop
  325.      
  326.     flowdone:
  327.      
  328.     If firstdraw = 0 Then
  329.      
  330.         'draw/colorize board
  331.         For t = 2 To (GridSize * GridSize)
  332.             If TileClr(t) = 1 And TileClr2(t) = 0 Then
  333.                 'show green...
  334.                 SHOW TileVal$(t) + "-grn.png", TileX(t), TileY(t), TileX(t) + TileSize, TileY(t) + TileSize
  335.             End If
  336.             If TileClr(t) = 0 And TileClr2(t) = 1 Then
  337.                 'show white...
  338.                 SHOW TileVal$(t) + "-wht.png", TileX(t), TileY(t), TileX(t) + TileSize, TileY(t) + TileSize
  339.             End If
  340.         Next t
  341.      
  342.     Else
  343.      
  344.         'draw/colorize board
  345.         For t = 2 To (GridSize * GridSize)
  346.             If TileClr(t) = 1 Then
  347.                 tag$ = "-grn.png"
  348.             Else
  349.                 tag$ = "-wht.png"
  350.             End If
  351.             SHOW TileVal$(t) + tag$, TileX(t), TileY(t), TileX(t) + TileSize, TileY(t) + TileSize
  352.         Next t
  353.      
  354.         firstdraw = 0
  355.      
  356.     End If
  357.      
  358.      
  359.     'copy current color values
  360.     For t = 1 To GridSize * GridSize
  361.         TileClr2(t) = TileClr(t)
  362.     Next t
  363.      
  364.      
  365.     '===========
  366.     checkforwin:
  367.     '===========
  368.      
  369.     all = 0
  370.     For w = 1 To (GridSize * GridSize)
  371.         If TileClr(w) = 1 Then all = all + 1
  372.         If TileVal$(w) = BM$ Then all = all + 1 'add any blocks
  373.     Next w
  374.      
  375.     If all = (GridSize * GridSize) Then
  376.      
  377.         ' bplus rewrote this section to fade in the You did it! sign over the gameboard =======================
  378.         ' Solved& has already been loaded after sounds at start of program
  379.         _SndPlay clap&
  380.         snap& = _NewImage(_Width, _Height, 32)
  381.         _PutImage , 0, snap&
  382.         For alph = 0 To 255
  383.             Cls
  384.             _PutImage , snap&, 0 'background
  385.             _SetAlpha alph, , Solved&
  386.             _PutImage (166, 258), Solved&
  387.             _Limit 40 ' 255 frames in 2 secs
  388.             _Display ' damn blinking!!! without this
  389.         Next
  390.         _AutoDisplay '<<<<<< back to not needing _display
  391.         _FreeImage snap&
  392.         ' end of bplus meddling ================================================================================
  393.      
  394.         Level = Level + 1
  395.      
  396.         GridSize = GridSize + 1
  397.      
  398.         If Level > MaxLevel Then Level = 1
  399.      
  400.         If GridSize > MaxGridSize Then
  401.             GridSize = 3 'MaxGridSize  'restart
  402.         End If
  403.      
  404.         GoTo newlevel
  405.      
  406.     End If
  407.      
  408.     Return
  409.      
  410.      
  411.     Sub setmaze ()
  412.      
  413.         If Level = 1 Then
  414.             GridSize = 3
  415.             a$ = "" '3x3 MazeConnect GridSize
  416.             a$ = a$ + "hzrdru"
  417.             a$ = a$ + "hzhzhz"
  418.             a$ = a$ + "ldluld"
  419.         End If
  420.      
  421.         If Level = 2 Then
  422.             GridSize = 4
  423.             a$ = "" '4x4 MazeConnect GridSize
  424.             a$ = a$ + "vtvtruru"
  425.             a$ = a$ + "rdvtluhz"
  426.             a$ = a$ + "hzrdruhz"
  427.             a$ = a$ + "ldluldlu"
  428.         End If
  429.      
  430.         If Level = 3 Then
  431.             GridSize = 5
  432.             a$ = "" '5x5 MazeConnect GridSize
  433.             a$ = a$ + "hzrdvtvtld"
  434.             a$ = a$ + "hzhzrdrdhz"
  435.             a$ = a$ + "hzhzldhzhz"
  436.             a$ = a$ + "hzldvtluhz"
  437.             a$ = a$ + "ldvtvtvtlu"
  438.         End If
  439.      
  440.         If Level = 4 Then
  441.             GridSize = 6
  442.             a$ = "" '6x6 MazeConnect GridSize
  443.             a$ = a$ + "hzrdrurdvtru"
  444.             a$ = a$ + "hzhzhzhzrdlu"
  445.             a$ = a$ + "ldluhzhzldru"
  446.             a$ = a$ + "rdvtluhzbmhz"
  447.             a$ = a$ + "hzrdruldruhz"
  448.             a$ = a$ + "ldluldvtlulu"
  449.         End If
  450.      
  451.         If Level = 5 Then
  452.             GridSize = 7
  453.             a$ = "" '7x7 MazeConnect GridSize
  454.             a$ = "vtruvtvtrurdru"
  455.             a$ = a$ + "rdlurdruldluhz"
  456.             a$ = a$ + "ldvtluldrurdlu"
  457.             a$ = a$ + "rdvtrurdluldru"
  458.             a$ = a$ + "ldruldlurdvtlu"
  459.             a$ = a$ + "rdlurdruldvtru"
  460.             a$ = a$ + "ldvtluldvtvtlu"
  461.         End If
  462.      
  463.         If Level = 6 Then
  464.             GridSize = 8
  465.             a$ = "" '8x8 MazeConnect GridSize
  466.             a$ = a$ + "hzvtrurdrurdrubm"
  467.             a$ = a$ + "hzbmldluhzhzldru"
  468.             a$ = a$ + "ldvtrurdluhzrdlu"
  469.             a$ = a$ + "rdvtluldvtluldru"
  470.             a$ = a$ + "ldrurdvtrurdvtlu"
  471.             a$ = a$ + "bmhzhzbmldlurdru"
  472.             a$ = a$ + "rdluldvtvtvtluhz"
  473.             a$ = a$ + "ldvtvtvtvtvtvtlu"
  474.         End If
  475.      
  476.         If Level = 7 Then
  477.             GridSize = 9
  478.             a$ = "" '9x9 MazeConnect GridSize
  479.             a$ = a$ + "hzrdvtvtrurdrurdru"
  480.             a$ = a$ + "hzldvtruldluldluhz"
  481.             a$ = a$ + "ldvtruldrubmrdvtlu"
  482.             a$ = a$ + "rdruldruldruldrubm"
  483.             a$ = a$ + "hzldruldruldruldru"
  484.             a$ = a$ + "ldruhzbmldruhzbmhz"
  485.             a$ = a$ + "rdluldvtvtluldruhz"
  486.             a$ = a$ + "hzrdrurdvtrurdluhz"
  487.             a$ = a$ + "ldluldlubmldluvtlu"
  488.         End If
  489.      
  490.         If Level = 8 Then
  491.             GridSize = 10
  492.             a$ = "" '10x10 MazeConnect GridSize
  493.             a$ = a$ + "vtvtvtrurdrurdvtrubm"
  494.             a$ = a$ + "hzrdvtluhzhzldruldru"
  495.             a$ = a$ + "hzldvtvtluldruhzrdlu"
  496.             a$ = a$ + "hzbmrdvtvtruldluldru"
  497.             a$ = a$ + "hzrdlurdruhzrdvtvtlu"
  498.             a$ = a$ + "hzhzrdluhzldlurdrubm"
  499.             a$ = a$ + "hzhzhzbmldrubmhzldru"
  500.             a$ = a$ + "hzldlurdruldvtlurdlu"
  501.             a$ = a$ + "hzrdruhzldrurdruldru"
  502.             a$ = a$ + "ldluldlubmldluldvtlu"
  503.         End If
  504.      
  505.         If Level = 9 Then
  506.             GridSize = 11
  507.             a$ = "" '11x11 MazeConnect GridSize
  508.             a$ = a$ + "hzvtrubmrdvtrubmrdvtru"
  509.             a$ = a$ + "ldruldruldruldruldruhz"
  510.             a$ = a$ + "bmldruldruldruldruhzhz"
  511.             a$ = a$ + "rdruldruldruldruldluhz"
  512.             a$ = a$ + "hzldruldruldruldrurdlu"
  513.             a$ = a$ + "ldruldruldruldruhzldru"
  514.             a$ = a$ + "bmldruldruldruldlurdlu"
  515.             a$ = a$ + "rdruldruldruldrurdlubm"
  516.             a$ = a$ + "hzldruldruldvtluldvtru"
  517.             a$ = a$ + "ldruldvtlurdrurdrurdlu"
  518.             a$ = a$ + "bmldvtvtvtluldluldlubm"
  519.         End If
  520.      
  521.         If Level = 10 Then
  522.             GridSize = 12
  523.             a$ = "" '12x12 MazeConnect GridSize
  524.             a$ = a$ + "vtvtrubmbmrdrurdrurdvtru"
  525.             a$ = a$ + "bmbmhzbmrdluldluhzhzrdlu"
  526.             a$ = a$ + "bmrdlurdlurdrurdluhzldru"
  527.             a$ = a$ + "rdlurdlurdluhzhzrdlurdlu"
  528.             a$ = a$ + "ldruldvtlurdluhzhzbmldru"
  529.             a$ = a$ + "bmldvtvtruhzbmldlurdvtlu"
  530.             a$ = a$ + "rdvtvtvtluhzrdvtvtlurdru"
  531.             a$ = a$ + "ldrurdvtvtluhzrdvtvtluhz"
  532.             a$ = a$ + "rdluhzbmbmbmldlurdrurdlu"
  533.             a$ = a$ + "hzrdlurdrurdrubmhzhzhzbm"
  534.             a$ = a$ + "ldlurdluhzhzhzrdluhzldru"
  535.             a$ = a$ + "vtvtlubmldluldlubmldvtlu"
  536.         End If
  537.      
  538.         If Level = 11 Then
  539.             GridSize = 13
  540.             a$ = "" '13x13 MazeConnect GridSize
  541.             a$ = a$ + "hzvtvtvtvtvtrurdrurdrurdru"
  542.             a$ = a$ + "hzrdrurdvtruldluhzhzldluhz"
  543.             a$ = a$ + "hzhzhzhzspldvtruhzhzrdruhz"
  544.             a$ = a$ + "hzhzhzldrubmrdluldluhzhzhz"
  545.             a$ = a$ + "hzhzldvtlurdlurdvtvtluldlu"
  546.             a$ = a$ + "hzldrubmrdlubmldvtvtrurdru"
  547.             a$ = a$ + "ldruldruhzbmbmbmrdruhzhzhz"
  548.             a$ = a$ + "rdlurdluldrubmrdluhzldluhz"
  549.             a$ = a$ + "hzrdlurdruldvtlurdlubmrdlu"
  550.             a$ = a$ + "hzldruhzldrurdvtlurdruldru"
  551.             a$ = a$ + "hzrdluhzbmldlurdvtluhzrdlu"
  552.             a$ = a$ + "hzhzrdlurdvtruhzrdvtluldru"
  553.             a$ = a$ + "ldluldvtlubmldluldvtvtvtlu"
  554.         End If
  555.      
  556.         If Level = 12 Then
  557.             GridSize = 14
  558.             a$ = "" '14x14 MazeConnect GridSize
  559.             a$ = a$ + "hzrdrurdvtvtrurdrurdvtvtrubm"
  560.             a$ = a$ + "hzhzhzldvtruhzhzhzhzrdruhzbm"
  561.             a$ = a$ + "ldluhzrdruhzldluldluhzhzhzbm"
  562.             a$ = a$ + "rdruhzhzhzldvtvtvtruhzldlubm"
  563.             a$ = a$ + "hzhzhzhzhzrdrurdruhzldvtrubm"
  564.             a$ = a$ + "hzhzhzhzhzhzhzhzhzhzrdruldru"
  565.             a$ = a$ + "hzhzldluhzhzhzhzhzhzhzldvtlu"
  566.             a$ = a$ + "hzldvtruhzhzhzhzhzhzldrurdru"
  567.             a$ = a$ + "hzrdruhzldluhzhzhzhzbmldluhz"
  568.             a$ = a$ + "ldluhzldvtruhzhzhzhzrdrurdlu"
  569.             a$ = a$ + "rdruhzrdvtluhzhzldluhzhzhzbm"
  570.             a$ = a$ + "hzldluldvtvtluhzrdvtluhzhzbm"
  571.             a$ = a$ + "hzvtvtvtvtvtvtluldrurdluhzbm"
  572.             a$ = a$ + "ldvtvtvtvtvtvtvtvtluldvtlubm"
  573.         End If
  574.      
  575.         If Level = 13 Then
  576.             GridSize = 15
  577.             a$ = "" '15x15 MazeConnect GridSize
  578.             a$ = a$ + "vtvtrurdrurdrurdrubmrdvtvtvtru"
  579.             a$ = a$ + "vtruldluhzhzldluldvtlurdvtruhz"
  580.             a$ = a$ + "rdlubmbmhzldvtvtrurdvtlubmldlu"
  581.             a$ = a$ + "ldrurdruhzbmrdruhzldrurdvtvtru"
  582.             a$ = a$ + "bmhzhzldlurdluhzldruldlurdvtlu"
  583.             a$ = a$ + "rdluldrurdlubmhzrdlurdruldrubm"
  584.             a$ = a$ + "ldrubmldlurdruldlubmhzhzbmldru"
  585.             a$ = a$ + "rdlurdvtvtluldrurdruhzhzrdvtlu"
  586.             a$ = a$ + "ldvtlurdvtvtvtluhzldluhzldvtru"
  587.             a$ = a$ + "rdvtvtlurdvtvtruldrurdlurdruhz"
  588.             a$ = a$ + "ldvtrurdlubmrdlurdluhzrdluldlu"
  589.             a$ = a$ + "rdvtluldrurdlurdlurdluhzbmrdru"
  590.             a$ = a$ + "ldvtrurdluhzbmldruldruldvtluhz"
  591.             a$ = a$ + "rdvtluldruhzrdruldruldvtrurdlu"
  592.             a$ = a$ + "ldvtvtvtluldluldvtlubmbmldlubm"
  593.         End If
  594.      
  595.         dd = 1
  596.         For s = 1 To Len(a$) Step 2
  597.             b$ = Mid$(a$, s, 2)
  598.             If b$ = "vt" Then rotate dd, 1
  599.             If b$ = "hz" Then rotate dd, 1
  600.             If b$ = "ld" Then rotate dd, 2
  601.             If b$ = "lu" Then rotate dd, 2
  602.             If b$ = "rd" Then rotate dd, 2
  603.             If b$ = "ru" Then rotate dd, 2
  604.             If b$ = "bm" Then TileVal$(dd) = BM$
  605.      
  606.             dd = dd + 1
  607.         Next s
  608.      
  609.     End Sub
  610.      
  611.     Sub rotate (num, typ)
  612.      
  613.         'there are only two types of rotating characters,
  614.         'straight lines, or right angles...
  615.      
  616.         'randomly rotate straight character
  617.         If typ = 1 Then
  618.             If Int(Rnd * 2) = 0 Then
  619.                 TileVal$(num) = VT$
  620.             Else
  621.                 TileVal$(num) = HZ$
  622.             End If
  623.         End If
  624.      
  625.         'randomly rotate right angles...
  626.         If typ = 2 Then
  627.             rn = Int(Rnd * 4) + 1
  628.             If rn = 1 Then TileVal$(num) = LD$
  629.             If rn = 2 Then TileVal$(num) = LU$
  630.             If rn = 3 Then TileVal$(num) = RD$
  631.             If rn = 4 Then TileVal$(num) = RU$
  632.         End If
  633.      
  634.     End Sub
  635.      
  636.     Sub SHOW (i$, x1, y1, x2, y2)
  637.         'Just a little sub to load & put an image at x1/y1
  638.         ttmp = _LoadImage(i$)
  639.         _PutImage (x1, y1)-(x2, y2), ttmp
  640.         _FreeImage ttmp
  641.     End Sub
  642.      
  643.     Sub PPRINT (x, y, size, clr&, trans&, text$)
  644.         'This sub outputs to the current _DEST set
  645.         'It makes trans& the transparent color
  646.      
  647.         'x/y is where to print text
  648.         'size is the font size to use
  649.         'clr& is the color of your text
  650.         'trans& is the background transparent color
  651.         'text$ is the string to print
  652.      
  653.         '=== get users current write screen
  654.         orig& = _Dest
  655.      
  656.         '=== if you are using an 8 or 32 bit screen
  657.         bit = 32: If _PixelSize(0) = 1 Then bit = 256
  658.      
  659.         '=== step through your text
  660.         For t = 0 To Len(text$) - 1
  661.             '=== make a temp screen to use
  662.             pprintimg& = _NewImage(16, 16, bit)
  663.             _Dest pprintimg&
  664.             '=== set colors and print text
  665.             Cls , trans&: Color clr&
  666.             Print Mid$(text$, t + 1, 1);
  667.             '== make background color the transprent one
  668.             _ClearColor _RGB(0, 0, 0), pprintimg&
  669.             '=== go back to original screen  to output
  670.             _Dest orig&
  671.             '=== set it and forget it
  672.             x1 = x + (t * size): x2 = x1 + size
  673.             y1 = y: y2 = y + size
  674.             _PutImage (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  675.             _FreeImage pprintimg&
  676.         Next
  677.     End Sub
  678.  
  679.  

Attachments:

 

PipesPuzzle.jpg

Author's previous version for rerefence:https://www.qb64.org/foru/index.php?topic=2094.msg113243#msg113243
« Last Edit: October 16, 2021, 05:45:45 am by Junior Librarian »