+ offerDraw: function() {
+ if (!confirm("Offer draw?"))
+ return;
+ // Stay in "draw offer sent" state until next move is played
+ this.drawOfferSent = true;
+ if (this.subMode == "corr")
+ {
+ // TODO: set drawOffer on in game (how ?)
+ }
+ else //live game
+ {
+ this.opponents.forEach(o => {
+ if (!!o.online)
+ {
+ try {
+ this.conn.send(JSON.stringify({code: "draw", oppid: o.id}));
+ } catch (INVALID_STATE_ERR) {
+ return;
+ }
+ }
+ });
+ }
+ },
+ // + conn handling: "draw" message ==> agree for draw (if we have "drawOffered" at true)
+ receiveDrawOffer: function() {
+ //if (...)
+ // TODO: ignore if preventDrawOffer is set; otherwise show modal box with option "prevent future offers"
+ // if accept: send message "draw"
+ },
+ abortGame: function() {
+ if (!confirm("Abort the game?"))
+ return;
+ //+ bouton "abort" avec score == "?" + demander confirmation pour toutes ces actions,
+ //send message: "gameOver" avec score "?"
+ },
+ resign: function(e) {
+ if (!confirm("Resign the game?"))
+ return;
+ if (this.mode == "human" && this.oppConnected(this.oppid))
+ {
+ try {
+ this.conn.send(JSON.stringify({code: "resign", oppid: this.oppid}));
+ } catch (INVALID_STATE_ERR) {
+ return;
+ }
+ }
+ this.endGame(this.mycolor=="w"?"0-1":"1-0");
+ },