Class: Hanoi::Jane::AnimatedTowers
- Inherits:
-
Object
- Object
- Hanoi::Jane::AnimatedTowers
- Includes:
- Enumerable
- Defined in:
- lib/hanoi/jane/towers/animated_towers.rb
Instance Attribute Summary collapse
-
#discs ⇒ Object
Returns the value of attribute discs.
-
#height ⇒ Object
Returns the value of attribute height.
-
#towers ⇒ Object
Returns the value of attribute towers.
Instance Method Summary collapse
- #each {|Frame.new (PaddedStacks.new @towers.stacks, @height), @towers.rebased, :key| ... } ⇒ Object
-
#initialize {|_self| ... } ⇒ AnimatedTowers
constructor
A new instance of AnimatedTowers.
Constructor Details
#initialize {|_self| ... } ⇒ AnimatedTowers
Returns a new instance of AnimatedTowers.
8 9 10 11 12 13 14 15 16 |
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 8 def initialize yield self if block_given? if @discs > @height raise HanoiException.new 'number_of_discs (%d) > height (%d)' % [@discs, @height] end @towers = @towers.new @discs end |
Instance Attribute Details
#discs ⇒ Object
Returns the value of attribute discs.
6 7 8 |
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 6 def discs @discs end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 6 def height @height end |
#towers ⇒ Object
Returns the value of attribute towers.
6 7 8 |
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 6 def towers @towers end |
Instance Method Details
#each {|Frame.new (PaddedStacks.new @towers.stacks, @height), @towers.rebased, :key| ... } ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 18 def each until @towers.solved stacks = PaddedStacks.new @towers.stacks, @height value = @towers.rebased @towers.move yield Frame.new stacks, value, :key @anim = Animation.new do |a| a.stacks = stacks a.disc = @towers.disc a.from = @towers.from a.to = @towers.to a.height = @height end @anim.each do |frame| yield Frame.new frame.stacks, @towers.rebased, :tween end end yield Frame.new (PaddedStacks.new @towers.stacks, @height), @towers.rebased, :key end |