Implemented layouting.
[kaya.git] / lib / controller.rb
blobfa73baedaa971c6ca8c1f1f06aaf426535c5f4fd
1 require 'observer_utils'
2 require 'history'
4 class Controller
5   include Observer
6   
7   attr_reader :history
8   
9   def initialize(board, history)
10     @board = board
11     @history = history
12     
13     board.add_observer self
14   end
15   
16   def on_new_move(data)
17     @history.add_move(data[:state], data[:move])
18     @board.highlight(data[:move])
19   end
20   
21   def on_back
22     state, move = @history.back
23     @board.back(state.dup, move)
24     @board.highlight(@history.move)
25   rescue History::OutOfBound
26     puts "error: first move"
27   end
28   
29   def on_forward
30     state, move = @history.forward
31     @board.forward(state.dup, move)
32     @board.highlight(move)
33   rescue History::OutOfBound
34     puts "error: last move"
35   end
36 end