Class: Hanoi::Jane::AnimatedTowers

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hanoi/jane/towers/animated_towers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ AnimatedTowers

Returns a new instance of AnimatedTowers.

Yields:

  • (_self)

Yield Parameters:



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

#discsObject

Returns the value of attribute discs.



6
7
8
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 6

def discs
  @discs
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/hanoi/jane/towers/animated_towers.rb', line 6

def height
  @height
end

#towersObject

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

Yields:



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