Vue.component('my-game', {
data: function() {
return {
vr: null, //object to check moves, store them, FEN..
mycolor: "w",
possibleMoves: [], //filled after each valid click/dragstart
Vue.component('my-game', {
data: function() {
return {
vr: null, //object to check moves, store them, FEN..
mycolor: "w",
possibleMoves: [], //filled after each valid click/dragstart
start: {}, //pixels coordinates + id of starting square (click or drag)
selectedPiece: null, //moving piece (or clicked piece)
start: {}, //pixels coordinates + id of starting square (click or drag)
selectedPiece: null, //moving piece (or clicked piece)
score: "*", //'*' means 'unfinished'
mode: "idle", //human, friend, computer or idle (when not playing)
oppid: "", //opponent ID in case of HH game
score: "*", //'*' means 'unfinished'
mode: "idle", //human, friend, computer or idle (when not playing)
oppid: "", //opponent ID in case of HH game
{
on: { click: this.toggleExpertMode },
attrs: { "aria-label": 'Toggle expert mode' },
{
on: { click: this.toggleExpertMode },
attrs: { "aria-label": 'Toggle expert mode' },
on: { click: e => this.undo() },
attrs: { "aria-label": 'Undo' },
on: { click: e => this.undo() },
attrs: { "aria-label": 'Undo' },
},
[h('i', { 'class': { "material-icons": true } }, "fast_rewind")]),
h('button',
},
[h('i', { 'class': { "material-icons": true } }, "fast_rewind")]),
h('button',
on: { click: this.undoInGame },
attrs: { "aria-label": 'Undo' },
on: { click: this.undoInGame },
attrs: { "aria-label": 'Undo' },
new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {});
}
this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant);
new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {});
}
this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant);
- this.newGame("human", data.fen, data.color, data.oppid); //oppid: opponent socket ID
+ // oppid: opponent socket ID
+ this.newGame("human", data.fen, data.color, data.oppid);
break;
case "newmove": //..he played!
this.play(data.move, "animate");
break;
case "newmove": //..he played!
this.play(data.move, "animate");
// Prepare and trigger download link
let downloadAnchor = document.getElementById("download");
downloadAnchor.setAttribute("download", "game.pgn");
// Prepare and trigger download link
let downloadAnchor = document.getElementById("download");
downloadAnchor.setAttribute("download", "game.pgn");
const iCanPlay = this.mode!="idle"
&& (this.mode=="friend" || this.vr.canIplay(this.mycolor,startSquare));
this.possibleMoves = iCanPlay ? this.vr.getPossibleMovesFrom(startSquare) : [];
const iCanPlay = this.mode!="idle"
&& (this.mode=="friend" || this.vr.canIplay(this.mycolor,startSquare));
this.possibleMoves = iCanPlay ? this.vr.getPossibleMovesFrom(startSquare) : [];
const [offsetX,offsetY] = !!e.clientX
? [e.clientX,e.clientY]
: [e.changedTouches[0].pageX, e.changedTouches[0].pageY];
let landing = document.elementFromPoint(offsetX, offsetY);
this.selectedPiece.style.zIndex = 3000;
const [offsetX,offsetY] = !!e.clientX
? [e.clientX,e.clientY]
: [e.changedTouches[0].pageX, e.changedTouches[0].pageY];
let landing = document.elementFromPoint(offsetX, offsetY);
this.selectedPiece.style.zIndex = 3000;
// OK: process move attempt
let endSquare = this.getSquareFromId(landing.id);
let moves = this.findMatchingMoves(endSquare);
// OK: process move attempt
let endSquare = this.getSquareFromId(landing.id);
let moves = this.findMatchingMoves(endSquare);
let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y};
let movingPiece =
document.querySelector("#" + this.getSquareId(move.start) + " > img.piece");
let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y};
let movingPiece =
document.querySelector("#" + this.getSquareId(move.start) + " > img.piece");
// Possible improvement: just alter squares on the piece's way...
squares = document.getElementsByClassName("board");
for (let i=0; i<squares.length; i++)
// Possible improvement: just alter squares on the piece's way...
squares = document.getElementsByClassName("board");
for (let i=0; i<squares.length; i++)