红宝石绿色鞋子计时器



我正在为游戏构建这个弹出倒数计时器。问题是我无法弄清楚如何更新动画以使显示也发生变化。到目前为止,它有效,但你看不到数字的变化。它融入00:00。我很肯定到目前为止它只是在这个更改中遇到问题。这是用绿色鞋子完成的。知道我在这里做错了什么吗?

#Timer button used for creating a countdown timer for the game.
    #Game ends when timer is zero.
    flow width: 80, height: 0.2 do
    button 'Timer', width: 1.0, height: 1.0 do
        window do
        def time_change!
           @clock = '%02d:%02d' % [@second / 60, @second % 60]
           if(@second == 0)
            alert "game is over"
            @clock = '00:00'
                close()
            para @clock, size: 50, stroke: black
           end
         end
         background whitesmoke
         @clock = '00:00'
         para @clock, size: 50, stroke: black

         @second = 10
        animate(1) do
            @second -= 1
            time_change!
            para @clock, size: 50, stroke: black
        end
    end
end

您可以替换显示时钟的当前段落的文本:

Shoes.app do
  flow do 
    button 'Timer', width: 100, height: 50 do
      window width: 200, height: 100 do  #Open a child window when the button is clicked
        seconds = 3
        tenths = 0
        clock =  '%02d:%02d'
        flow do
          @p = para clock % [seconds, tenths], #Assign the clock para to an instance variable, 
            size: 50,                          #which will make the variable visible outside this block.
            stroke: black
        end
        a = animate(10) do  #Upate the clock every 1/10 of a second.
          tenths -= 1
          if tenths < 0
            tenths  = 9
            seconds -= 1
          end
          @p.text = clock % [seconds, tenths]  #Replace the clock text.
          if seconds == 0 and tenths == 0
            a.stop
            alert("game over")
            close   #=>self.close where self is the window whose block contains this code
          end
        end #animate
      end #window
    end #button
  end #flow
end #app

要验证时钟是否实际显示每个时间增量,您可以通过将animate(10)更改为animate(1)来减慢速度。

相关内容

  • 没有找到相关文章

最新更新