Created
January 25, 2015 09:51
-
-
Save ueno1969/960935ea735c72866a08 to your computer and use it in GitHub Desktop.
"翔べ!ガンダム"をrubyで書いてみた ref: http://qiita.com/Ueno1969/items/e37a83a6518ad99fea14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ガンダムは燃え上がる | |
ガンダムは燃え上がる | |
ガンダムは燃え上がる | |
ガンダムは走る | |
ガンダムは巨大な敵を撃つ | |
ガンダムは巨大な敵を撃つ | |
ガンダムは巨大な敵を撃つ | |
ガンダムは正義の怒りをぶつける | |
機動戦士 ガンダム ガンダム | |
ガンダムは立ち上がる | |
ガンダムは立ち上がる | |
ガンダムは立ち上がる | |
ガンダムは叫ぶ | |
ガンダムは恐怖を払う | |
ガンダムは行く | |
ガンダムは行く | |
ガンダムは行く | |
ガンダムは渦巻く血潮を燃やす | |
機動戦士 ガンダム ガンダム | |
ガンダムはよみがえる | |
ガンダムはよみがえる | |
ガンダムはよみがえる | |
ガンダムは掴む | |
ガンダムは平和を願う | |
ガンダム翔ぶ | |
ガンダム翔ぶ | |
ガンダム翔ぶ | |
ガンダム銀河へ向かって翔ぶ | |
機動戦士 ガンダム ガンダム | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'mobile_suit/gumdam' | |
def fire_up(ms) | |
3.times{ ms.fire_up } | |
ms.instance_eval do |you| | |
you.rush | |
if you.fighting_spirit && you.fighting_spirit.burn?("怒り") | |
enemy = you.search("巨大な敵") | |
3.times { you.shoot_up(enemy) } if enemy | |
end | |
end | |
ms.strike("正義の怒り") | |
end | |
def get_up(ms) | |
3.times{ ms.get_up } | |
ms.instance_eval do |you| | |
you.shout | |
if you.grief && you.grief.sink?("絶望") | |
you.drive_off("恐怖") | |
3.times { you.go_up } | |
end | |
end | |
ms.burn("渦巻く血潮") | |
end | |
def renew(ms) | |
3.times{ ms.renew } | |
ms.instance_eval do |you| | |
you.reach | |
if you.heart && you.heart.trembling?("愛") | |
you.desire("平和") | |
3.times { you.fly } | |
end | |
end | |
ms.fly("銀河") | |
end | |
gundam = Gundam.new | |
[:fire_up, :get_up, :renew].each do |action| | |
send(action, gundam) | |
puts "機動戦士 #{gundam.name} #{gundam.name}\n\n" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Property | |
def initialize(parts) | |
@parts = parts | |
end | |
def burn?(what) | |
@parts == :fighting_spirit && what == "怒り" | |
end | |
def sink?(what) | |
@parts == :grief && what == "絶望" | |
end | |
def trembling?(what) | |
@parts == :heart && what == "愛" | |
end | |
end | |
class Gundam | |
attr_reader :fighting_spirit, :grief, :heart | |
def initialize | |
@fighting_spirit = Property.new(:fighting_spirit) | |
@grief = Property.new(:grief) | |
@heart = Property.new(:heart) | |
end | |
def name | |
"ガンダム" | |
end | |
def fire_up | |
puts "#{name}は燃え上がる" | |
end | |
def rush | |
puts "#{name}は走る" | |
end | |
def search(target) | |
target | |
end | |
def shoot_up(target) | |
puts "#{name}は#{target}を撃つ" | |
end | |
def strike(property) | |
puts "#{name}は#{property}をぶつける" | |
end | |
def get_up | |
puts "#{name}は立ち上がる" | |
end | |
def shout | |
puts "#{name}は叫ぶ" | |
end | |
def drive_off(what) | |
puts "#{name}は#{what}を払う" | |
end | |
def go_up | |
puts "#{name}は行く" | |
end | |
def burn(what) | |
puts "#{name}は#{what}を燃やす" | |
end | |
def renew | |
puts "#{name}はよみがえる" | |
end | |
def reach | |
puts "#{name}は掴む" | |
end | |
def desire(what) | |
puts "#{name}は#{what}を願う" | |
end | |
def fly(what = nil) | |
puts name + (what ? "#{what}へ向かって" : "") + "翔ぶ" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment