Sodoku puzzle (iPad)
Posted: Fri Apr 15, 2016 3:26 am
This is just one sudoku puzzle, fully playable. I like to make small button games with smart Basic when waiting for something, in this case I was waiting for dinner. It's really simply coded, no auto-solving or undo. Just one puzzle to pass the time. I'll add comments in the code later. Enjoy.
- Dav
- Dav
Code: Select all
'SodokuPuzzle.txt
'Just one sodoku puzzle, fully playable.
'Made in a hurry, waiting for dinner.
'Code by Dav, April/2016
if lowstr$(device_type$())<>"ipad" then
print "Sorry, game for iPad only."
end
end if
option base 1
graphics
graphics clear 1,1,1
draw font size 36
draw size 5
draw color 0,0,0
draw rect 15,75 to 740,800
draw line 15,317 to 740,317
draw line 15,557 to 740,557
draw line 257,75 to 257,800
draw line 498,75 to 498,800
draw text "Sodoku Puzzle #1 (HARD)" at 20,20
set buttons custom
set buttons font size 42
dim bx(81),by(81), btn$(81)
restart:
dat$="sodoku.dat"
if not file_exists(dat$) then
a$=" 68 73 93 9 45"
a$=a$&"49 8 3 9 2 36"
a$=a$&"9 4 3 87 68 28 "
for e =1 to len(a$)
file dat$ write asc(mid$(a$,e,1))
next e
else
a$=""
file dat$ setpos 0
for f = 1 to 81
file dat$ read e
a$=a$&chr$(e)
next f
end if
puz$="172549683645873219389261745"
puz$=puz$&"496327851813456972257198436"
puz$=puz$&"964715328731682594528934167"
c=1!x=20!y=80
for t = 1 to 9
for t2 = 1 to 9
button str$(c) text mid$(a$,c,1) at x,y size 75,75
btn$(c)=mid$(a$,c,1)
bx(c)=x!by(c)=y
x=x+80!c=c+1
next t2
y=y+80!x=20
next t
button "r" text "restart" at 600,5
main:
for t = 1 to 81
if button_pressed(str$(t)) then
fill color 1,1,.3
button str$(t) text "" at bx(t),by(t) size 75,75
c=1!x=20
for b=1 to 9
button "b"&(str$(b)) text str$(b) at x,815 size 75,75
x=x+80
next b
button "c" text "cancel" at 300,905
fill color 1,1,1
done=0
do
for u=1 to 9
if button_pressed("b"&str$(u)) then
button str$(t) text str$(u) at bx(t),by(t) size 75,75
btn$(t)=str$(u)
done=1!break
end if
next u
if button_pressed("c") then
button str$(t) text btn$(t) at bx(t),by(t) size 75,75
done=1
end if
until done=1
for b=1 to 9
button "b"&(str$(b)) delete
next b
button "c" delete
chk$=""
for o= 1 to 81
chk$=chk$&btn$(o)
next o
file dat$ setpos 0
for e =1 to len(chk$)
file dat$ write asc(mid$(chk$,e,1))
next e
if chk$=puz$ then
graphics clear
draw font size 36
draw text "You solved it!" at 250,300
for c = 1 to 81
button str$(c) delete
next c
button "c" delete
end
end if
end if
next t
if button_pressed("r") then
file dat$ delete
goto restart
end if
goto main
end