--888888_____888____888888__88
--88___88____888________88__88
--88___88____8_8_______88___88
--88___88___88_88______88___88
--88___88___88__8_____88____88
--888888____8___8____88_____88
--88_______8888888___88_____88
--88_______88___88__88______88
--88______88_____88_888888__888888

Mp3me.stop()
Mp3me.load("data/sound/3.mp3")
Mp3me.play()
circl=Image.load("data/img/circl.png")
local pin={16}--dlia proverki nakladivania kartinok ia zadau massiv
local masx={16}--massivi koordinat po x i po y
local masy={16}
font77 = Font.load("data/font/qwe3.ttf")
font77:setPixelSizes(30,30)
file=io.open("data/nastroi/save.CPP","r")
peremennay=file:read()
file:close()
c1=Image.load("data/img/pazl/c1.png")
c2=Image.load("data/img/pazl/c2.png")
c3=Image.load("data/img/pazl/c3.png")
c4=Image.load("data/img/pazl/c4.png")
c5=Image.load("data/img/pazl/c5.png")
c6=Image.load("data/img/pazl/c6.png")
c7=Image.load("data/img/pazl/c7.png")
c8=Image.load("data/img/pazl/c8.png")
c9=Image.load("data/img/pazl/c9.png")
c10=Image.load("data/img/pazl/c10.png")
c11=Image.load("data/img/pazl/c11.png")
c12=Image.load("data/img/pazl/c12.png")
c13=Image.load("data/img/pazl/c13.png")
c14=Image.load("data/img/pazl/c14.png")
c15=Image.load("data/img/pazl/c15.png")
c16=Image.load("data/img/pazl/c16.png")
ramka=Image.load("data/img/pazl/ramka.png")

function nill()
circl=nil
c1=nil
c2=nil
c3=nil
c4=nil
c5=nil
c6=nil
c7=nil
c8=nil
c9=nil
c10=nil
c11=nil
c12=nil
c13=nil
c14=nil
c15=nil
c16=nil
ramka=nil
end
razb = math.random(1,2)

if razb==1 then
masx[1]=64
masx[2]=0
masx[3]=0
masx[4]=0
masx[5]=0
masx[6]=0
masx[7]=64
masx[8]=64
masy[1]=38
masy[2]=38
masy[3]=76
masy[4]=114
masy[5]=150
masy[6]=188
masy[7]=188
masy[8]=188
masx[9]=354
masx[10]=418
masx[11]=418
masx[12]=418
masx[13]=418
masx[14]=418
masx[15]=354
masx[16]=354
masy[9]=38
masy[10]=38
masy[11]=76
masy[12]=114
masy[13]=150
masy[14]=188
masy[15]=188
masy[16]=188
elseif razb==2 then
masx[8]=64
masx[1]=0
masx[2]=0
masx[3]=0
masx[4]=0
masx[5]=0
masx[6]=64
masx[7]=64
masy[1]=38
masy[8]=38
masy[2]=76
masy[3]=114
masy[4]=150
masy[5]=188
masy[6]=188
masy[7]=188
masx[9]=354
masx[16]=418
masx[10]=418
masx[11]=418
masx[12]=418
masx[13]=418
masx[14]=354
masx[15]=354
masy[9]=38
masy[16]=38
masy[10]=76
masy[11]=114
masy[12]=150
masy[13]=188
masy[14]=188
masy[15]=188
end

for i=1,16 do--dlia proverki stolknovenii
pin[i]=0
end

pigip=1
while pigip==1 do
screen:clear()
pad = Controls.read()
screen:blit(0,0,fonit)
screen:blit(119,57,ramka)
screen:blit(430,233,circl)
screen:blit(masx[1],masy[1],c1)
screen:blit(masx[2],masy[2],c2)
screen:blit(masx[3],masy[3],c3)
screen:blit(masx[4],masy[4],c4)
screen:blit(masx[5],masy[5],c5)
screen:blit(masx[6],masy[6],c6)
screen:blit(masx[7],masy[7],c7)
screen:blit(masx[8],masy[8],c8)
screen:blit(masx[9],masy[9],c9)
screen:blit(masx[10],masy[10],c10)
screen:blit(masx[11],masy[11],c11)
screen:blit(masx[12],masy[12],c12)
screen:blit(masx[13],masy[13],c13)
screen:blit(masx[14],masy[14],c14)
screen:blit(masx[15],masy[15],c15)
screen:blit(masx[16],masy[16],c16)

--Peremeshenie-- ^-^
if x>=masx[1] and x<=masx[1]+62 and y>=masy[1] and y<=masy[1]+36 then
screen:blit(masx[1],masy[1],ramses)
end
if x>=masx[2] and x<=masx[2]+62 and y>=masy[2] and y<=masy[2]+36 then
screen:blit(masx[2],masy[2],ramses)
end
if x>=masx[3] and x<=masx[3]+62 and y>=masy[3] and y<=masy[3]+36 then
screen:blit(masx[3],masy[3],ramses)
end
if x>=masx[4] and x<=masx[4]+62 and y>=masy[4] and y<=masy[4]+36 then
screen:blit(masx[4],masy[4],ramses)
end
if x>=masx[5] and x<=masx[5]+62 and y>=masy[5] and y<=masy[5]+36 then
screen:blit(masx[5],masy[5],ramses)
end
if x>=masx[6] and x<=masx[6]+62 and y>=masy[6] and y<=masy[6]+36 then
screen:blit(masx[6],masy[6],ramses)
end
if x>=masx[7] and x<=masx[7]+62 and y>=masy[7] and y<=masy[7]+36 then
screen:blit(masx[7],masy[7],ramses)
end
if x>=masx[8] and x<=masx[8]+62 and y>=masy[8] and y<=masy[8]+36 then
screen:blit(masx[8],masy[8],ramses)
end
if x>=masx[9] and x<=masx[9]+62 and y>=masy[9] and y<=masy[9]+36 then
screen:blit(masx[9],masy[9],ramses)
end
if x>=masx[10] and x<=masx[10]+62 and y>=masy[10] and y<=masy[10]+36 then
screen:blit(masx[10],masy[10],ramses)
end
if x>=masx[11] and x<=masx[11]+62 and y>=masy[11] and y<=masy[11]+36 then
screen:blit(masx[11],masy[11],ramses)
end
if x>=masx[12] and x<=masx[12]+62 and y>=masy[12] and y<=masy[12]+36 then
screen:blit(masx[12],masy[12],ramses)
end
if x>=masx[13] and x<=masx[13]+62 and y>=masy[13] and y<=masy[13]+36 then
screen:blit(masx[13],masy[13],ramses)
end
if x>=masx[14] and x<=masx[14]+62 and y>=masy[14] and y<=masy[14]+36 then
screen:blit(masx[14],masy[14],ramses)
end
if x>=masx[15] and x<=masx[15]+62 and y>=masy[15] and y<=masy[15]+36 then
screen:blit(masx[15],masy[15],ramses)
end
if x>=masx[16] and x<=masx[16]+62 and y>=masy[16] and y<=masy[16]+36 then
screen:blit(masx[16],masy[16],ramses)
end
if pad:cross() and x>=masx[1] and x<=masx[1]+62 and y>=masy[1] and y<=masy[1]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[1]=1
if masx[1]<120 or masx[1]>136 or masy[1]<168 or masy[1]>184 then
masx[1]=x-31
masy[1]=y-18
else
masx[1]=120
masy[1]=168
end
else
pin[1]=0
end
if pad:cross() and x>=masx[2] and x<=masx[2]+62 and y>=masy[2] and y<=masy[2]+36 and pin[1]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[2]=1
if masx[2]<244 or masx[2]>260 or masy[2]<132 or masy[2]>148 then
masx[2]=x-31
masy[2]=y-18
else
masx[2]=244
masy[2]=132
end
else
pin[2]=0
end
if pad:cross() and x>=masx[3] and x<=masx[3]+62 and y>=masy[3] and y<=masy[3]+36 and pin[2]==0 and pin[1]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[3]=1
if masx[3]<120 or masx[3]>136 or masy[3]<132 or masy[3]>148 then
masx[3]=x-31
masy[3]=y-18
else
masx[3]=120
masy[3]=132
end
else
pin[3]=0
end
if pad:cross() and x>=masx[4] and x<=masx[4]+62 and y>=masy[4] and y<=masy[4]+36 and pin[2]==0 and pin[3]==0 and pin[1]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[4]=1
if masx[4]<306 or masx[4]>322 or masy[4]<96 or masy[4]>112 then
masx[4]=x-31
masy[4]=y-18
else
masx[4]=306
masy[4]=96
end
else
pin[4]=0
end
if pad:cross() and x>=masx[5] and x<=masx[5]+62 and y>=masy[5] and y<=masy[5]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[1]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[5]=1
if masx[5]<120 or masx[5]>136 or masy[5]<60 or masy[5]>76 then
masx[5]=x-31
masy[5]=y-18
else
masx[5]=120
masy[5]=60
end
else
pin[5]=0
end
if pad:cross() and x>=masx[6] and x<=masx[6]+62 and y>=masy[6] and y<=masy[6]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[1]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[6]=1
if masx[6]<244 or masx[6]>260 or masy[6]<168 or masy[6]>184 then
masx[6]=x-31
masy[6]=y-18
else
masx[6]=244
masy[6]=168
end
else
pin[6]=0
end
if pad:cross() and x>=masx[7] and x<=masx[7]+62 and y>=masy[7] and y<=masy[7]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[1]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[7]=1
if masx[7]<306 or masx[7]>322 or masy[7]<168 or masy[7]>184 then
masx[7]=x-31
masy[7]=y-18
else
masx[7]=306
masy[7]=168
end
else
pin[7]=0
end
if pad:cross() and x>=masx[8] and x<=masx[8]+62 and y>=masy[8] and y<=masy[8]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[1]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[8]=1
if masx[8]<182 or masx[8]>198 or masy[8]<168 or masy[8]>184 then
masx[8]=x-31
masy[8]=y-18
else
masx[8]=182
masy[8]=168
end
else
pin[8]=0
end
if pad:cross() and x>=masx[9] and x<=masx[9]+62 and y>=masy[9] and y<=masy[9]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[1]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[9]=1
if masx[9]<244 or masx[9]>260 or masy[9]<60 or masy[9]>76 then
masx[9]=x-31
masy[9]=y-18
else
masx[9]=244
masy[9]=60
end
else
pin[9]=0
end
if pad:cross() and x>=masx[10] and x<=masx[10]+62 and y>=masy[10] and y<=masy[10]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[1]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[10]=1
if masx[10]<182 or masx[10]>198 or masy[10]<132 or masy[10]>148 then
masx[10]=x-31
masy[10]=y-18
else
masx[10]=182
masy[10]=132
end
else
pin[10]=0
end
if pad:cross() and x>=masx[11] and x<=masx[11]+62 and y>=masy[11] and y<=masy[11]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[1]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[11]=1
if masx[11]<120 or masx[11]>136 or masy[11]<96 or masy[11]>112 then
masx[11]=x-31
masy[11]=y-18
else
masx[11]=120
masy[11]=96
end
else
pin[11]=0
end
if pad:cross() and x>=masx[12] and x<=masx[12]+62 and y>=masy[12] and y<=masy[12]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[1]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[12]=1
if masx[12]<244 or masx[12]>260 or masy[12]<96 or masy[12]>112 then
masx[12]=x-31
masy[12]=y-18
else
masx[12]=244
masy[12]=96
end
else
pin[12]=0
end
if pad:cross() and x>=masx[13] and x<=masx[13]+62 and y>=masy[13] and y<=masy[13]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[1]==0 and pin[14]==0 and pin[15]==0 and pin[16]==0 then
pin[13]=1
if masx[13]<182 or masx[13]>198 or masy[13]<96 or masy[13]>112 then
masx[13]=x-31
masy[13]=y-18
else
masx[13]=182
masy[13]=96
end
else
pin[13]=0
end
if pad:cross() and x>=masx[14] and x<=masx[14]+62 and y>=masy[14] and y<=masy[14]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[1]==0 and pin[15]==0 and pin[16]==0 then
pin[14]=1
if masx[14]<182 or masx[14]>198 or masy[14]<60 or masy[14]>76 then
masx[14]=x-31
masy[14]=y-18
else
masx[14]=182
masy[14]=60
end
else
pin[14]=0
end
if pad:cross() and x>=masx[15] and x<=masx[15]+62 and y>=masy[15] and y<=masy[15]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[1]==0 and pin[16]==0 then
pin[15]=1
if masx[15]<306 or masx[15]>322 or masy[15]<60 or masy[15]>76 then
masx[15]=x-31
masy[15]=y-18
else
masx[15]=306
masy[15]=60
end
else
pin[15]=0
end
if pad:cross() and x>=masx[16] and x<=masx[16]+62 and y>=masy[16] and y<=masy[16]+36 and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 and pin[6]==0 and pin[7]==0 and pin[8]==0 and pin[9]==0 and pin[10]==0 and pin[11]==0 and pin[12]==0 and pin[13]==0 and pin[14]==0 and pin[15]==0 and pin[1]==0 then
pin[16]=1
if masx[16]<306 or masx[16]>322 or masy[16]<132 or masy[16]>148 then
masx[16]=x-31
masy[16]=y-18
else
masx[16]=306
masy[16]=132
end
else
pin[16]=0
end

--proverka viigrasha putem totalnoi proverki koordinat
if pad:circle() then
if masx[5]>=110 and masx[5]<=134 and masy[5]>=50 and masy[5]<=74 and masx[14]>=172 and masx[14]<=196 and masy[14]>=50 and masy[14]<=74 and masx[9]>=234 and masx[9]<=258 and masy[9]>=50 and masy[9]<=74 and masx[15]>=296 and masx[15]<=320 and masy[15]>=50 and masy[15]<=74 and masx[11]>=110 and masx[11]<=134 and masy[11]>=86 and masy[11]<=110 and masx[13]>=172 and masx[13]<=196 and masy[13]>=86 and masy[13]<=110 and masx[12]>=234 and masx[12]<=258 and masy[12]>=86 and masy[12]<=110 and masx[4]>=296 and masx[4]<=320 and masy[4]>=86 and masy[4]<=110 and masx[3]>=100 and masx[3]<=134 and masy[3]>=122 and masy[3]<=146 and masx[10]>=172 and masx[10]<=196 and masy[10]>=122 and masy[10]<=146 and masx[2]>=234 and masx[2]<=258 and masy[2]>=122 and masy[2]<=146 and masx[16]>=296 and masx[16]<=320 and masy[16]>=122 and masy[16]<=146 and masx[1]>=110 and masx[1]<=134 and masy[1]>=158 and masy[1]<=182 and masx[8]>=172 and masx[8]<=196 and masy[8]>=158 and masy[8]<=182 and masx[6]>=234 and masx[6]<=258 and masy[6]>=158 and masy[6]<=182 and masx[7]>=296 and masx[7]<=320 and masy[7]>=158 and masy[7]<=182 then
System.message("You WIN! =)",0)
file=io.open("data/makesave/save24.msn","w")
file:write(3)
file:close()
file=io.open("data/nastroi/save.CPP","w")
file:write(math.ceil(peremennay))
file:close()
nill()
dofile("data/load/load.cpp")
else
screen:blit(0,232,erro)
pigip=0
end
end
peremennay=peremennay-0.01
if peremennay<0 then
System.message("You died! =(",0)
nill()
dofile("data/scripts/script.cpp")
end
screen:fontPrint(font55,220,262,math.ceil(peremennay),red)
screen:blit(x,y,souris)
screen:flip()
if pad:up() then
y =y - 10
end

if pad:down() then
y =y + 10
end

if pad:left() then
x =x - 10
end

if pad:right() then
x =x + 10
end
if pad:r() then
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 16;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 16;
end
else
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 128;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 128;
end
end
if x < 0 then x = 0 elseif x + souris:width() > 480 then x = 480 -  souris:width() end
if y < 0 then y = 0 elseif y + souris:height() > 272 then y = 268 -  souris:width() end
if pad:select() then
file=io.open("data/makesave/screenshoter.msn","r")
nscreen=tonumber(file:read())
file:close()
screen:save("data/screenshot/SHOT"..nscreen..".png")
nscreen=nscreen+1
file=io.open("data/makesave/screenshoter.msn","w")
file:write(math.ceil(nscreen))
file:close()
end
oldpad=pad
end
System.message("You died! =(",0)
nill()
dofile("data/scripts/script.cpp")