Author Topic: Clone of an old Qbasic puzzle game called INSANE  (Read 5348 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Clone of an old Qbasic puzzle game called INSANE
« on: September 18, 2018, 09:34:55 am »
One of my favorite little games made in the Qbasic heyday was a small puzzle game by 'entropy' called INSANE.  I don't know if entropy ever took it further, but the game was addicting.  I made a QB64 version here, staying true to the original game idea (but my version moves blocks right instead of left).  It's just something to play while waiting for the power to be restored in my area (been out for days now thanks to hurricane florence). 

- Dav

Code: QB64: [Select]
  1. '===============
  2. 'INSANECLONE.BAS
  3. '===============
  4. 'A close clone of Qbasic puzzle game called 'Insane" by entropy.
  5. 'Coded for QB64 by Dav, SEP/2018 during Hurricane Florence (NC).
  6.  
  7. '==============================================================
  8. 'CREDITS: Heavily inspired by Qbasic game "insane" by 'entropy'
  9. '         It's about the same idea, you clear groups of blocks.
  10. '==============================================================
  11.  
  12. '===========
  13. 'HOW TO PLAY:
  14. '===========
  15. '
  16. 'Try to clear the board of groups of color blocks.
  17. 'You click on a group of colors to remove that group.
  18. 'Any Blocks left above will drop down to fill in the holes.
  19. 'Blocks move to the right when a whole column is cleared.
  20.  
  21. 'SPACE key will generate a new puzzle board.
  22. 'ESC key quits.
  23. '==============================================================
  24.  
  25.  
  26. DIM SHARED rows, columns
  27.  
  28. rows = 10: columns = 10: size = 60
  29.  
  30. REDIM SHARED Block(rows, columns)
  31.  
  32. '=== set up screen
  33. SCREEN _NEWIMAGE(rows * size, columns * size, 256)
  34.  
  35. _SCREENMOVE _SCREENX, _SCREENY 'a fix to make _title work
  36. _TITLE "INSANE CLONE v1.0"
  37.  
  38.  
  39. '======
  40. newgame:
  41. '======
  42.  
  43. CLS: LOCATE 16, 31: PRINT "Generating...";
  44.  
  45. 'generate random board colors
  46. FOR r = 1 TO rows
  47.     FOR c = 1 TO columns
  48.         Block(r, c) = INT(RND * 6)
  49.     NEXT c
  50.  
  51. 'make sure there's enough groups present to do puzzle.
  52. 'without this here, it's soooo hard! Really insane...
  53. IF NumberOfGroups < rows * columns - rows THEN GOTO newgame
  54.  
  55. CLS: GOSUB updateboard
  56.  
  57.     DO
  58.         _LIMIT 60
  59.         WHILE _MOUSEINPUT: WEND
  60.  
  61.         K$ = INKEY$
  62.         IF K$ = CHR$(32) THEN GOTO newgame
  63.         IF K$ = CHR$(27) THEN SYSTEM
  64.  
  65.         IF _MOUSEBUTTON(1) THEN
  66.             mx = _MOUSEX: my = _MOUSEY
  67.  
  68.             nm = 0 'block count
  69.             FOR r = 1 TO rows
  70.                 FOR c = 1 TO columns
  71.                     nm = nm + 1
  72.                     bx = (r * size) - size: by = (c * size) - size
  73.                     IF mx >= bx AND mx <= bx + size AND my >= by AND my <= by + size THEN
  74.                         old = Block(r, c) 'block color
  75.  
  76.                         'only do when non black touched
  77.                         IF old <> 6 THEN
  78.                             'only do if a neighbor block color is same
  79.                             nn = 0
  80.                             IF r > 1 THEN
  81.                                 IF Block(r - 1, c) = old THEN nn = 1
  82.                             END IF
  83.                             IF r < rows THEN
  84.                                 IF Block(r + 1, c) = old THEN nn = 1
  85.                             END IF
  86.                             IF c > 1 THEN
  87.                                 IF Block(r, c - 1) = old THEN nn = 1
  88.                             END IF
  89.                             IF c < columns THEN
  90.                                 IF Block(r, c + 1) = old THEN nn = 1
  91.                             END IF
  92.                             'if a group of colors...
  93.                             IF nn = 1 THEN
  94.                                 x = (r * size) - size: y = (c * size) - size
  95.                                 GOTO selected
  96.                             END IF
  97.                         END IF
  98.                     END IF
  99.                 NEXT
  100.             NEXT
  101.  
  102.         END IF
  103.  
  104.     LOOP
  105.  
  106.  
  107.     selected:
  108.  
  109.     'fill the group...
  110.     FloodFill old, 6, r, c
  111.  
  112.     'show blacked out colors
  113.     GOSUB updateboard
  114.  
  115.     'drop down blocks here...
  116.     FOR r = 1 TO rows
  117.         FOR c = columns TO 2 STEP -1
  118.             IF Block(r, c) = 6 THEN
  119.                 FOR c2 = c TO 1 STEP -1
  120.                     IF Block(r, c2) <> 6 THEN EXIT FOR
  121.                 NEXT
  122.                 IF c2 > 0 THEN
  123.                     IF Block(r, c) <> Block(r, c2) THEN moved = 1
  124.                     Block(r, c) = Block(r, c2): Block(r, c2) = 6
  125.                 END IF
  126.             END IF
  127.         NEXT
  128.     NEXT
  129.  
  130.     'move blocks right here...
  131.     FOR r = 1 TO rows - 1
  132.         IF Block(r, columns) = 6 THEN
  133.             FOR r2 = 1 TO rows
  134.                 IF Block(r2, columns) <> 6 THEN EXIT FOR
  135.             NEXT
  136.             FOR c = 1 TO columns
  137.                 IF Block(r, c) <> Block(r2, c) THEN moved = 1
  138.                 Block(r, c) = Block(r2, c): Block(r2, c) = 6
  139.             NEXT
  140.         END IF
  141.     NEXT
  142.  
  143.     'redraw puzzle board
  144.     GOSUB updateboard
  145.  
  146.     'wait until mouse button up to continue
  147.     WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  148.  
  149.     'see if all blocks gone (cleared!)
  150.     h = 0
  151.     FOR r = 1 TO rows
  152.         FOR c = 1 TO columns
  153.             IF Block(r, c) <> 6 THEN h = 1
  154.         NEXT c
  155.     NEXT r
  156.  
  157.     'if board is cleared, then you win...
  158.     IF h = 0 THEN
  159.         LINE (200, 200)-(400, 300), 15, BF
  160.         LINE (202, 202)-(398, 298), _RGB(0, 0, 255), BF
  161.         LOCATE 16, 31: COLOR 15, _RGB(0, 0, 255)
  162.         PRINT "YOU DID IT!!!";
  163.         _DELAY 3
  164.         GOTO newgame
  165.     END IF
  166.  
  167.     'see if any groups presently left
  168.     dn = NumberOfGroups
  169.  
  170.     'if no more groups, end...
  171.     IF NumberOfGroups = 0 THEN
  172.         LINE (200, 200)-(400, 300), 15, BF
  173.         LINE (202, 202)-(398, 298), _RGB(0, 0, 255), BF
  174.         LOCATE 16, 31:: COLOR 15, _RGB(0, 0, 255)
  175.         PRINT "NO GROUPS LEFT!";
  176.         _DELAY 3
  177.         GOTO newgame
  178.     END IF
  179.  
  180.  
  181.  
  182. '=============================================================================
  183.  
  184. '==========
  185. updateboard:
  186. '==========
  187.  
  188. nm = 0
  189. FOR r = 1 TO rows
  190.     FOR c = 1 TO columns
  191.         j = Block(r, c): nm = nm + 1
  192.         IF j = 0 THEN fill = 1
  193.         IF j = 1 THEN fill = 2
  194.         IF j = 2 THEN fill = 3
  195.         IF j = 3 THEN fill = 4
  196.         IF j = 4 THEN fill = 5
  197.         IF j = 5 THEN fill = 6
  198.         IF j = 6 THEN fill = 0
  199.  
  200.         x = (r * size) - size: y = (c * size) - size
  201.  
  202.         LINE (x, y)-(x + size, y + size), fill, BF
  203.         LINE (x, y)-(x + size, y + size), 0, B
  204.  
  205.     NEXT c
  206.  
  207.     _DELAY .025 'add delay for moving effect
  208.  
  209.  
  210.  
  211. '=====================================================
  212.  
  213. FUNCTION NumberOfGroups ()
  214.  
  215.     'returns how many block groups left on board
  216.  
  217.     dn = 0
  218.     FOR r = 1 TO rows
  219.         FOR c = 1 TO columns
  220.             IF Block(r, c) <> 6 THEN
  221.                 IF r > 1 THEN
  222.                     IF Block(r - 1, c) = Block(r, c) THEN dn = dn + 1
  223.                 END IF
  224.                 IF r < rows THEN
  225.                     IF Block(r + 1, c) = Block(r, c) THEN dn = dn + 1
  226.                 END IF
  227.                 IF c > 1 THEN
  228.                     IF Block(r, c - 1) = Block(r, c) THEN dn = dn + 1
  229.                 END IF
  230.                 IF c < columns THEN
  231.                     IF Block(r, c + 1) = Block(r, c) THEN dn = dn + 1
  232.                 END IF
  233.             END IF
  234.         NEXT c
  235.     NEXT r
  236.  
  237.     NumberOfGroups = dn
  238.  
  239.  
  240. '=====================================================
  241.  
  242. SUB FloodFill (old, clr, x, y)
  243.     IF Block(x, y) <> old THEN
  244.         EXIT SUB
  245.     ELSE
  246.         Block(x, y) = clr
  247.     END IF
  248.     IF x > 1 THEN FloodFill old, clr, x - 1, y
  249.     IF x < rows THEN FloodFill old, clr, x + 1, y
  250.     IF y > 1 THEN FloodFill old, clr, x, y - 1
  251.     IF y < columns THEN FloodFill old, clr, x, y + 1
  252.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Clone of an old Qbasic puzzle game called INSANE
« Reply #1 on: September 18, 2018, 12:36:33 pm »
I don't remember this one in QB. What's a win? I keep getting no more color groups left message at some point, but so what?

I know, I don't game so I don't get it.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Clone of an old Qbasic puzzle game called INSANE
« Reply #2 on: September 18, 2018, 12:50:56 pm »
Oh I've learned and programmed this game as "Click-O-Mania" at JB forum.

The object is to clear all the squares by clicking groups of like color in row and/or column, click 1 of 2 red adjacent squares and they will blink away and the squares above will fall down and a whole blank column will move left columns, right now?
Oh Pete should love that!

So a message, no more color groups left, means to move on to next game. You do well if less than what? 8 squares left?

« Last Edit: September 18, 2018, 12:59:54 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Clone of an old Qbasic puzzle game called INSANE
« Reply #3 on: September 18, 2018, 12:58:45 pm »
Clear all the squares is what I thought. In other words a blank screen is a win. I can hack that right now with one line of added code... CLS

I like Dav's peg game, in his other post, better. Did you see the graphics job on that?

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Clone of an old Qbasic puzzle game called INSANE
« Reply #4 on: September 18, 2018, 01:01:19 pm »
Clear all the squares is what I thought. In other words a blank screen is a win. I can hack that right now with one line of added code... CLS

I like Dav's peg game, in his other post, better. Did you see the graphics job on that?

Pete :D


Next up but need lunch first!