def piece_event(item, event)
case event.event_type
when Gdk::Event::ENTER_NOTIFY
item.text.set({:fill_color => "white"})
when Gdk::Event::LEAVE_NOTIFY
item.text.set({:fill_color => "black"})
when Gdk::Event::BUTTON_PRESS
y = item.pos / 4
x = item.pos % 4
move = true
if (y > 0) && @board[(y - 1) * 4 + x].nil?
dx = 0.0
dy = -1.0
y -= 1
elsif (y < 3) && @board[(y + 1) * 4 + x].nil?
dx = 0.0
dy = 1.0
y += 1
elsif (x > 0) && @board[y * 4 + x - 1].nil?
dx = -1.0
dy = 0.0
x -= 1
elsif (x < 3) && @board[y * 4 + x + 1].nil?
dx = 1.0
dy = 0.0
x += 1
else
move = false
end
if move
newpos = y * 4 + x
@board[item.pos] = nil
@board[newpos] = item
item.pos = newpos
item.move(dx * PIECE_SIZE, dy * PIECE_SIZE)
test_win()
end
end
end