Attempting to move into tile that blocks shouldnt result in wait action

This commit is contained in:
Peter Stockings
2026-01-06 21:23:25 +11:00
parent 6e060013f7
commit 309ab19e8c
4 changed files with 73 additions and 5 deletions

View File

@@ -0,0 +1,63 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { applyAction } from '../simulation';
import type { World, CombatantActor, Action } from '../../../core/types';
import { TileType } from '../../../core/terrain';
import { GAME_CONFIG } from '../../../core/config/GameConfig';
describe('Movement Blocking Behavior', () => {
let world: World;
let player: CombatantActor;
beforeEach(() => {
// minimalist world setup
world = {
width: 3,
height: 3,
tiles: new Array(9).fill(TileType.GRASS),
actors: new Map(),
exit: { x: 2, y: 2 }
};
// Blocking wall at (1, 0)
world.tiles[1] = TileType.WALL;
player = {
id: 1,
type: 'player',
category: 'combatant',
isPlayer: true,
pos: { x: 0, y: 0 },
speed: 100,
energy: 0,
stats: { ...GAME_CONFIG.player.initialStats }
};
world.actors.set(player.id, player);
});
it('should return move-blocked event when moving into a wall', () => {
const action: Action = { type: 'move', dx: 1, dy: 0 }; // Try to move right into wall at (1,0)
const events = applyAction(world, player.id, action);
expect(events).toHaveLength(1);
expect(events[0]).toMatchObject({
type: 'move-blocked',
actorId: player.id,
x: 1,
y: 0
});
});
it('should return moved event when moving into empty space', () => {
const action: Action = { type: 'move', dx: 0, dy: 1 }; // Move down to (0,1) - valid
const events = applyAction(world, player.id, action);
expect(events).toHaveLength(1);
expect(events[0]).toMatchObject({
type: 'moved',
actorId: player.id,
from: { x: 0, y: 0 },
to: { x: 0, y: 1 }
});
});
});

View File

@@ -123,9 +123,9 @@ function handleMove(w: World, actor: Actor, action: { dx: number; dy: number },
}
return events;
} else {
return [{ type: "waited", actorId: actor.id }];
}
return [{ type: "move-blocked", actorId: actor.id, x: nx, y: ny }];
}