// Start of code //
Set Window on
Set Window Layout 0,0,0
Set Window size 400,420
Set Display Mode 400,420,16
Sync On : Sync Rate 60
#constant cLast 3
Set Text Font "Arial"
Set Text To Bold
set image colorkey 255,0,255
global iOn as integer : iOn=lamp_img(1)
global iOff as integer : iOff=lamp_img(0)
global Level : Level=1
global click
global space
dim field(4,4) as boolean
global Lstart as integer
load_level(1)
do : cls
handle_lamps()
draw_lamps()
sync
sync : loop
function lamp_img(On as boolean)
cls rgb(255,0,255)
if On
r#=135.0 : g#=135.0 : b#=105.0
else
r#=100.0 : g#=100.0 : b#=100.0
endif
for r=300 to 0 step -1
ink rgb(r#,g#,b#),0
circle 40,40,r/10.0
circle 41,40,r/10.0
circle 41,41,r/10.0
circle 40,41,r/10.0
if On then inc r#,0.5*(r#<255) : inc g#,0.4*(g#<255) : inc b#,0.3*(b#<255)
if not On then inc r#,0.3*(r#<255) : inc g#,0.3*(g#<255) : inc b#,0.3*(b#<255)
next r
num=free_image()
get image num,0,0,80,80,1
cls
endfunction num
function load_level(num as integer)
select num
case 1 : restore level1 : endcase
case 2 : restore level2 : endcase
case 3 : restore level3 : endcase
endselect
for x=0 to 4
for y=0 to 4
read a
field(x,y)=a
next y
next x
Lstart=timer()/1000
repeat : until mouseclick()=0 and scancode()=0
repeat
click=1
space=1
draw_lamps()
ink rgb(220,220,250),0
Set Text size 26
Center Text 200,200,"Level "+str$(num)
ink rgb(0,0,0),0
Set Text size 24
Center Text 200,200,"Level "+str$(num)
ink rgb(220,220,250),0
Set Text size 26
Center Text 200,230,"[press any key]"
ink rgb(0,0,0),0
Set Text size 24
Center Text 200,230,"[press any key]"
sync : sync
until mouseclick()>0 or scancode()>0
endfunction
function handle_lamps()
//change on click
for x=0 to 4
for y=0 to 4
if sqrt((mousex()-(x*80+40))^2+(mousey()-(y*80+40))^2)< 30 and mouseclick()&&1>0 and click=0
field(x,y)=abs(int(field(x,y))-1)
if x-1>=0 then field(x-1,y)=abs(int(field(x-1,y))-1)
if y-1>=0 then field(x,y-1)=abs(int(field(x,y-1))-1)
if x+1<=4 then field(x+1,y)=abs(int(field(x+1,y))-1)
if y+1<=4 then field(x,y+1)=abs(int(field(x,y+1))-1)
endif
next y
next x
click=mouseclick()&&1
//check if won
win=1
for x=0 to 4
for y=0 to 4
if field(x,y)=1 then win=0
next y
next x
if win and Level=cLast then Exit Prompt "You won the game!","Winner" : end
if win then inc Level : load_level(Level) : exitfunction
if space=0 and spacekey() then load_level(Level)
space=spacekey()
endfunction
function draw_lamps()
// draw lamps
box 0,0,400,400,rgb(220,220,220),rgb(200,200,220),rgb( 170,170,170),rgb(110,110,150)
for x=0 to 4
for y=0 to 4
img=iOn*(field(x,y)=1)+iOff*(field(x,y)=0)
paste image img,80*x,80*y,1
next y
next x
//draw info-bar
box 0,400,400,402,rgb(22,22,22),rgb(20,20,22),rgb(17,1 7,17),rgb(11,11,15)
box 0,402,400,420,rgb(220,220,220),rgb(200,200,220),rg b(170,170,170),rgb(110,110,150)
set text size 18
ink rgb(240,240,255),0
text 5,402," Level: "+str$(Level)+"/"+str$(cLast)+" Level-time: "+str$((timer()/1000)-Lstart)+"s [Space] to reset"
set text size 17
ink rgb(10,10,15),0
text 6,403," Level: "+str$(Level)+"/"+str$(cLast)+" Level-time: "+str$((timer()/1000)-Lstart)+"s [Space] to reset"
endfunction
function free_image()
x=0 : repeat : inc x : until image exist(x)=0
endfunction x
level1:
data 1,1,0,1,1
data 1,0,1,0,1
data 0,1,1,1,0
data 1,0,1,0,1
data 1,1,0,1,1
level2:
data 0,1,0,1,0
data 1,1,0,1,1
data 0,0,0,0,0
data 1,1,0,1,1
data 0,1,0,1,0
level3:
data 0,1,0,0,0
data 1,0,1,1,0
data 1,0,0,0,1
data 0,1,1,0,1
data 0,0,0,1,0
// End of Code //