Good day. I do client chess on js without AI to begin to understand at least something in the application architecture. I use jQueryUI.
Problem number 1 - to teach the pawn to go forward and everything.
Problem: the pawn moves forward, vertically B checker. fields, but the passed fields become available both for the course backwards and further for the course forward. The elimination of the ui-droppable class, either through {addClass: false}, or manually (removeClass for the parent — the board’s fields) did not help. Even in his absence, the traversed fields are available for dragging back and forth.
Ie, the rule can go forward one cell is triggered once for each field, and then canceled. I do not understand what it affects.
Thank.
var pawn = new Pawn('P'); //Конструктор не прилагаю, там ничего необычного $(".sqB,.sqW").eq(49).append(pawn.img); //Вставка одной пешки на поле В2 шах. доски $("img").attr("id", pawn.id); //Установка id для DOM-элемента пешки var allowID = ""; //id разрешенного для перетаскивания поля доски $("#"+pawn.id).mouseenter (function () { var $startPos = $(this).parent().attr("id");//id поля где пешка находится(В2) if (pawn.charFEN == 'P') allowID = "#"+ $startPos.split('')[0] + (+$startPos.split('')[1]+1);//id следующего поля(В3) $(this).draggable ({revert:'invalid'}); $(allowID).droppable({drop: function (e,ui) { // центрирование картинки пешки в поле var cut = $(ui.draggable).detach(); $(this).append(cut.css({'top':'0','left':'0'})); }}); });