Again Charlie's post causes me to dig into my files
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:
Working the puzzle:
Solved:
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 + ...