Lua常用封裝方法


Lua

獲取隨機值

--獲取隨機值,指定上限和下限
function getRandom(min,max)
    -- 接收一個整數n作為隨即序列的種子
    math.randomseed(os.time())
    ----然后不斷產生隨機數
    --[[
    for i=1, 5 do
     print(math.random(100))
    end]]--
    return math.random(min,max)
end

獲取當前時間

function getNow()
    local nowTime = os.date("%Y-%m-%d %H:%M:%S", os.time())
    -- print(nowTime)
    return nowTime
end
print(os.time())

觸動精靈常用封裝方法

根據坐標點擊

function click(x,y)
    if(x~= -1 and y~= -1)  -- 根據多點顏色區域模糊查色返回的結果
    then
        touchDown(x, y)   -- 點擊事件
        mSleep(20)
        touchUp(x, y)
    end
    mSleep(1000)
end

改良

-- 根據坐標點擊
function click(x,y)
    if(x~= -1 and y~= -1)  -- 根據多點顏色區域模糊查色返回的結果
    then
        touchDown(x, y)   -- 點擊事件
        mSleep(getRandom(15,30))
        touchUp(x, y)
    end
    mSleep(getRandom(1000,3000))  -- 點擊后等待一秒到三秒
end

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM