Author Topic: Tents & Trees Puzzle clone  (Read 3320 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Tents & Trees Puzzle clone
« on: February 06, 2021, 05:26:54 pm »
Started playing this addictive puzzle game called Tents & Trees, had to make one in QB64 today.

You put tents next to trees, and try to match the correct number of tents allowed for each row and column (their numbers shown on side).  Click on an empty square to add a tent there.  Each tree much have a tent next to it.  If too many tents, row/col the number turns red.  If the correct number, they turn green.  Turn all row/col numbers green. Tents cannot touch other tents or they will turn red. 

- Dav

Updated 2/7/2021: 10 levels now.
Code: QB64: [Select]
  1. '=========
  2. 'TENTS.BAS v0.30
  3. '==========
  4. 'Tents & Trees puzzle clone.
  5. 'Coded by Dav, FEB/2021
  6.  
  7. 'Added: 10 levels. Navigate levels with left/right arrows
  8. 'Added: Current level shown in title bar
  9. 'Added: _ICON _DISPLAY for instant program icon
  10. 'Fixed: Reorganized how the board updates/draws.
  11. 'Fixed: Touching tent conflicts now shown instantly
  12.  
  13. '===========
  14. 'HOW TO PLAY:
  15. '===========
  16.  
  17. 'Click on blank squares to place tent next a tree.
  18. 'Every tree must have a tent next to it.
  19. 'However, tents cannot be next to other tents.
  20. 'If tents are touching, they will turn red.
  21. 'Numbers on side tell how many tents each row needs.
  22. 'When the right number is reach, number turns green.
  23. 'Too many tents in the row/col, number turns red.
  24.  
  25. 'when all numbers turn green, and no tents are red,
  26. 'then the puzzle is completed.
  27.  
  28. 'Pressing SPACE will retart level.
  29. 'Use Left/Right Arrows to navigate to other levels
  30.  
  31. '======================================================
  32.  
  33. REDIM SHARED grid, tiles
  34.  
  35. grid = 9 '9x9 grid size (8 for tiles, 1 for number row/col)
  36. tiles = grid * grid '  total number of tiles on board
  37.  
  38. SCREEN _NEWIMAGE(75 * grid, 75 * grid, 32)
  39.  
  40. REDIM SHARED tilev(tiles), tilem(tiles)
  41. REDIM SHARED tilex(tiles), tiley(tiles)
  42.  
  43. 'Make the images
  44. tree& = BASIMAGE1&
  45. tent& = BASIMAGE2&
  46. blank& = BASIMAGE3&
  47.  
  48. Level = 1
  49. LevelMax = 10
  50.  
  51. '======
  52. Restart:
  53. '======
  54.  
  55. _TITLE "Tents: Level " + STR$(Level) + " of " + STR$(LevelMax)
  56.  
  57. CLS , _RGB(77, 77, 77)
  58.  
  59. GOSUB SetLevel
  60.  
  61. 'init values
  62. bc = 1
  63. FOR x = 1 TO grid
  64.     FOR y = 1 TO grid
  65.         tilex(bc) = (x * 75) - 75: tiley(bc) = (y * 75) - 75
  66.         tilev(bc) = VAL(MID$(lev$, bc, 1))
  67.         tilem(bc) = 0
  68.         bc = bc + 1
  69.     NEXT
  70.  
  71. GOSUB DrawBoard
  72.  
  73. '=======
  74. MainLoop:
  75. '=======
  76.  
  77.     'wait until mouse button up to continue
  78.     WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  79.  
  80.     trap = _MOUSEINPUT
  81.         mx = _MOUSEX: my = _MOUSEY
  82.  
  83.         'cycle through tiles
  84.         FOR t = 1 TO tiles
  85.  
  86.             'skip the numbers sides
  87.             SELECT CASE t
  88.                 CASE 1 TO 10, 19, 28, 37, 46, 55, 64, 73: GOTO skip
  89.             END SELECT
  90.  
  91.             tx = tilex(t): tx2 = tilex(t) + 75
  92.             ty = tiley(t): ty2 = tiley(t) + 75
  93.  
  94.             'if you clicked on a tile
  95.             IF mx >= tx AND mx <= tx2 THEN
  96.                 IF my >= ty AND my <= ty2 THEN
  97.  
  98.                     SELECT CASE tilev(t)
  99.                         CASE 7: _PUTIMAGE (tilex(t), tiley(t)), tent&: tilev(t) = 9
  100.                         CASE 9: _PUTIMAGE (tilex(t), tiley(t)), blank&: tilev(t) = 7
  101.                     END SELECT
  102.  
  103.                     'check for win, see if tent tally matches
  104.                     win = 1
  105.                     FOR row = 2 TO 9
  106.                         IF RowTally(row) <> tilev(row) THEN win = 0
  107.                     NEXT
  108.                     FOR col = 10 TO tiles STEP 9
  109.                         IF ColTally(col) <> tilev(col) THEN win = 0
  110.                     NEXT
  111.  
  112.                     'See if there's any conflicting tents
  113.                     FOR r = 1 TO tiles
  114.                         IF tilev(r) = 9 THEN
  115.                             IF Touching(r) THEN
  116.                                 tilem(r) = 1
  117.                                 win = 0
  118.                             ELSE
  119.                                 tilem(r) = 0
  120.                             END IF
  121.                         END IF
  122.                     NEXT
  123.  
  124.                     'If all still good, you won
  125.                     IF win = 1 THEN
  126.                         GOSUB DrawBoard
  127.                         PLAY "mbl8o2go3cel4gl8el2g": _DELAY 3
  128.                         Level = Level + 1
  129.                         IF Level > LevelMax THEN Level = 1
  130.                         GOTO Restart
  131.                     END IF
  132.  
  133.                 END IF
  134.  
  135.             END IF
  136.             skip:
  137.         NEXT
  138.  
  139.         GOSUB DrawBoard
  140.  
  141.     END IF
  142.  
  143.     K$ = INKEY$ 'Check for a keypress
  144.     'Right arrows advance to next level
  145.     IF K$ = CHR$(0) + CHR$(77) THEN
  146.         Level = Level + 1
  147.         IF Level > LevelMax THEN Level = 1
  148.         GOTO Restart
  149.     END IF
  150.     'Left Arrows go back a level
  151.     IF K$ = CHR$(0) + CHR$(75) THEN
  152.         Level = Level - 1
  153.         IF Level < 1 THEN Level = LevelMax
  154.         GOTO Restart
  155.     END IF
  156.     'space restarts level
  157.     IF K$ = CHR$(32) THEN GOTO Restart
  158.     'ESC ends game
  159.     IF K$ = CHR$(27) THEN SYSTEM
  160.  
  161.  
  162.  
  163.  
  164. '========
  165. DrawBoard:
  166. '========
  167.  
  168. bc = 1
  169. FOR x = 1 TO grid
  170.     FOR y = 1 TO grid
  171.         SELECT CASE bc
  172.             CASE 1: 'skip this corner
  173.             CASE 2 TO 10, 19, 28, 37, 46, 55, 64, 73
  174.                 PPRINT tilex(bc), tiley(bc) + 10, 45, _RGB(128, 128, 128), 0, STR$(tilev(bc))
  175.             CASE ELSE
  176.                 IF tilev(bc) = 7 THEN _PUTIMAGE (tilex(bc), tiley(bc)), blank&
  177.                 IF tilev(bc) = 8 THEN _PUTIMAGE (tilex(bc), tiley(bc)), tree&
  178.                 IF tilev(bc) = 9 THEN
  179.                     _PUTIMAGE (tilex(bc), tiley(bc)), tent&
  180.                     IF tilem(bc) = 1 THEN
  181.                         LINE (tilex(bc), tiley(bc))-(tilex(bc) + 75, tiley(bc) + 75), _RGBA(255, 0, 0, 100), BF
  182.                     END IF
  183.                 END IF
  184.         END SELECT
  185.         bc = bc + 1
  186.     NEXT
  187.  
  188. 'Update numbers in row
  189. FOR row = 2 TO 9
  190.     SELECT CASE RowTally(row)
  191.         CASE IS > tilev(row): 'red
  192.             PPRINT tilex(row), tiley(row) + 10, 45, _RGB(255, 0, 0), 0, STR$(tilev(row))
  193.         CASE IS = tilev(row): 'green
  194.             PPRINT tilex(row), tiley(row) + 10, 45, _RGB(0, 255, 0), 0, STR$(tilev(row))
  195.         CASE IS < tilev(row): 'normal
  196.             PPRINT tilex(row), tiley(row) + 10, 45, _RGB(128, 128, 128), 0, STR$(tilev(row))
  197.     END SELECT
  198. 'Update numbers in cols
  199. FOR col = 10 TO tiles STEP 9
  200.     SELECT CASE ColTally(col)
  201.         CASE IS > tilev(col): 'red
  202.             PPRINT tilex(col), tiley(col) + 10, 45, _RGB(255, 0, 0), 0, STR$(tilev(col))
  203.         CASE IS = tilev(col): 'green
  204.             PPRINT tilex(col), tiley(col) + 10, 45, _RGB(0, 255, 0), 0, STR$(tilev(col))
  205.         CASE IS < tilev(col): 'normal
  206.             PPRINT tilex(col), tiley(col) + 10, 45, _RGB(128, 128, 128), 0, STR$(tilev(col))
  207.     END SELECT
  208.  
  209.  
  210.  
  211. '==================================================================
  212.  
  213. '=======
  214. SetLevel:
  215. '=======
  216. SELECT CASE Level
  217.     CASE 1: lev$ = "012031302278877777177777878277777777177778777"
  218.         lev$ = lev$ + "178778777177777777278777887277877787"
  219.     CASE 2: lev$ = "031120122278777787187777777277877778177778777"
  220.         lev$ = lev$ + "277777777087787887377877777177777787"
  221.     CASE 3: lev$ = "021212040177877777287778877278777777177777778"
  222.         lev$ = lev$ + "278777787177778777178877777277777877"
  223.     CASE 4: lev$ = "021111312177788778377777777187778777187788787"
  224.         lev$ = lev$ + "377777777077777877287777777177777787"
  225.     CASE 5: lev$ = "021211212177787777277777777178788887277777777"
  226.         lev$ = lev$ + "177777777187777778177877787378778777"
  227.     CASE 6: lev$ = "021121122277777777278778778177877777177777887"
  228.         lev$ = lev$ + "277887777177777777177877788278777777"
  229.     CASE 7: lev$ = "012112122177777777287777787177787778378777878"
  230.         lev$ = lev$ + "177878777177777778277877877177777777"
  231.     CASE 8: lev$ = "021211212277787777187778777178777877277777777"
  232.         lev$ = lev$ + "278778778177778777177777787277877787"
  233.     CASE 9: lev$ = "011212113377777777077878778278778777277778778"
  234.         lev$ = lev$ + "177777877087777778277777777277787877"
  235.     CASE 10: lev$ = "012121122278787778177777777177777787177777777"
  236.         lev$ = lev$ + "378788777177787778177787877277877777"
  237.  
  238.  
  239. '==================================================================
  240.  
  241. FUNCTION RowTally (row)
  242.     DoNum = row 'how many for all done
  243.     Count = 0
  244.     FOR t = row + 9 TO tiles STEP grid
  245.         IF tilev(t) = 9 THEN Count = Count + 1
  246.     NEXT
  247.     RowTally = Count
  248.  
  249. '==================================================================
  250.  
  251. FUNCTION ColTally (col)
  252.     DoNum = tilev(col)
  253.     Count = 0
  254.     FOR t = col + 1 TO col + 8
  255.         IF tilev(t) = 9 THEN Count = Count + 1
  256.     NEXT
  257.     ColTally = Count
  258.  
  259. '==================================================================
  260.  
  261. FUNCTION Touching (num)
  262.  
  263.     'returns if given tent num is touching another
  264.  
  265.     Touching = 0
  266.  
  267.     SELECT CASE num
  268.         CASE 11 'top left corner
  269.             IF tilev(num + 1) = 9 THEN Touching = 1
  270.             IF tilev(num + 9) = 9 THEN Touching = 1
  271.             IF tilev(num + 10) = 9 THEN Touching = 1
  272.         CASE 18 'bottom left corner
  273.             IF tilev(num - 1) = 9 THEN Touching = 1
  274.             IF tilev(num + 8) = 9 THEN Touching = 1
  275.             IF tilev(num + 9) = 9 THEN Touching = 1
  276.         CASE 74 'top right corner
  277.             IF tilev(num + 1) = 9 THEN Touching = 1
  278.             IF tilev(num - 8) = 9 THEN Touching = 1
  279.             IF tilev(num - 9) = 9 THEN Touching = 1
  280.         CASE 81 'bottom right corner
  281.             IF tilev(num - 1) = 9 THEN Touching = 1
  282.             IF tilev(num - 9) = 9 THEN Touching = 1
  283.             IF tilev(num - 10) = 9 THEN Touching = 1
  284.         CASE 20, 29, 38, 47, 56, 65 'top row, 20 to 65
  285.             IF tilev(num + 1) = 9 THEN Touching = 1
  286.             IF tilev(num - 9) = 9 THEN Touching = 1
  287.             IF tilev(num + 9) = 9 THEN Touching = 1
  288.         CASE 27, 36, 45, 54, 63, 72 'bottom row, 27 to 72
  289.             IF tilev(num - 1) = 9 THEN Touching = 1
  290.             IF tilev(num - 9) = 9 THEN Touching = 1
  291.             IF tilev(num + 9) = 9 THEN Touching = 1
  292.         CASE 12 TO 17 'left side, 12 to 17
  293.             IF tilev(num - 1) = 9 THEN Touching = 1
  294.             IF tilev(num + 1) = 9 THEN Touching = 1
  295.             IF tilev(num + 8) = 9 THEN Touching = 1
  296.             IF tilev(num + 9) = 9 THEN Touching = 1
  297.             IF tilev(num + 10) = 9 THEN Touching = 1
  298.         CASE 75 TO 80 'right side
  299.             IF tilev(num - 1) = 9 THEN Touching = 1
  300.             IF tilev(num + 1) = 9 THEN Touching = 1
  301.             IF tilev(num - 8) = 9 THEN Touching = 1
  302.             IF tilev(num - 9) = 9 THEN Touching = 1
  303.             IF tilev(num - 10) = 9 THEN Touching = 1
  304.         CASE 21 TO 26, 30 TO 35, 39 TO 44, 48 TO 53, 56 TO 61, 66 TO 70 'rest of board
  305.             IF tilev(num - 1) = 9 THEN Touching = 1
  306.             IF tilev(num + 1) = 9 THEN Touching = 1
  307.             IF tilev(num - 8) = 9 THEN Touching = 1
  308.             IF tilev(num + 8) = 9 THEN Touching = 1
  309.             IF tilev(num - 9) = 9 THEN Touching = 1
  310.             IF tilev(num + 9) = 9 THEN Touching = 1
  311.             IF tilev(num - 10) = 9 THEN Touching = 1
  312.             IF tilev(num + 10) = 9 THEN Touching = 1
  313.     END SELECT
  314.  
  315.  
  316. '=======================================================================
  317.  
  318. FUNCTION BASIMAGE1& 'tree.png
  319.     v& = _NEWIMAGE(75, 75, 32)
  320.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  321.     A$ = ""
  322.     A$ = A$ + "haIkL_SD343360N;YTB:cAQ:ZYRc2UL0h2#77P];GPDc#572Zc=`4W9NaIO5"
  323.     A$ = A$ + "KI9mkMG5?JPQQRT_8ITLfUVV6GS5F8DlmYe7fJ`jgC[nFioi?mecFd;fOJIF"
  324.     A$ = A$ + "IF]E\jMgWW3d??ZM[naM\kiRok[5cZ=[jL:\R<c\J2WNiBdn_IXmZF\JDWRS"
  325.     A$ = A$ + "8_#ECF3FMCWji5ZL<dFU\CCDCZI>6B[bf9`iHX\bW?#f9#iHX\Z;WZ]0[D>7"
  326.     A$ = A$ + "3QE5EkUH>fJ`:ALBYN;dd:aMBhJB]\BLWJS2ge_Nh:oB3[^bYfI2ZndcVhJ#"
  327.     A$ = A$ + ">[3UfZ^N3B9ba[fY]AZN7d8_:ne#LhOmiODJoXn7BH32[V]^\dm`Dl<8PgO5"
  328.     A$ = A$ + "SmR:]G[Vn[D`;]\:\odB]?D]\R]mVb`;9baTf:fgK:U#XI3Ud:eVYAYm`T`:"
  329.     A$ = A$ + "EfK2PGLKUZk=Y\GLJeP?K_iVmSj<P0mR;[bJ^?Zc0B=j=S=E_h<_JZinHM6`"
  330.     A$ = A$ + "DMIVcPPjid0i\nTdYALYoI##]?E8WeWTeMAWm`Bll[D_o1QV=DUNAAdo`5_F"
  331.     A$ = A$ + "2iE#V]ITm^ZmILFSm\c]EEe\=2h5GFEUcf`\GLH5lmVDb[B\Z:[i4d;ZFEee"
  332.     A$ = A$ + "L9hUFch\8ZiV::XGRL]:i?_M>R:[F<7[8O^;D39OoPPGiVGUbi^#92WCc37L"
  333.     A$ = A$ + "^kOkhi_Zek9Y^g5j[3ihlE_?gmh[MQg\h8hGlI8`A8mO7D2[lN4KeHA`;4g?"
  334.     A$ = A$ + "0ePEQoNA:FioMfZF=Emg]\J;NOCTCm7jj#dFUCm7jj#TFUKmgFf::iD8gc2m"
  335.     A$ = A$ + "mSC^iD8gc2]EiVCQ\>4meFKYFYIM82[:]n3EM8B[XVCQZ>4ie\=GF]F__D3i"
  336.     A$ = A$ + "DkL^1WS0UHWC_j#DFQj<XFBF5lRk#JW#IeB=<[<[<[<[F:aHFiooMhNK=HeM"
  337.     A$ = A$ + "mCKQ525o1`aF%%h1"
  338.     btemp$ = ""
  339.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  340.         IF INSTR(1, B$, "%") THEN
  341.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  342.                 IF F$ <> "%" THEN C$ = C$ + F$
  343.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  344.             IF MID$(B$, j, 1) = "#" THEN
  345.         MID$(B$, j) = "@": END IF: NEXT
  346.         FOR t% = LEN(B$) TO 1 STEP -1
  347.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  348.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  349.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  350.     NEXT: btemp$ = btemp$ + X$: NEXT
  351.     btemp$ = _INFLATE$(btemp$)
  352.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  353.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  354.  
  355. '==================================================================
  356.  
  357. FUNCTION BASIMAGE2& 'tent.png
  358.     v& = _NEWIMAGE(75, 75, 32)
  359.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  360.     A$ = ""
  361.     A$ = A$ + "haIkL^SC33455e5D#9UDb2Q2ZXVU3U\0H3#7kQ\1X6A5;2ZI7HbHY15iHLNo"
  362.     A$ = A$ + "O?7^IdEb:FAJdaWkX9fAIHHHL01aYlana;HLdh[mSi\Zmngon38cb^m3`:`:"
  363.     A$ = A$ + "`:`Z]#0[0[0[0[f:1\jlPE??njDbNNDMFmihgo>OJ7WmlYZ\ZiB]iae_=>Uf"
  364.     A$ = A$ + "aE`_Z8[j>eE?mmDZRKE=FMXCMiM?>UZhFESE7jDMFE5gZB\J9WZB^EUHeB>E"
  365.     A$ = A$ + "UL[Z`ZeLZi^EFlZ:\J=WZ:Ma:`Z>WFcYZ#G<KFAYkE5g:KFA]kE1g:CF9aYb"
  366.     A$ = A$ + "LMn<IU4W:c^HF\BSCUEG<;FYeYb`]bPEDM::L<Bg:3FAaYJWkRK^U4_Rb]RV"
  367.     A$ = A$ + "EDggIklDIED^ET\RCg[aYFX^fO4kQ8BFaikleI5Eg:R^HD\BRCae]l^;65[X"
  368.     A$ = A$ + "jD;aZZhFA`:>kkLNoS;[ld]RPEJM:>m#?GWgKFaiNCmG>5Ggb[^XW\RCgK=W"
  369.     A$ = A$ + "BRKiAGdCFaiklAQEIkFNa:^g7QCeoT`:[M;_HU7>5gNXe^U7\b;W:Kgb3FiU"
  370.     A$ = A$ + "CYe]db;[I5GWB2[hjFFe5]VEL_OWLkOBIU5MA;I5WmMZaYTd3]`]\REBOVXB"
  371.     A$ = A$ + "IE6^UE\RKgCSCIQK9QGF`:9>U5\BRKYY;J1[Tll[dfod`:YMA]\:CWBJ?DZK"
  372.     A$ = A$ + "YUEIjDAkFJHEkJ2g[]FjDFhF]??EgB3[JGCjcen_5mC5[MZ3i5ei`li2EgB:"
  373.     A$ = A$ + "[j>eiBXhFJkPW;9Refo?5`:`:`:`Z]B0[0[0[0[f:1\2\2\2\J[TUHEkok`M"
  374.     A$ = A$ + "HLdXmJ>[##\<oTS4%%h1"
  375.     btemp$ = ""
  376.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  377.         IF INSTR(1, B$, "%") THEN
  378.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  379.                 IF F$ <> "%" THEN C$ = C$ + F$
  380.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  381.             IF MID$(B$, j, 1) = "#" THEN
  382.         MID$(B$, j) = "@": END IF: NEXT
  383.         FOR t% = LEN(B$) TO 1 STEP -1
  384.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  385.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  386.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  387.     NEXT: btemp$ = btemp$ + X$: NEXT
  388.     btemp$ = _INFLATE$(btemp$)
  389.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  390.     BASIMAGE2& = _COPYIMAGE(v&): _FREEIMAGE v&
  391.  
  392. '==================================================================
  393.  
  394. FUNCTION BASIMAGE3& 'blank.png
  395.     v& = _NEWIMAGE(75, 75, 32)
  396.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  397.     A$ = ""
  398.     A$ = A$ + "haIkL7K3243554dE7adND7GGPX>^f0\CmA84\BSOJCnQC1haHlN8mWjeL?\;"
  399.     A$ = A$ + "kL^M[Fg_ml^fjH>Fa:FaZ2a:Fa:FE9Fa:FaZ:a:Fa:FE9Fa:FaZ:a:Fa:FE9"
  400.     A$ = A$ + "Fa:FaZ:a:Fa:FE9Fa:FaZ:a:Fa:FE9Fa:FaZ:a:Fa:FE9Fa:FaZ:a:Fa:FE9"
  401.     A$ = A$ + "Fa:FaZ:a:Fa:FE9Fa:FaZ:m=[FogQ7fU]NkF9m;k3HFP%%h1"
  402.     btemp$ = ""
  403.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  404.         IF INSTR(1, B$, "%") THEN
  405.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  406.                 IF F$ <> "%" THEN C$ = C$ + F$
  407.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  408.             IF MID$(B$, j, 1) = "#" THEN
  409.         MID$(B$, j) = "@": END IF: NEXT
  410.         FOR t% = LEN(B$) TO 1 STEP -1
  411.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  412.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  413.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  414.     NEXT: btemp$ = btemp$ + X$: NEXT
  415.     btemp$ = _INFLATE$(btemp$)
  416.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  417.     BASIMAGE3& = _COPYIMAGE(v&): _FREEIMAGE v&
  418.  
  419. '==================================================================
  420.  
  421. SUB PPRINT (x, y, size, clr&, trans&, text$)
  422.     orig& = _DEST
  423.     bit = 32: IF _PIXELSIZE(0) = 1 THEN bit = 256
  424.     FOR t = 0 TO LEN(text$) - 1
  425.         pprintimg& = _NEWIMAGE(16, 16, bit)
  426.         _DEST pprintimg&
  427.         CLS , trans&: COLOR clr&
  428.         PRINT MID$(text$, t + 1, 1);
  429.         _CLEARCOLOR _RGB(0, 0, 0), pprintimg&
  430.         _DEST orig&
  431.         x1 = x + (t * size): x2 = x1 + size
  432.         y1 = y: y2 = y + size
  433.         _PUTIMAGE (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  434.         _FREEIMAGE pprintimg&
  435.     NEXT
  436.  

 
tents.jpg
« Last Edit: February 07, 2021, 03:58:17 pm by Dav »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Tents & Trees Puzzle clone
« Reply #1 on: February 06, 2021, 06:11:05 pm »
I love it!

EDIT: Deleted attachment of solution.
« Last Edit: February 06, 2021, 06:12:17 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Tents & Trees Puzzle clone
« Reply #2 on: February 06, 2021, 06:20:17 pm »
Well good job! (I saw it before you deleted it). 

Actually that wouldn't be a correct solution in the real game, tents aren't supposed to touch each other (side or diag), but I haven't coded that checking in yet.  But it's not easy anyway as is, so well done.  And you did it fast.  I see I need to get busy making some hard levels...

- Dav

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Tents & Trees Puzzle clone
« Reply #3 on: February 07, 2021, 09:59:49 am »
Updated the code.  I put in the tent error checking, now the puzzle should play just like the real Tents & Trees puzzle game. It will show you when tents are in conflict so it won't complete.  Makes it a lot harder to solve.

Here's an example of putting the correct number of tents next to trees, but some tents are touching so it's not completed.

- Dav

 
tents2.jpg


Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Tents & Trees Puzzle clone
« Reply #4 on: February 07, 2021, 04:02:44 pm »
Latest update (probably the last too) .  There are now 10 levels of puzzles to figure out.  You can navigate to them with the arrow keys. Space key restarts current level. Esc quits
 
Reorganized the code, conflicting tents are now shown instantly, not just at the end.  The levels are kind of hard, but it should be entertaining.  Enjoy it.  My fun was coding it.

Original code updated at the top.

- Dav