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.
58 lines (57 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var parseCoord_1 = require("./parseCoord");
var getAvailableColumns = function (coord, movement) {
var _a = (0, parseCoord_1.default)(coord), rowId = _a[0], colId = _a[1];
var columns = {
top: [],
bottom: [],
left: [],
right: [],
topLeft: [],
topRight: [],
bottomLeft: [],
bottomRight: [],
};
var stepCount = (movement === null || movement === void 0 ? void 0 : movement.stepCount) || 1;
for (var step = 1; step <= stepCount; step += 1) {
if (movement === null || movement === void 0 ? void 0 : movement.top) {
columns.top.push("".concat(rowId - step, "|").concat(colId));
}
if (movement === null || movement === void 0 ? void 0 : movement.bottom) {
columns.bottom.push("".concat(rowId + step, "|").concat(colId));
}
if (movement === null || movement === void 0 ? void 0 : movement.left) {
columns.left.push("".concat(rowId, "|").concat(colId - step));
}
if (movement === null || movement === void 0 ? void 0 : movement.right) {
columns.right.push("".concat(rowId, "|").concat(colId + step));
}
if (movement === null || movement === void 0 ? void 0 : movement.topRight) {
columns.topRight.push("".concat(rowId - step, "|").concat(colId + step));
}
if (movement === null || movement === void 0 ? void 0 : movement.topLeft) {
columns.topLeft.push("".concat(rowId - step, "|").concat(colId - step));
}
if (movement === null || movement === void 0 ? void 0 : movement.bottomRight) {
columns.bottomRight.push("".concat(rowId + step, "|").concat(colId + step));
}
if (movement === null || movement === void 0 ? void 0 : movement.bottomLeft) {
columns.bottomLeft.push("".concat(rowId + step, "|").concat(colId - step));
}
if (movement === null || movement === void 0 ? void 0 : movement.linear) {
columns.top.push("".concat(rowId - step, "|").concat(colId));
columns.bottom.push("".concat(rowId + step, "|").concat(colId));
columns.left.push("".concat(rowId, "|").concat(colId - step));
columns.right.push("".concat(rowId, "|").concat(colId + step));
}
if (movement === null || movement === void 0 ? void 0 : movement.angular) {
columns.topLeft.push("".concat(rowId - step, "|").concat(colId - step));
columns.topRight.push("".concat(rowId - step, "|").concat(colId + step));
columns.bottomLeft.push("".concat(rowId + step, "|").concat(colId - step));
columns.bottomRight.push("".concat(rowId + step, "|").concat(colId + step));
}
}
return columns;
};
exports.default = getAvailableColumns;