Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smallish Games
#10
Again Charlie's post causes me to dig into my files Smile

4x4 Sliding Blocks Puzzle: use arrow keys to move the block to fill the hole ie right arrow to slide the block left of hole, up arrow to move block below hole... actually we just have numbers here not tiles.

No fancy graphics in this 34 LOC game:
Code: (Select All)
_Title "Sliding Blocks MOD 4x4 Galileo" 'rev 2019-04-20
Randomize Timer
Dim Shared delta(4)
delta(1) = 4: delta(2) = 1: delta(3) = -1: delta(4) = -4
Dim Shared board$, hole
board$ = "123456789ABCDEF0": solve$ = board$: hole = 16
For i = 1 To 200: move Int(Rnd * 4 + 1): Next
Do
    print_board
    If board$ = solve$ Then Locate 8, 4: Print "solved!": Exit Do
    KH& = _KeyHit
    Select Case KH&
        Case 18432: move 1 'up
        Case 20480: move 4 'down
        Case 19200: move 2 'left
        Case 19712: move 3 'right
    End Select
    _Display
    _Limit 30
Loop
Sub print_board ()
    Cls: Locate 2, 1: Print " ";
    For i = 1 To Len(board$)
        If i = hole Then Print "    "; Else n$ = Right$("  " + Str$(Val("&H" + Mid$(board$, i, 1))) + " ", 4): Print n$;
        If i Mod 4 = 0 Then Print: Print " ";
    Next
    Print
End Sub
Sub move (d)
    newHole = hole + delta(d)
    If newHole >= 1 And newHole <= 16 And (hole Mod 4 = newHole Mod 4) Or Int((hole - 1) / 4) = Int((newHole - 1) / 4) Then
        Mid$(board$, hole, 1) = Mid$(board$, newHole, 1): Mid$(board$, newHole, 1) = "0": hole = newHole
    End If
End Sub

Working the puzzle:
   

Solved:
   
b = b + ...
Reply


Messages In This Thread
Smallish Games - by bplus - 04-25-2022, 10:55 PM
Smallish Games - by bplus - 06-12-2022, 12:01 AM
RE: Smallish Games - by johnno56 - 06-12-2022, 07:43 AM
RE: Smallish Games - by bplus - 01-12-2023, 11:48 PM
RE: Smallish Games - by PhilOfPerth - 01-13-2023, 01:25 AM
RE: Smallish Games - by bplus - 01-13-2023, 03:08 AM
RE: Smallish Games - by bplus - 03-01-2023, 05:19 AM
RE: Smallish Games - by PhilOfPerth - 03-01-2023, 06:49 AM
RE: Smallish Games - by bplus - 03-01-2023, 03:54 PM
RE: Smallish Games - by bplus - 07-14-2023, 08:11 PM
RE: Smallish Games - by bplus - 07-14-2023, 08:27 PM
RE: Smallish Games - by mnrvovrfc - 07-14-2023, 09:47 PM
RE: Smallish Games - by bplus - 05-03-2024, 06:35 PM
RE: Smallish Games - by bplus - 05-30-2024, 12:57 PM
RE: Smallish Games - by JRace - 05-31-2024, 03:44 AM
RE: Smallish Games - by bplus - 05-31-2024, 10:07 AM
RE: Smallish Games - by bplus - 07-17-2024, 05:24 PM
RE: Smallish Games - by Pete - 07-17-2024, 06:51 PM
RE: Smallish Games - by bplus - 09-12-2024, 07:09 PM
RE: Smallish Games - by bplus - 09-13-2024, 09:47 AM



Users browsing this thread: 2 Guest(s)