@real_one_chess_king/game-logic
Version:
R.O.C.K. chess game logic
61 lines • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KnightMovementRule = void 0;
const movement_rule_1 = require("./movement-rule");
const straight_movement_rule_1 = require("./straight-movement.rule");
const affect_utils_1 = require("../../affect/affect.utils");
/**
* upLeft up
* left upRight
* x y
* downleft right
* down downRight
*/
const actionMap = {
[movement_rule_1.Direction.UpRight]: (x, y, diff) => {
return [x + diff + 1, y - diff];
},
[movement_rule_1.Direction.UpLeft]: (x, y, diff) => {
return [x - diff, y - diff - 1];
},
[movement_rule_1.Direction.DownRight]: (x, y, diff) => {
return [x + diff, y + diff + 1];
},
[movement_rule_1.Direction.DownLeft]: (x, y, diff) => {
return [x - diff - 1, y + diff];
},
[movement_rule_1.Direction.Up]: (x, y, diff) => {
return [x + diff, y - diff - 1];
},
[movement_rule_1.Direction.Down]: (x, y, diff) => {
return [x - diff, y + diff + 1];
},
[movement_rule_1.Direction.Right]: (x, y, diff) => {
return [x + diff + 1, y + diff];
},
[movement_rule_1.Direction.Left]: (x, y, diff) => {
return [x - diff - 1, y - 1];
},
};
class KnightMovementRule extends straight_movement_rule_1.StraightMovementRule {
constructor({ id, name, moveToEmpty, moveToKill, collision, distance, directions, speed, }) {
super(id, name, moveToEmpty, moveToKill, collision, distance, directions, speed);
}
possibleDirrections = [
movement_rule_1.Direction.UpRight,
movement_rule_1.Direction.UpLeft,
movement_rule_1.Direction.DownRight,
movement_rule_1.Direction.DownLeft,
movement_rule_1.Direction.Up,
movement_rule_1.Direction.Down,
movement_rule_1.Direction.Right,
movement_rule_1.Direction.Left,
];
calculateNewCoord = (x, y, diff, dirrection) => {
return [
(0, affect_utils_1.markAsUserSelected)((0, affect_utils_1.buildMoveAffect)([x, y], actionMap[dirrection](x, y, diff))),
];
};
}
exports.KnightMovementRule = KnightMovementRule;
//# sourceMappingURL=knight-movement.rule.js.map