2012-06-11 80 views
0

我正在使用Corona SDK製作應用程序。在遊戲中你必須及時觸及所有領域,如果你贏了,你會獲勝。我在「你贏」的信息下做了一個重播按鈕,但我怎麼說他重新開始整個遊戲呢?Lua - 重播按鈕?

下面是代碼(不是全部):

function winLose(condition) 
if condition == "Win" then 
    print ("Winner") 
    winMSG = display.newImage("media/win.png") 


    -- Replay button 

    local btnReplay = ui.newButton{ 
    default = "media/buttonWhite.png", 
    over = "media/buttonWhiteOver.png", 
    onPress = btnReplayPress, 
    onRelease = btnReplayRelease, 
    text = "Replay", 
    textColor = { 0, 0, 0, 255 }, 
    size = 26, 
    id = "replay", 
    emboss = true 
    } 

    btnReplay.x = _W/2; 
    btnReplay.y = _H/2 + 50; 

elseif condition == "Fail" then 

    print ("Loser") 
    loseMSG = display.newImage("media/lose.png") 

    -- Replay Button 

    btnReplay = ui.newButton{ 
    default = "media/buttonWhite.png", 
    over = "media/buttonWhiteOver.png", 
    onPress = btnReplayPress, 
    onRelease = btnReplayRelease, 
    textColor = { 0, 0, 0, 255 }, 
    size = 26, 
    text = "Replay" 
    id = "replay", 
    emboss = true 
    } 


    ----- 

    function btnReplay:touch(e) 
     if e.phase == "began" then 
      -- 
     elseif e.phase == "moved" then 
      -- 
     elseif e.phase == "ended" then 
      -- Here I should say what it has to do to replay 
     end 
    end 

    ----- 

    btnReplay:addEventListener("touch", btnReplay); 

    ----- 

    btnReplay.x = _W/2; 
    btnReplay.y = _H/2 + 50; 
end 
end 

local function trackOrbs(obj) 
obj:removeSelf() 
o = o-1; 

if time_up ~= true then 
    if (o == 0) then 
     timer.cancel(gametmr); 
     winLose("Win"); 
    end 
end 
end 

local function countDown (e) 
if (time_remain == total_secs) then 
    ready = true 
end 
time_remain = time_remain - 1; 
countdowntxt.text = time_remain; 

if time_remain == 0 then 
    time_up = true 

    if o ~= 0 then 
     winLose("Fail"); 
     ready = false; 
    end 
end 
end 


local function spawnOrb() 

local orb = display.newImageRect("media/orb.png", 60, 60); 
orb:setReferencePoint(display.CenterReferencePoint); 
orb.x = mRand(50, _W-50); orb.y = mRand (50, _H-50); 

function orb:touch(e) 
    if time_up ~= true then 
     if (ready == true) then 
      if (e.phase == "ended") then 
       trackOrbs(self); 
      end 
     end 
    end 

    return true 
end 

o = o + 1; 

orb:addEventListener("touch", orb); 

if (o == total_orbs) then 
    gametmr = timer.performWithDelay(1000, countDown, total_secs) ; 
else 
    ready = false 
end 
end 

tmr = timer.performWithDelay (20, spawnOrb, total_orbs); 

回答

0

你可以有這樣的

while true do 
    if mainGame then 
     --game code 
    elseif done then 
     --buttons 
     if button.restart then 
      mainGame = true 
     end 
    end 
end 
while循環