function mini_create()
  init_mini(true)
  create_mini(8128);
end

if flags.proshelPryazhki then
  speciale_action(4,obj.derevo_17_15.id)
  setcolor(obj.derevo_17_15.id,1,1,1,1)
  setCursor(obj.derevo_17_15.id,4)
  for i=1,18 do
    set_visible_object(i,false)
  end
else
  miniCreate()
end

local state = {}

for i=1,18 do
  state[i]=true
end
local last_id = nil

function gameinput (sender,obj_id,attachedID)
  MiniInterfaceHandler(sender, obj_id,attachedID);
  sendersProcessing(sender,obj_id,attachedID)
  if wrongItemWarning(sender, obj_id, attachedID) then
    return
  end
  if sender==1 then
    if obj_id>=1 and obj_id<=18 then
      if last_id then
        if last_id == obj_id then
          setcolor(last_id,1,1,1,1)
          last_id = nil
          return
        else
          local k = math.floor(last_id/2)*2
          if ((k<last_id)  and (obj_id-last_id==1))
          or ((k==last_id) and (last_id-obj_id==1)) then
            ActivateObject(obj_id,false)
            ActivateObject(last_id,false)
            SetAlfa(obj_id,1,0,1)
            SetAlfa(last_id,1,0,1)
            playeffect("otlichie")
            state[last_id]=false
            state[obj_id]=false
            last_id = nil
            checkMini()
            return
          else
            setcolor(last_id,1,1,1,1)
            last_id = nil
          end
        end
        
      end
      last_id=obj_id
      setcolor(last_id,0.7,0.7,0.7,1)
    end
    if obj_id == obj.derevo_17_15.id then
      StoreObj(obj.derevo_17_15.id)
      neighbors.Pryazhki.lock = true
    end
  end
  if sender == 10 then
    Block_Show_Cur(true)
    playeffect("mini_complete")
    speciale_action(4,obj.derevo_17_15.id)
    SetAlfa(obj.derevo_17_15.id,0,1,2,"unBlock_Show_Cur")
    setCursor(obj.derevo_17_15.id,4)
    flags.proshelPryazhki = true
    -- StoreObj(obj.derevo_17_15.id)
  end
  if sender == 26 then
  --  CloseSatelite()
  end
end

function checkMini()
  for i=1,18 do
    if state[i] then
      return
    end
  end
  finish_mini_game(true)
end
