コード例 #1
0
ファイル: ctrl.js プロジェクト: 9cat/lila
 this.userMove = function(orig, dest) {
   var res = puzzle.tryMove(this.data, [orig, dest]);
   var newProgress = res[0];
   var newLines = res[1];
   var lastMove = last(newProgress);
   var promotion = lastMove ? lastMove[4] : undefined;
   m.startComputation();
   switch (newLines) {
     case 'retry':
       setTimeout(partial(this.revert, this.data.puzzle.id), 500);
       this.data.comment = 'retry';
       break;
     case 'fail':
       var t = this;
       setTimeout(function() {
         if (t.data.mode == 'play') xhr.attempt(t, false);
         else t.revert(t.data.puzzle.id);
       }, 500);
       this.data.comment = 'fail';
       break;
     default:
       this.userFinalizeMove([orig, dest, promotion], newProgress);
       if (newLines == 'win') xhr.attempt(this, true);
       else setTimeout(partial(this.playOpponentNextMove, this.data.puzzle.id), 1000);
       break;
   }
   m.endComputation(); // give feedback ASAP, don't wait for delayed action
 }.bind(this);
コード例 #2
0
ファイル: ctrl.js プロジェクト: apetresc/lila
module.exports = function(cfg) {

  this.data = editor.init(cfg);

  this.chessground = new chessground.controller({
    fen: cfg.fen,
    orientation: 'white',
    movable: {
      free: true,
      color: 'both',
      dropOff: 'trash'
    },
    animation: {
      duration: cfg.animation.duration
    },
    premovable: {
      enabled: false
    },
    draggable: {
      showGhost: false
    }
  });

  this.computeFen = partial(editor.computeFen, this.data, this.chessground.getFen);

  this.trans = partial(editor.trans, this.data);

  this.startPosition = function() {
    this.chessground.reconfigure({
      fen: 'start'
    });
  }.bind(this);

  this.clearBoard = function() {
    this.chessground.reconfigure({
      fen: '8/8/8/8/8/8/8/8'
    });
  }.bind(this);

  this.loadNewFen = function(fen) {
    window.location = editor.makeUrl(this.data, fen);
  }.bind(this);

  this.chessgroundIsAnimating = function() {
    return this.chessground.data.draggable.current.orig || this.chessground.data.animation.current.start;
  }.bind(this);

  this.costly = function(cell) {
    return this.chessgroundIsAnimating() ? {
      subtree: 'retain'
    } : cell();
  }.bind(this);
};
コード例 #3
0
ファイル: ctrl.js プロジェクト: 9cat/lila
 this.initiate = function() {
   if (this.data.mode != 'view')
     setTimeout(partial(this.playInitialMove, this.data.puzzle.id), 1000);
 }.bind(this);