X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=94340e6605ce77c363d16cd0c7323c661d4494cc;hb=dbcc32e95d526fe518ac866f7b3cdac546f1178e;hp=d8f06b3358bb6156981689796c4db98c58d6f30e;hpb=78bab51e57306ae9085d83828bbb73b62dd83fd8;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index d8f06b33..94340e66 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -1105,7 +1105,7 @@ Vue.component('my-game', { this.conn.onclose = socketCloseListener; // Listen to keyboard left/right to navigate in game document.onkeydown = event => { - if (["idle","chat"].includes(this.mode) && + if (["human","computer"].includes(this.mode) && !!this.vr && this.vr.moves.length > 0 && [37,39].includes(event.keyCode)) { event.preventDefault(); @@ -1307,7 +1307,7 @@ Vue.component('my-game', { this.endGame(this.mycolor=="w"?"0-1":"1-0"); }, newGame: function(mode, fenInit, color, oppId) { - const fen = "rnbbqkrn/1ppppp1p/p5p1/8/8/3P4/PPP1PPPP/BNQBRKRN w1 1111 -"; //fenInit || VariantRules.GenRandInitFen(); + const fen = fenInit || VariantRules.GenRandInitFen(); console.log(fen); //DEBUG if (mode=="human" && !oppId) { @@ -1388,7 +1388,7 @@ Vue.component('my-game', { else if (mode == "computer") { this.compWorker.postMessage(["init",this.vr.getFen()]); - this.mycolor = "w";//(Math.random() < 0.5 ? 'w' : 'b'); + this.mycolor = (Math.random() < 0.5 ? 'w' : 'b'); if (this.mycolor != this.vr.turn) this.playComputerMove(); } @@ -1598,24 +1598,24 @@ Vue.component('my-game', { // Send the move to web worker (TODO: including his own moves?!) this.compWorker.postMessage(["newmove",move]); } + const eog = this.vr.checkGameOver(); + if (eog != "*") + { + if (["human","computer"].includes(this.mode)) + this.endGame(eog); + else + { + // Just show score on screen (allow undo) + this.score = eog; + this.showScoreMsg(); + } + } } else { VariantRules.PlayOnBoard(this.vr.board, move); this.$forceUpdate(); //TODO: ?! } - const eog = this.vr.checkGameOver(); - if (eog != "*") - { - if (["human","computer"].includes(this.mode)) - this.endGame(eog); - else - { - // Just show score on screen (allow undo) - this.score = eog; - this.showScoreMsg(); - } - } if (["human","computer","friend"].includes(this.mode)) this.updateStorage(); //after our moves and opponent moves if (this.mode == "computer" && this.vr.turn != this.mycolor && this.score == "*")