Implement notification.
[kaya.git] / lib / board / user.rb
blob06464ca1dc621150dc8e6439b5a61b01d0dc038c
1 require 'interaction/match'
3 # This class represents a local player
4
5 class User
6   include Player
7   
8   attr_accessor :color
9   
10   def initialize(color, board, notify)
11     @color = color
12     @board = board
13     @notify = notify
14   end
15   
16   def reset(match)
17     puts "resetting to #{match.state.inspect}"
18     puts "color = #{color}"
19     @board.flip!(color != :white)
20     @board.warp(match.state)
21     
22     user = self
23     @board.observe :new_move do |data|
24       match.move(user, data[:move], data[:state])
25     end
26   end
27   
28   def on_move(data)
29     @board.forward(data[:state], data[:move])
30     @notify[:move => "A new move has been played"]
31   end
32 end