Information Technology - Computer Programming - Source Code - Homebrew - Open Source - Software - Hardware - 8 bit - 16 bit - 32 bit - 64 bit - x86 - x64 - DOS - Windows - Linux - Arduino - Embedded - Development - Retro - Vintage - Math - Science - History - Hobby - Beginners - Professionals - Experiment - Research - Study - Fun - Games

ATTENTION NEW USERS: Due to bot traffic, we are forced to manually approve registrations. We get thousands of bots trying to register, causing us to delete registrations in bulk with little ability to filter what is real or not. If you're having trouble getting approved, then send an email to ptrworkmails@gmail.com explaining that you are a real user. Use the same email you're trying to register with. Thank you.

15 Puzzle number game

Share your Express Basic creations here.
Post Reply
admin
Site Admin
Posts: 142
Joined: Wed Feb 22, 2023 6:51 am

15 Puzzle number game

Post by admin »

15 Puzzle

I made this game while testing the new Express Basic release.
It is now included with the download for each edition.
Slide the numbers to the correct order.

Code: Select all

5 CLS: PRINT "15 Puzzle by Gemino Smothers": PRINT
10 LET size = 16: GOSUB 1000
20 FOR i = 0 TO size - 1: LET nl = nl + 1
30 PRINT @(i),: IF nl = 4 THEN LET nl = 0: PRINT
40 NEXT i
50 PRINT: INPUT "SELECT"; sel: IF sel < 1 OR sel > 15 THEN 50
60 FOR i = 0 TO size - 1: IF sel = @(i) THEN LET sel = i: BREAK i
70 NEXT I: LET moves = moves + 1
80 LET top = sel - 4: LET right = sel + 1
90 LET bottom = sel + 4: LET left = sel - 1
100 IF top >= 0 THEN IF @(top) = 0 THEN LET n = top: GOSUB 2000
110 IF right <= size - 1 THEN IF @(right) = 0 THEN LET n = right: GOSUB 2000
120 IF bottom <= size - 1 THEN IF @(bottom) = 0 THEN LET n = bottom: GOSUB 2000
130 IF left >= 0 THEN IF @(left) = 0 THEN LET n = left: GOSUB 2000
140 LET correct = 0
150 FOR i = 0 TO size - 2
160 IF @(i) = i + 1 THEN LET correct = correct + 1
170 NEXT i
180 IF correct = size - 1 THEN PRINT "You win! Moves: ", moves: INPUT "Enter any number to continue...", sel: GOTO 5
190 IF correct < size - 1 THEN CLS: PRINT "Correct: "; correct; " Moves: "; moves: PRINT: GOTO 20
200 END
1000 FOR i = 0 TO size - 1: LET @(i) = 0: NEXT i
1010 LET t = 0: LET i = 0
1020 IF i = 14 THEN LET n = 120 - t: LET @(i) = n: RETURN
1030 FOR f = 0 TO size - 1
1040 LET n = INT(RND * 15) + 1: LET s = 0
1050 FOR c = 0 TO i - 1
1060 IF n = @(c) THEN LET s = 1: BREAK c
1070 NEXT c
1080 IF s = 0 AND @(i) = 0 THEN LET @(i) = n: LET t = t + n: LET i = i + 1
1090 NEXT f
1100 IF i < size - 1 THEN 1020
1110 RETURN
2000 LET t = @(sel): LET @(n) = @(sel): LET @(sel) = 0: RETURN
Post Reply