X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=72b5da9009252f03fa7a15842888827fa87c2519;hb=dda21a71b6245832a78ca987b14c77176bd15dd6;hp=aaef522ba40375ed3524200c446fe06152e85902;hpb=8a196305a09269888497995373658f953b9b5bf8;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index aaef522b..72b5da90 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -17,6 +17,7 @@ Vue.component('my-game', { incheck: [], pgnTxt: "", expert: document.cookie.length>0 ? document.cookie.substr(-1)=="1" : false, + gameId: "", //used to limit computer moves' time }; }, render(h) { @@ -239,23 +240,77 @@ Vue.component('my-game', { ); } elementArray.push(gameDiv); - // if (!!vr.reserve) - // { - // let reserve = h('div', - // {'class':{'game':true}}, [ - // h('div', - // { 'class': { 'row': true }}, - // [ - // h('div', - // {'class':{'board':true}}, - // [h('img',{'class':{"piece":true},attrs:{"src":"/images/pieces/wb.svg"}})] - // ) - // ] - // ) - // ], - // ); - // elementArray.push(reserve); - // } + if (!!this.vr.reserve) + { + const shiftIdx = (this.mycolor=="w" ? 0 : 1); + let myReservePiecesArray = []; + for (let i=0; i what about smartphone?! + // NOTE: click = mousedown + mouseup on: { mousedown: this.mousedown, mousemove: this.mousemove, mouseup: this.mouseup, - touchdown: this.mousedown, - touchmove: this.mousemove, - touchup: this.mouseup, +// touchstart: this.mousedown, //TODO... +// touchmove: this.mousemove, +// touchend: this.mouseup, }, }, elementArray @@ -585,7 +640,6 @@ Vue.component('my-game', { this.newGame("computer"); }, newGame: function(mode, fenInit, color, oppId, moves, continuation) { - //const fen = "1n2T1n0/p2pO2p/1s1k1s2/8/3S2p1/2U2cO1/P3PuPP/3K1BR1 0100"; const fen = fenInit || VariantRules.GenRandInitFen(); console.log(fen); //DEBUG this.score = "*"; @@ -614,6 +668,8 @@ Vue.component('my-game', { } return; } + // random enough (TODO: function) + this.gameId = (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase(); this.vr = new VariantRules(fen, moves || []); this.pgnTxt = ""; //redundant with this.score = "*", but cleaner this.mode = mode; @@ -654,8 +710,11 @@ Vue.component('my-game', { playComputerMove: function() { const timeStart = Date.now(); const nbMoves = this.vr.moves.length; //using played moves to know if search finished + const gameId = this.gameId; //to know if game was reset before timer end setTimeout( () => { + if (gameId != this.gameId) + return; //game stopped const L = this.vr.moves.length; if (nbMoves == L || !this.vr.moves[L-1].notation) //move search didn't finish this.vr.shouldReturn = true; @@ -677,6 +736,19 @@ Vue.component('my-game', { }, mousedown: function(e) { e = e || window.event; + let ingame = false; + let elem = e.target; + while (!ingame && elem !== null) + { + if (elem.classList.contains("game")) + { + ingame = true; + break; + } + elem = elem.parentElement; + } + if (!ingame) //let default behavior (click on button...) + return; e.preventDefault(); //disable native drag & drop if (!this.selectedPiece && e.target.classList.contains("piece")) { @@ -696,7 +768,8 @@ Vue.component('my-game', { this.possibleMoves = this.mode!="idle" && this.vr.canIplay(this.mycolor,startSquare) ? this.vr.getPossibleMovesFrom(startSquare) : []; - e.target.parentNode.appendChild(this.selectedPiece); + // Next line add moving piece just after current image (required for Crazyhouse reserve) + e.target.parentNode.insertBefore(this.selectedPiece, e.target.nextSibling); } }, mousemove: function(e) {