Add campfireRest function with tests
This commit is contained in:
parent
febb05764b
commit
91d32a71ee
2 changed files with 19 additions and 0 deletions
|
|
@ -23,6 +23,10 @@ export function endCombat(run, combatHp) {
|
||||||
return { ...run, hp, combatCount: run.combatCount + 1 };
|
return { ...run, hp, combatCount: run.combatCount + 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function campfireRest(run) {
|
||||||
|
return { ...run, hp: Math.min(run.hp + 3, run.maxHp) };
|
||||||
|
}
|
||||||
|
|
||||||
export function revealRewards(run) {
|
export function revealRewards(run) {
|
||||||
const count = Math.min(3, run.cardRewardsDeck.length);
|
const count = Math.min(3, run.cardRewardsDeck.length);
|
||||||
const revealed = run.cardRewardsDeck.slice(0, count);
|
const revealed = run.cardRewardsDeck.slice(0, count);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { getAllCards, initCards } from "./cards.js";
|
import { getAllCards, initCards } from "./cards.js";
|
||||||
import { initEnemies } from "./enemies.js";
|
import { initEnemies } from "./enemies.js";
|
||||||
import {
|
import {
|
||||||
|
campfireRest,
|
||||||
createRunState,
|
createRunState,
|
||||||
endCombat,
|
endCombat,
|
||||||
pickReward,
|
pickReward,
|
||||||
|
|
@ -89,6 +90,20 @@ describe("endCombat", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("campfireRest", () => {
|
||||||
|
test("campfireRest heals 3 HP", () => {
|
||||||
|
const run = { hp: 5, maxHp: 11 };
|
||||||
|
const result = campfireRest(run);
|
||||||
|
expect(result.hp).toBe(8);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("campfireRest does not heal above maxHp", () => {
|
||||||
|
const run = { hp: 10, maxHp: 11 };
|
||||||
|
const result = campfireRest(run);
|
||||||
|
expect(result.hp).toBe(11);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("rewards", () => {
|
describe("rewards", () => {
|
||||||
test("revealRewards removes 3 from rewards deck and returns them", () => {
|
test("revealRewards removes 3 from rewards deck and returns them", () => {
|
||||||
const run = createRunState("ironclad");
|
const run = createRunState("ironclad");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue