Skip to content

Instantly share code, notes, and snippets.

@poga
Created September 24, 2008 20:08
Show Gist options
  • Save poga/12649 to your computer and use it in GitHub Desktop.
Save poga/12649 to your computer and use it in GitHub Desktop.
require 'gosu'
require 'date'
$Kcode = 'u'
def remain(date)
intervals = [["天",1],["小時",24],["分鐘",60],["秒",60]]
elapsed = DateTime.now - date
interval = 1.0
parts = intervals.collect do |name,new_interval|
interval /= new_interval
number,elapsed = elapsed.abs.divmod(interval)
"#{number.to_i}#{name}"
end
return parts.join('')
end
class GameWindow < Gosu::Window
def initialize
super(730, 60, false)
self.caption = "CountDown"
@now = DateTime.now
@deadline = DateTime.parse("2009-02-28T00:00:00+08:00")
@font = Gosu::Font.new(self, Gosu::default_font_name, 40)
end
def update
@remain = remain(@deadline)
end
def draw
@font.draw("距離台大考試還有:#{@remain}", 10, 10, 0, 1.0, 1.0, 0xffffff00)
end
end
window = GameWindow.new
window.show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment