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



Users browsing this thread: 6 Guest(s)