UNPKG

@real_one_chess_king/game-logic

Version:
57 lines 1.81 kB
import { Direction } from "./movement-rule"; import { StraightMovementRule, } from "./straight-movement.rule"; import { buildMoveAffect, markAsUserSelected } from "../../affect/affect.utils"; /** * upLeft up * left upRight * x y * downleft right * down downRight */ const actionMap = { [Direction.UpRight]: (x, y, diff) => { return [x + diff + 1, y - diff]; }, [Direction.UpLeft]: (x, y, diff) => { return [x - diff, y - diff - 1]; }, [Direction.DownRight]: (x, y, diff) => { return [x + diff, y + diff + 1]; }, [Direction.DownLeft]: (x, y, diff) => { return [x - diff - 1, y + diff]; }, [Direction.Up]: (x, y, diff) => { return [x + diff, y - diff - 1]; }, [Direction.Down]: (x, y, diff) => { return [x - diff, y + diff + 1]; }, [Direction.Right]: (x, y, diff) => { return [x + diff + 1, y + diff]; }, [Direction.Left]: (x, y, diff) => { return [x - diff - 1, y - 1]; }, }; export class KnightMovementRule extends StraightMovementRule { constructor({ id, name, moveToEmpty, moveToKill, collision, distance, directions, speed, }) { super(id, name, moveToEmpty, moveToKill, collision, distance, directions, speed); } possibleDirrections = [ Direction.UpRight, Direction.UpLeft, Direction.DownRight, Direction.DownLeft, Direction.Up, Direction.Down, Direction.Right, Direction.Left, ]; calculateNewCoord = (x, y, diff, dirrection) => { return [ markAsUserSelected(buildMoveAffect([x, y], actionMap[dirrection](x, y, diff))), ]; }; } //# sourceMappingURL=knight-movement.rule.js.map