Lua常用封装方法

时间:2021-06-12 09:36:53

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~= - and y~= -) -- 根据多点颜色区域模糊查色返回的结果
then
touchDown(x, y) -- 点击事件
mSleep()
touchUp(x, y)
end
mSleep()
end

改良

-- 根据坐标点击
function click(x,y)
if(x~= - and y~= -) -- 根据多点颜色区域模糊查色返回的结果
then
touchDown(x, y) -- 点击事件
mSleep(getRandom(,))
touchUp(x, y)
end
mSleep(getRandom(,)) -- 点击后等待一秒到三秒
end