1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/kata-for-gabriel/src/handle-initial-monster-encounter.injectable.ts
Iku-turso a38a06f916 Make monster pool extendable instead of single hard-coded monster
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2023-03-15 11:09:02 +02:00

34 lines
1.1 KiB
TypeScript

import { getInjectable } from "@ogre-tools/injectable";
import messageToPlayerInjectable from "./message-to-player.injectable";
import questionToPlayerInjectable from "./question-to-player.injectable";
import monsterInjectable from "./monster.injectable";
const handleInitialMonsterEncounterInjectable = getInjectable({
id: "handle-initial-monster-encounter",
instantiate: (di) => {
const messageToPlayer = di.inject(messageToPlayerInjectable);
const questionToPlayer = di.inject(questionToPlayerInjectable);
const monster = di.inject(monsterInjectable);
return async () => {
messageToPlayer(`You encounter a monster "${monster.name}" with ${monster.hitPoints} hit-points`);
const playerWantsToAttack = await questionToPlayer("Attack the monster?");
if (playerWantsToAttack) {
return { gameIsOver: false };
}
messageToPlayer(
"You chose not to attack the monster, and the monster eats you dead, in disappointment.",
);
messageToPlayer("You lose. Game over!");
return { gameIsOver: true };
};
},
});
export default handleInitialMonsterEncounterInjectable;