1 require 'observer_utils'
9 def initialize(elements, game, history)
10 @board = elements[:board]
11 @pools = elements[:pools]
15 @animator = @game.animator.new(@board)
16 @field = AnimationField.new(20)
17 @board.reset(history.state.board)
20 @board.observe(:click) {|p| c.on_board_click(p) }
24 state = @history.state
26 move = @game.policy.new_move(state, @board.selection, p)
27 validate = @game.validator.new(state)
32 @board.selection = nil
33 elsif @game.policy.movable?(state, p) and movable?(p)
39 state = @history.state.dup
41 @history.add_move(state, move)
43 @pools.each {|color, pool| pool.warp(state.pool(color)) }
44 animate(:forward, state, move)
45 @board.highlight(move)
49 state, move = @history.back
50 @pools.each {|color, pool| pool.warp(state.pool(color)) }
51 animate(:back, state, move)
52 @board.highlight(@history.move)
53 rescue History::OutOfBound
54 puts "error: first move"
58 state, move = @history.forward
59 @pools.each {|color, pool| pool.warp(state.pool(color)) }
60 animate(:forward, state, move)
61 @board.highlight(move)
62 rescue History::OutOfBound
63 puts "error: last move"
66 def animate(direction, state, move)
67 anim = @animator.send(direction, state, move)