我正在用 Lua 制作游戏 - 特别是 Corona SDK - 我被困在定时健康奖励上(玩家每 4 小时获得一次健康奖励),第二部分是玩家将获得免费旋转的轮式游戏这将使他们有机会赢得在游戏中使用的免费物品。
真正让我困惑的部分是我如何获得准确的定时奖金(例如每 4 小时和每天一次)以触发奖金功能?我还希望有一个倒计时计时器显示小时:分钟:在可以收集下一个可用奖金之前剩下的秒数。这是不可能的吗?
到目前为止,这是我的一些代码......
function hourlyBonus()
local date = os.date( "*t" )
local currentHour = date.hour
lastHourlyBonusClaimedHour =
GameSave.lastHourlyBonusClaimedHour or date.hour
--account for the 24 hour clock
if currentHour > 12 then
currentHour = currentHour - 12
end
if lastHourlyBonusClaimedHour > 12 then
lastHourlyBonusClaimedHour = lastHourlyBonusClaimedHour - 12
end
if currentHour == (lastHourlyBonusClaimedHour + 4) then
lastHourlyBonusClaimedHour = currentHour
-- increase the bonus
print("New 4 hour bonus ThisHour is: " .. thisHourNum)
else
local hoursToWait = (4 - (currentHour - lastHourlyBonusClaimedHour))
--have to wait for hourly bonus
print("Have to wait: "
.. hoursToWait .. "hours, "
.. minutes .. "minutes, and "
.. second .. "seconds to collect hourly Bonus still!"
)
print("CurrentHour is:" .. currentHour)
print("LastHourlyBonusClaimedHour is :" .. lastHourlyBonusClaimedHour)
end
GameSave.lastHourlyBonusClaimedHour = lastHourlyBonusClaimedHour
GameSave:save()
end
如果有人有一些示例代码,我可以查看或告诉我如何执行此操作,我将不胜感激!