ymir-js
Version:
This toolkit is created to make it easier for you to develop games like chess, checkers, go, match 3 puzzle and more. It is still under development.
47 lines (46 loc) • 1.96 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var board_1 = require("./board");
var AutoPlay = /** @class */ (function (_super) {
__extends(AutoPlay, _super);
function AutoPlay(board) {
var _this = _super.call(this) || this;
_this.autoPlay = function (color, _a) {
var onAttack = _a.onAttack;
var attacks = _this.getAttacks(color);
var selectedItemCoord;
var lastCoord;
Object.keys(attacks).forEach(function (coord) {
var attackItem = _this.getItem(coord);
if (attackItem.color !== color)
return;
if (attackItem.selected)
selectedItemCoord = coord;
lastCoord = coord;
});
var selectedCoord = selectedItemCoord || lastCoord;
var selectedAttack = attacks[selectedCoord];
_this.selectItem(selectedCoord);
onAttack === null || onAttack === void 0 ? void 0 : onAttack(selectedAttack);
};
_this.board = board;
return _this;
}
return AutoPlay;
}(board_1.default));
exports.default = AutoPlay;