当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript util.key2pos函数代码示例

本文整理汇总了TypeScript中chessground/util.key2pos函数的典型用法代码示例。如果您正苦于以下问题:TypeScript key2pos函数的具体用法?TypeScript key2pos怎么用?TypeScript key2pos使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了key2pos函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: renderPromotion

  function renderPromotion(dest, pieces, color, orientation) {
    if (!promoting) return;

    let left = (8 - cgUtil.key2pos(dest)[0]) * 12.5;
    if (orientation === 'white') left = 87.5 - left;

    const vertical = color === orientation ? 'top' : 'bottom';

    return h('div#promotion-choice.' + vertical, {
      hook: onInsert(el => {
          el.addEventListener('click', cancel);
          el.oncontextmenu = () => false;
      })
    }, pieces.map(function(serverRole, i) {
      const top = (color === orientation ? i : 7 - i) * 12.5;
      return h('square', {
        attrs: {
          style: 'top: ' + top + '%;left: ' + left + '%'
        },
        hook: bind('click', e => {
          e.stopPropagation();
          finish(serverRole);
        })
      }, [h('piece.' + serverRole + '.' + color)]);
    }));
  };
开发者ID:ornicar,项目名称:lila,代码行数:26,代码来源:promotion.ts

示例2: renderPromotion

function renderPromotion(ctrl: AnalyseCtrl, dest: Key, pieces, color: Color, orientation: Color) {
  if (!promoting) return;

  let left = (8 - util.key2pos(dest)[0]) * 12.5;
  if (orientation === 'white') left = 87.5 - left;

  const vertical = color === orientation ? 'top' : 'bottom';

  return h('div#promotion_choice.' + vertical, {
    hook: {
      insert: vnode => {
        const el = (vnode.elm as HTMLElement);
        el.addEventListener('click', _ => cancel(ctrl));
        el.oncontextmenu = () => false;
      }
    }
  }, pieces.map(function(serverRole, i) {
    const top = (color === orientation ? i : 7 - i) * 12.5;
    return h('square', {
      attrs: {
        style: 'top: ' + top + '%;left: ' + left + '%'
      },
      hook: bind('click', e => {
        e.stopPropagation();
        finish(ctrl, serverRole);
      })
    }, [h('piece.' + serverRole + '.' + color)]);
  }));
}
开发者ID:lexisvar,项目名称:lila,代码行数:29,代码来源:promotion.ts

示例3: renderPromotion

function renderPromotion(ctrl: RoundController, dest: cg.Key, roles: cg.Role[], color: Color, orientation: Color) {
  var left = (8 - key2pos(dest)[0]) * 12.5;
  if (orientation === 'white') left = 87.5 - left;
  var vertical = color === orientation ? 'top' : 'bottom';

  return h('div#promotion_choice.' + vertical, {
    hook: {
      insert: vnode => {
        const el = vnode.elm as HTMLElement;
        el.addEventListener('click', () => cancel(ctrl));
        el.addEventListener('contextmenu', e => {
          e.preventDefault();
          return false;
        });
      }
    }
  }, roles.map((serverRole, i) => {
    var top = (color === orientation ? i : 7 - i) * 12.5;
    return h('square', {
      attrs: {style: 'top: ' + top + '%;left: ' + left + '%'},
      hook: bind('click', e => {
        e.stopPropagation();
        finish(ctrl, serverRole);
      })
    }, [
      h('piece.' + serverRole + '.' + color)
    ]);
  }));
};
开发者ID:lexisvar,项目名称:lila,代码行数:29,代码来源:promotion.ts

示例4: capture

export function capture(ctrl: RoundController, key: cg.Key) {
  const exploding: cg.Key[] = [],
  diff: cg.PiecesDiff = {},
  orig = util.key2pos(key),
  minX = Math.max(1, orig[0] - 1),
    maxX = Math.min(8, orig[0] + 1),
    minY = Math.max(1, orig[1] - 1),
    maxY = Math.min(8, orig[1] + 1);
  const pieces = ctrl.chessground.state.pieces;

  for (let x = minX; x <= maxX; x++) {
    for (let y = minY; y <= maxY; y++) {
      const k = util.pos2key([x, y]);
      exploding.push(k);
      const explodes = pieces[k] && (
        k === key || pieces[k]!.role !== 'pawn')
      if (explodes) diff[k] = undefined;
    }
  }
  ctrl.chessground.setPieces(diff);
  ctrl.chessground.explode(exploding);
}
开发者ID:ddugovic,项目名称:lila,代码行数:22,代码来源:atomic.ts

示例5: enpassant

export function enpassant(ctrl: RoundController, key: cg.Key, color: cg.Color) {
  const pos = util.key2pos(key),
  pawnPos: cg.Pos = [pos[0], pos[1] + (color === 'white' ? -1 : 1)];
  capture(ctrl, util.pos2key(pawnPos));
}
开发者ID:ddugovic,项目名称:lila,代码行数:5,代码来源:atomic.ts


注:本文中的chessground/util.key2pos函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。