Moving opponent pieces is now forbidden.
[kaya.git] / lib / board / user.rb
blob96747794f4fd72eca8c05532e2cf859ee89a91ef
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     @board.flip!(color != :white)
18     @board.warp(match.state)
19     @board.movable = lambda do |state, p|
20       state.board[p].color == color
21     end
22     
23     user = self
24     @board.observe :new_move do |data|
25       match.move(user, data[:move], data[:state])
26     end
27     
28     @notify[:newGame => 'Starting new game']
29   end
30   
31   def on_move(data)
32     @board.forward(data[:state], data[:move])
33     @notify[:move => "A new move has been played"]
34   end
35 end