#! ruby # @author Kazuhiro Yoshida (moriq) # @version 0.1 1998.6 # @code sjis class Link attr("text") attr("jump") def initialize(text, jump) @text = text @jump = jump end end class Suit attr("text") attr("link") def initialize(text, link) @text = text @link = link end def println cnt = 1 print @text for i in @link print "#{cnt}: #{i.text} (#{i.jump})\n" cnt += 1 end end def readfile(filename) if FileTest::file?(filename) file = open(filename, "r") @text = file.gets("\n\n") @link = [] while file.gets list = split text = list.shift jump = list.shift link = Link.new(text, jump) @link.push(link) end else print "error: fail to read #{filename}\n\n" end end end suit = Suit.new(nil, []) suit.readfile("adv.txt") suit.println while TRUE print "> " ch = gets.to_i print "\n" if ch == 0 then exit(1) end ch -= 1 if defined?(suit.link[ch].jump) jump = suit.link[ch].jump suit.readfile("#{jump}.txt") suit.println else print "error: fail to jump\n\n" end end