【发布时间】:2014-03-19 04:30:22
【问题描述】:
我目前正在使用 Lua 开发一个简单的“猜数字”游戏。我正在通过 iPad 上的一个名为 TouchLua+ 的应用程序进行编程。其中一种游戏模式是您有一定的时间来猜数字。我认为要做到这一点,我会创建一个从给定时间倒计时的协程。由于某种原因,协程运行时我无法输入数字。任何人都可以帮忙吗?这是我目前所拥有的。
target = math.random(1, 100)
coroutine.resume(coroutine.create(function()
for i = 1, roundTime do
sleep(1000)
sys.alert("tock")
end
lose = true
coroutine.yield()
end))
repeat
local n = tonumber(io.read())
if (n > target) then
print("Try a lower number.\n")
elseif (n < target) then
print("Try a higher number.\n")
else
win = true
end
until (lose or win)
return true
【问题讨论】: