Skip to content

Instantly share code, notes, and snippets.

@poga
Created November 18, 2008 13:26
Show Gist options
  • Save poga/26122 to your computer and use it in GitHub Desktop.
Save poga/26122 to your computer and use it in GitHub Desktop.
require 'gosu'
require 'date'
$Kcode = 'u'
config = File.open("config.txt",'r')
$deadline = config.gets.chomp
config.close
def remain(date)
intervals = [["天",1],["小時",24],["分鐘",60],["秒",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(550, 60, false)
self.caption = "CountDown"
@now = DateTime.now
@deadline = DateTime.parse($deadline)
@font = Gosu::Font.new(self, Gosu::default_font_name, 40)
#@font = Gosu::Font.new(self, "./comic.ttf",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