puzzlescript
Version:
Play PuzzleScript games in your terminal!
100 lines (83 loc) • 2.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-env jasmine */
const engine_1 = require("./engine");
const parser_1 = __importDefault(require("./parser/parser"));
function parseEngine(code) {
const { data } = parser_1.default.parse(code);
const engine = new engine_1.LevelEngine(data);
engine.setLevel(0);
return { engine, data };
}
function buildGame(winConditions) {
return `title foo
========
OBJECTS
========
Background .
gray
Player
transparent
Hat H
transparent
Glasses
transparent
Dog D
transparent
Cat
transparent
=======
LEGEND
=======
P = Player AND Glasses AND Hat
L = Player
=======
SOUNDS
=======
================
COLLISIONLAYERS
================
Background
Player
Hat
Glasses
Dog
Cat
======
RULES
======
==============
WINCONDITIONS
==============
${winConditions.join('\n')}
=======
LEVELS
=======
PDHL
`;
}
describe('Win Conditions', () => {
it('detects conditions for simple checks', () => {
function simple(conditions, expected) {
const { engine } = parseEngine(buildGame(conditions));
const { isWinning } = engine.tick();
expect(isWinning).toBe(expected);
}
simple(['NO Player'], false);
simple(['NO Cat'], true);
simple(['SOME Cat'], false);
simple(['SOME Player'], true);
simple(['ALL Glasses ON Player'], true);
simple(['SOME Glasses ON Player'], true);
simple(['NO Glasses ON Player'], false);
// All Target on CleanDishes
simple(['ALL Player ON Hat'], false);
simple(['NO Dog ON Player'], true);
simple(['ALL Dog ON Player'], false);
simple(['SOME Dog ON Player'], false);
});
});
//# sourceMappingURL=winConditions.spec.js.map