15 puzzle game: Difference between revisions

(Last fix C#. Ideal now :D)
Line 4,617:
(aref *board* (first zpos) (second zpos))))))
(format t "You win!~%"))</syntaxhighlight>
 
=={{header|Craft Basic}}==
[[File:15 puzzle craft basic.png|thumb]]
<syntaxhighlight lang="basic">'15 Puzzle example game
'written in Craft Basic
'by Gemino Smothers 2023
'www.basicgames.xyz
 
define size = 16, correct = 0, moves = 0
define click = 0, start = 0
 
dim list[size]
 
gosub setup
gosub game
 
end
 
sub setup
 
title "15 Puzzle"
 
resize 0, 0, 170, 250
center
 
bgcolor 0,128,0
cls
 
let x = 0
let y = 30
let i = 0
 
do
 
if x = 112 then
 
let x = 0
let y = y + 25
 
endif
 
let x = x + 28
 
formid i + 1
formtext ""
buttonform x, y, 25, 20
 
let i = i + 1
 
loop i < size
 
formid 17
formtext "
staticform 40, 130, 100, 20
bgcolor 0, 128, 0
fgcolor 255, 255, 0
colorform
 
formid 18
formtext ""
staticform 40, 150, 100, 20
bgcolor 0, 128, 0
fgcolor 255, 255, 0
colorform
 
formid 19
formtext "New"
buttonform 1, 1, 50, 20
 
formid 20
formtext "Help"
buttonform 55, 1, 50, 20
 
formid 21
formtext "About"
buttonform 110, 1, 50, 20
 
formid 22
formtext "Welcome."
staticform 40, 170, 120, 20
bgcolor 0, 128, 0
fgcolor 255, 255, 0
colorform
 
return
 
sub shuffle
 
let start = 1
 
formid 22
formtext "shuffling..."
updateform
 
let i = 0
 
do
 
formid i + 1
formtext ""
updateform
 
let list[i] = 0
let i = i + 1
 
loop i < size
 
let i = 0
 
do
 
let f = 0
 
do
 
let n = ( int: (rnd) * 14 ) + 1
let s = 0
let c = 0
 
do
 
if n = list[c] then
 
let s = 1
break
 
endif
 
let c = c + 1
 
loop c < i
 
if s = 0 and list[i] = 0 then
 
formid i + 1
formtext n
updateform
 
let list[i] = n
let i = i + 1
 
endif
 
let f = f + 1
 
wait
 
loop f = < size - 1
 
loop i < size - 1
 
formid 22
formtext ""
updateform
 
return
 
sub game
 
do
 
let click = (forms)
 
if click > 0 and click < 17 and start = 1 then
 
let moves = moves + 1
 
formid 17
formtext "Moves: ", moves
updateform
 
gosub checkspaces
gosub checkorder
 
endif
 
if click = 19 then
 
gosub shuffle
 
let moves = 0
let correct = 0
 
formid 17
formtext "Moves:"
updateform
 
formid 18
formtext "Correct:"
updateform
 
endif
 
if click = 20 then
 
alert "Click the numbers to move them in the correct order."
 
endif
 
if click = 21 then
 
alert "15 Puzzle - by Gemino Smothers 2023 - www.basicgames.xyz
 
endif
 
button k, 27
 
wait
 
loop k = 0
 
return
 
sub checkspaces
 
let click = click - 1
let top = click - 4
let right = click + 1
let bottom = click + 4
let left = click - 1
 
if top >= 0 then
 
if list[top] = 0 then
 
let n = top
gosub swap
 
endif
 
endif
 
if right <= size - 1 then
 
if list[right] = 0 then
 
let n = right
gosub swap
 
endif
 
endif
 
if bottom <= size - 1 then
 
if list[bottom] = 0 then
 
let n = bottom
gosub swap
 
endif
 
endif
 
if left >= 0 then
 
if list[left] = 0 then
 
let n = left
gosub swap
 
endif
 
endif
 
return
 
sub swap
 
let t = list[click]
let list[n] = list[click]
let list[click] = 0
 
let click = click + 1
formid click
formtext ""
updateform
 
let n = n + 1
formid n
formtext t
updateform
 
return
 
sub checkorder
 
let correct = 0
let i = 0
 
do
 
if list[i] = i + 1 then
 
let correct = correct + 1
 
formid 18
formtext "Correct: ", correct
updateform
 
endif
 
let i = i + 1
 
loop i < size - 1
 
if correct = size - 1 then
 
alert "You win! Moves: ", moves
 
endif
 
return</syntaxhighlight>
 
=={{header|EasyLang}}==
305

edits