class 'start_puzle' (Script)

function start_puzle:__init() super()
 self.height=4
 self.width=4
end

function start_puzle:on_attach()
 self:MyInit()
end
function start_puzle:MyInit()
 local scene=self:scene()
 local part='minigame_part'

 self.arr_object={}
 self.arr_position={}
 self.arr_data_complete={{x=1,y=1},{x=1,y=2},{x=1,y=3},{x=1,y=4},{x=2,y=1},{x=2,y=2},{x=2,y=3},{x=2,y=4},{x=3,y=1},{x=3,y=2},{x=3,y=3},{x=3,y=4},{x=4,y=1},{x=4,y=2},{x=4,y=3},{x=4,y=4}}
 self.arr_data_start={{x=1,y=1},{x=1,y=3},{x=2,y=1},{x=2,y=3},{x=3,y=1},{x=3,y=3},{x=4,y=1},{x=4,y=3},{x=4,y=4},{x=4,y=2},{x=3,y=4},{x=3,y=2},{x=2,y=4},{x=2,y=2},{x=1,y=4},{x=1,y=2}}
 self.arr_MyObject={}


 for i=1,16 do
  local arrPps={};
  self.arr_object[i]=scene:object(part..i)
  arrPps={}
  rawset(self.arr_MyObject,i,arrPps)
  rawset(arrPps,'data',self.arr_data_start[i])
  rawset(arrPps,'object',self.arr_object[i])
 end
 self.arr_position=self:createTablePos(self.arr_object[1],self.height,self.width)
 for j=1,16 do
  self:mySetPosition(self.arr_MyObject[j])
 end
 self.arr_MyObject[1]['object']:hide()
end

function start_puzle:createTablePos(object,height,width)
 local arrPos={}

 local xPos=object:position():x()
 local yPos=object:position():y()

 local xDem=object:dimensions():lx()
 local yDem=object:dimensions():ly()

 for i=1,height do
  local col={}
  rawset(arrPos,i,col)
  for j=1,width do
   rawset(col,j,Position(xPos+xDem*(j-1),yPos+yDem*(i-1)))
  end
 end
 return arrPos

end

function start_puzle:mySetPosition(myObject)
 local pos
 pos=self.arr_position[myObject['data'].x][myObject['data'].y]
 myObject['object']:set_position(pos)
end


