Skip to content

Instantly share code, notes, and snippets.

@iigmir
Last active November 21, 2020 19:55
Show Gist options
  • Save iigmir/6415b0a30fe0931eff29f031135181d9 to your computer and use it in GitHub Desktop.
Save iigmir/6415b0a30fe0931eff29f031135181d9 to your computer and use it in GitHub Desktop.
doodle_rabbit
class Rabbit
# Google Doodle 那隻兔子的解法,把 Ruby 安裝好後在命令列執行:ruby doodle_rabbit.rb
def initialize(stagename)
@stagename = "第 #{stagename} 關"
end
def intro(starting)
if( starting == true )
puts "#{@stagename}解法:"
else
puts "#{@stagename}解法到此結束。"
end
end
def left
puts "往左轉"
end
def right
puts "往右轉"
end
def forward
puts "往前走"
end
def loop(times)
puts "重複這些動作 #{times} 次"
end
end
class Circle_stage < Rabbit
def initialize(stagename)
@stagename = "第 #{stagename} 關"
end
def circle
#tc = Rabbit.new(tc_name)
#tc.intro(false)
self.forward()
self.forward()
self.right()
self.loop("4")
end
def starting
self.intro(true)
end
def ending
self.intro(false)
puts " "
end
end
stage3 = Circle_stage.new("3")
stage3.starting()
stage3.circle()
stage3.ending()
stage4 = Circle_stage.new("4")
stage4.starting()
stage4.circle()
stage4.right()
stage4.right()
stage4.loop("4")
stage4.ending()
stage5 = Circle_stage.new("5")
stage5.starting()
stage5.circle()
stage5.right()
stage5.loop("4")
stage5.ending()
stage6 = Circle_stage.new("6")
stage6.starting()
stage6.forward()
stage6.right()
stage6.forward()
stage6.loop("4")
stage6.left()
stage6.loop("4")
stage6.ending()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment