#!/usr/koeki/bin/ruby def cry(ct) ct.times do print("ぴよ\t") end print("\n") sleep(0.5) end def message(name) STDERR.print("[1]\t餌をあげる?\n") STDERR.print("[2]\tおもちゃをあげる?\n") STDERR.print("[3]\t散歩をする?\n") end def fat(perday,exercise) x = 4 * perday - exercise return x end printf("たまごを拾った。\n") STDERR.printf("どんな名前にするの?") name = gets.chomp if name == "" then name = "るびおっち" end printf("%sという名前になった。\n",name) happy = 1 # しあわせ度 weight = 1 # 体重 day = 0 # 育てた日付 printf("よく鳴くと大きくなるよ\n") while true cry(happy) message(name) ans = gets.chomp!.to_i happy += day * ans weight += fat(day,ans) if happy > 4 break end if weight > 4 break end cry(ans) day += 1 end cry(weight) # 最終段階の体重が鳴き声になる if weight > 8 printf("%sはふくろうみたいになりました\n",name) elsif weight <= 5 printf("%sはすずめみたいになりました\n",name) else printf("%sはからすみたいになりました\n",name) end