我正在制作一个Simon说的游戏,似乎当它运行我的算法时,它并没有完全完成它。
我已经尝试过调试问题,并发现问题的根源在哪里,但我不确定要解决什么问题。
我使用Corona sdk,Lua作为我的语言。在此功能之前,我已声明light = 2。
应该每次将光减1,直到它<= 0.之后,应该运行该布尔表达式,但事实并非如此。
以下是我的代码的一部分:
started = false
pattern = true
gameOver = false
function starting(event)
if (started == false) then
started = true
end
if (event.phase == "ended") then
start()
count = count + 1
startText.isVisible = false
if (started == true) then
if(count%20 == count - math.floor(count/20)*20) then
clicked = 0
if(light >= 0) then
light = light - 1
end
end
if (pattern == true) then
--BELOW DOESNT WORK--
if (light <= 0) then
if (patternIndex >= table.getn(pat)) then
--randomizes lights--
clicked = math.random(1,10)+1
table.insert(pat,clicked)
patternIndex = 0
pattern = false
else
clicked = pat[patternIndex]
patternIndex = patternIndex + 1
end
light = 1
end
elseif (patternIndex == table.getn(pat)) then
pattern = true
patternIndex = 0
light = 2
end
end
startText: addEventListener( "touch", starting)
我注意到什么不起作用。看起来,&#34; if(light&lt; = 0)然后&#34;当我尝试通过放置&#34; print(&#34; hello&#34;)来测试它时不会通过。 如果有帮助的话,我也会发布我的Start()函数:
function start()
pat = {}
random = math.random(9)
patternIndex = 0
light = 2
clicked = 0
count = 0
end
编辑:
这是我的OnTouchListener函数:
function onTouchListener(event)
if (pattern == false and gameOver == false) then
if(event.target == btnclick1) then
clicked = 1
count = 1
elseif(event.target == btnclick2) then
clicked = 2
count = 1
elseif(event.target == btnclick3) then
clicked = 3
count = 1
elseif(event.target == btnclick4) then
clicked = 4
count = 1
elseif(event.target == btnclick5) then
clicked = 5
count = 1
elseif(event.target == btnclick6) then
clicked = 6
count = 1
elseif(event.target == btnclick7) then
clicked = 7
count = 1
elseif(event.target == btnclick8) then
clicked = 8
count = 1
elseif(event.target == btnclick9) then
clicked = 9
count = 1
end
if(clicked ~= 0) then
if(pat[patternIndex] == clicked) then
patternIndex = patternIndex + 1
else
gameOver = true
end
end
elseif (gameOver) then
start()
gameOver = false
end
end
btnclick1: addEventListener( "touch", onTouchListener)
btnclick2: addEventListener( "touch", onTouchListener)
btnclick3: addEventListener( "touch", onTouchListener)
btnclick4: addEventListener( "touch", onTouchListener)
btnclick5: addEventListener( "touch", onTouchListener)
btnclick6: addEventListener( "touch", onTouchListener)
btnclick7: addEventListener( "touch", onTouchListener)
btnclick8: addEventListener( "touch", onTouchListener)
btnclick9: addEventListener( "touch", onTouchListener)
答案 0 :(得分:0)
条件后添加打印功能。这将有助于您的程序流程的调整。还添加了变量的打印,这将有很大的帮助