Files
wownerogue/test/monsterChase.test.js
jwinterm fad2a695bd Wownerogue
A browser-based roguelike synchronized with crypto block timing. A run is a race
against the next block: reach the exit before the block lands, or the house wins.
The same codebase runs the solo dungeon, the social Tavern, and operator-selected
PvP and race rulesets, with separate free and paid leaderboards.

Self-hostable under the MIT License. See README.md to run it, docs/ARCHITECTURE.md
for the design, and docs/DEPLOY.md to operate an instance.
2026-07-27 08:23:01 -04:00

42 lines
1.9 KiB
JavaScript

const MovementManager = require('../src/game/movementManager');
function makeChaseGame() {
// Minimal game stub with player + monster and deterministic chase
return {
player: { x: 1, y: 1, getState() { return { x: this.x, y: this.y }; } },
monster: { x: 5, y: 1, getState() { return { x: this.x, y: this.y }; } },
movePlayer(dx, dy) {
this.player.x += dx; this.player.y += dy; return { status: 'moved' };
},
moveMonster() { // simple horizontal chase
if (this.monster.x > this.player.x) this.monster.x--; else if (this.monster.x < this.player.x) this.monster.x++;
if (this.monster.y > this.player.y) this.monster.y--; else if (this.monster.y < this.player.y) this.monster.y++;
},
getState() { return { player: { x: this.player.x, y: this.player.y }, monster: { x: this.monster.x, y: this.monster.y } }; }
};
}
describe('Monster chase integration (MovementManager hook)', () => {
test('monster advances toward player each move', () => {
const activeGames = new Map();
const socketId = 'sock-monster';
const game = makeChaseGame();
activeGames.set(socketId, game);
const emitted = [];
const io = { to: () => ({ emit: (evt, data) => emitted.push({ evt, data }) }) };
const debugManager = { getCurrentBlockHeight: () => 999 };
// Provide postMoveHook similar to server wiring
const mm = new MovementManager({ activeGames, io, debugManager, moveCooldown: 0, postMoveHook: ({ game }) => game.moveMonster() });
// Player moves right 3 times; monster should close distance
const startDistance = game.monster.x - game.player.x;
for (let i = 0; i < 3; i++) {
mm.handleMove(socketId, { direction: 'right' });
}
const endDistance = game.monster.x - game.player.x;
expect(endDistance).toBeLessThan(startDistance); // monster got closer
// Ensure we emitted 3 updates
expect(emitted.filter(e => e.evt === 'game_update').length).toBe(3);
});
});