Code: Select all
--LUA Lights out by Debug
w = Color.new(255,255,255)
bl = Color.new(0,0,100)
bk = Color.new(0,0,0)
yl = Color.new(255,255,100)
buffer = Image.createEmpty(480,272)
grid = {}
for y=0,6 do
grid[y] = {}
for x=0,6 do
grid[y][x]=math.random(0,1)
end
end
x = 3
y = 3
function DrawGrid()
for b=1,5 do
for a=1,5 do
if grid[b][a] == 1 then
buffer:fillRect(a*30,b*30,28,28,yl)
else
buffer:fillRect(a*30,b*30,28,28,bl)
end
end
end
end
function DrawCursor()
buffer:fillRect(x*30+8,y*30+8,12,12,bk)
buffer:fillRect(x*30+10,y*30+10,8,8,w)
end
function Check()
c=0
for a=1,5 do
for b=1,5 do
c=(c+grid[a][b])
end
end
if c<1 then
while true do
buffer:clear(bk)
buffer:print(200,120,"You Win!!!!!!",yl)
screen:blit(0,0,buffer)
screen.waitVblankStart()
screen.flip()
end
end
end
function Click()
grid[y][x]=math.abs(grid[y][x]-1)
grid[y-1][x]=math.abs(grid[y-1][x]-1)
grid[y+1][x]=math.abs(grid[y+1][x]-1)
grid[y][x-1]=math.abs(grid[y][x-1]-1)
grid[y][x+1]=math.abs(grid[y][x+1]-1)
moves=moves+1
end
moves=0
while true do
pad = Controls.read()
if pad~=temp then
if pad:up() then y=y-1 end
if pad:down() then y=y+1 end
if pad:left() then x=x-1 end
if pad:right() then x=x+1 end
if x<1 then x=1 end
if x>5 then x=5 end
if y<1 then y=1 end
if y>5 then y=5 end
if pad:cross() then Click() end
Check()
temp=pad
end
buffer:clear(bk)
buffer:print(210,15,"Current Position: ("..x..","..y..")", w)
buffer:print(210,25,"Moves: "..moves,w)
DrawGrid()
DrawCursor()
screen:blit(0,0,buffer)
screen.waitVblankStart()
screen.flip()
end