diff --git a/tests/game-logic.test.mjs b/tests/game-logic.test.mjs index d0ec1c0..dcf1c43 100644 --- a/tests/game-logic.test.mjs +++ b/tests/game-logic.test.mjs @@ -6,6 +6,7 @@ import { PLAYER_HIT_COOLDOWN_MS, PLAYER_MAX_HULL, normalizePlayerDamage, + processQueuedPlayerHits, reducePlayerHitQueue, } from '../src/game-logic.js'; @@ -24,6 +25,43 @@ test('first pirate hit removes exactly the default damage and does not end the g assert.equal(result.gameOver, false); }); + +test('actual queued first player hit destroys the projectile, applies 6 damage, and leaves gameplay active', () => { + const shot = { + active: true, + destroyed: false, + destroy() { + this.destroyed = true; + this.active = false; + }, + }; + + const firstFrame = processQueuedPlayerHits({ + hull: PLAYER_MAX_HULL, + lastHitAt: -Infinity, + now: 1000, + hits: [{ shot, damage: DEFAULT_PIRATE_SHOT_DAMAGE }], + }); + + assert.equal(shot.destroyed, true); + assert.equal(shot.active, false); + assert.equal(firstFrame.hull, 94); + assert.equal(firstFrame.appliedHits, 1); + assert.equal(firstFrame.ignoredHits, 0); + assert.equal(firstFrame.gameOver, false); + + const followingFrame = processQueuedPlayerHits({ + hull: firstFrame.hull, + lastHitAt: firstFrame.lastHitAt, + now: 1016, + hits: [], + }); + + assert.equal(followingFrame.hull, 94); + assert.equal(followingFrame.gameOver, false); + assert.equal(followingFrame.appliedHits, 0); +}); + test('three cannonballs arriving in one broadside only apply one hull hit', () => { const result = reducePlayerHitQueue({ hull: 100,