Refactor for reduced nesting

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-tursoandJanne Savolainen committed 2023-03-14 12:43:59 +02:00
1 parent a966c29a2e
commit 0c7db307d6
1 file changed
+10 -8
@@ -11,7 +11,16 @@ const createGame = ({ messageToPlayer, questionToPlayer, castDie }: Dependencies
messageToPlayer(`You encounter a monster with ${monsterHitPoints} hit-points`); messageToPlayer(`You encounter a monster with ${monsterHitPoints} hit-points`);
const playerWantsToAttack = await questionToPlayer("Attack the monster?"); const playerWantsToAttack = await questionToPlayer("Attack the monster?");
if (playerWantsToAttack) { if (!playerWantsToAttack) {
messageToPlayer(
"You chose not to attack the monster, and the monster eats you dead, in disappointment.",
);
messageToPlayer("You lose. Game over!");
return;
}
while (true) { while (true) {
messageToPlayer("You attack the monster."); messageToPlayer("You attack the monster.");
@@ -52,13 +61,6 @@ const createGame = ({ messageToPlayer, questionToPlayer, castDie }: Dependencies
return; return;
} }
} }
}
messageToPlayer(
"You chose not to attack the monster, and the monster eats you dead, in disappointment.",
);
messageToPlayer("You lose. Game over!");
}, },
}); });