crazyhouse: can hover the drop on opponent turn

This commit is contained in:
Thibault Duplessis 2016-01-18 19:09:50 +07:00
parent 8a0fe82660
commit ed52974a56
3 changed files with 8 additions and 3 deletions

View file

@ -4,7 +4,7 @@ var game = require('game').game;
module.exports = function(ctrl, e) {
if (e.button !== 0) return; // only left click
if (!game.isPlayerTurn(ctrl.data)) return;
if (!game.isPlayerPlaying(ctrl.data)) return;
var node = e.target.parentNode.parentNode;
var role = node.getAttribute('data-role'),
color = node.getAttribute('data-color');

View file

@ -1,11 +1,16 @@
var util = require('./util');
var game = require('game').game;
module.exports = {
validateDrop: function(chessground, dropStr, piece, pos) {
validateDrop: function(chessground, data, piece, pos) {
if (!game.isPlayerTurn(data)) return false;
if (piece.role === 'pawn' && (pos[1] === '1' || pos[1] === '8')) return false;
var dropStr = data.possibleDrops;
if (typeof dropStr === 'undefined' || dropStr === null) return true;
var drops = dropStr.match(/.{2}/g) || [];

View file

@ -59,7 +59,7 @@ module.exports = function(opts) {
}.bind(this);
var onUserNewPiece = function(piece, pos) {
if (crazyhouse.validateDrop(this.chessground, this.data.possibleDrops, piece, pos))
if (crazyhouse.validateDrop(this.chessground, this.data, piece, pos))
this.sendNewPiece(piece.role, pos);
else this.jump(this.vm.ply);
}.bind(this);