Play game
Sudoku PICO-8's itch.io pageCompressed Bytes used
659
Source Code (OPTIONAL)
--sudoku pico-1k jam
--fabriciokarim
function _init()
numbers={
{5,3,0,0,7,0,0,0,0},
{6,0,0,1,9,5,0,0,0},
{0,9,8,0,0,0,0,6,0},
{8,0,0,0,6,0,0,0,3},
{4,0,0,8,0,3,0,0,1},
{7,0,0,0,2,0,0,0,6},
{0,6,0,0,0,0,2,8,0},
{0,0,0,4,1,9,0,0,5},
{0,0,0,0,8,0,0,7,9}
}
screen={
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
}
answer={
{5,3,4,6,7,8,9,1,2},
{6,7,2,1,9,5,3,4,8},
{1,9,8,3,4,2,5,6,7},
{8,5,9,7,6,1,4,2,3},
{4,2,6,8,5,3,7,9,1},
{7,1,3,9,2,4,8,5,6},
{9,6,1,5,3,7,2,8,4},
{2,8,7,4,1,9,6,3,5},
{3,4,5,2,8,6,1,7,9}
}
cx=5
cy=5
complete=0
for x=1,9 do
for y=1,9 do
if numbers[x][y]>0 then
screen[x][y]=numbers[x][y]
end
end
end
end
function _update()
if complete<81 then
if btnp(⬅️) then cx -= 1 end
if btnp(➡️) then cx += 1 end
if btnp(⬆️) then cy -= 1 end
if btnp(⬇️) then cy += 1 end
cx=mid(1,cx,9)
cy=mid(1,cy,9)
local n=screen[cx][cy]
if btnp(❎) then
if numbers[cx][cy]==0 then
n+=1
end
end
if btnp(🅾️) then
if numbers[cx][cy]==0 then
n-=1
end
end
screen[cx][cy]=mid(0,n,9)
complete=0
for x=1,9 do
for y=1,9 do
if screen[x][y]==answer[x][y] then
complete+=1
end
end
end
end
end
function _draw()
cls(15)
line(10,44,116,44,2)
line(10,80,116,80,2)
line(44,10,44,116,2)
line(80,10,80,116,2)
rect(cx*12-2,cy*12-2,cx*12+4,cy*12+6,8)
for x=1,9 do
for y=1,9 do
if screen[x][y]>0 then
print(screen[x][y], x*12,y*12,12)
end
if numbers[x][y]>0 then
print(numbers[x][y],x*12,y*12,0)
end
end
end
if complete==81 then
rectfill(10,1,116,9,2)
print("complete",48,3,7)
end
end
Leave a comment
Log in with itch.io to leave a comment.
Comments
No one has posted a comment yet