diff --git a/puzzles/puzzle_11.json b/puzzles/puzzle_11.json new file mode 100644 index 0000000..3c7c668 --- /dev/null +++ b/puzzles/puzzle_11.json @@ -0,0 +1,11 @@ +{ + "code": "6001600054141560155736153460001415166075575B3460001415601F57FD5B6001600055366000803736600036348152603B81602001526064565B9050803403813652604E36602001526064565B01929190f0600080808080945AF1504714607557FD5B600536518181069003043660200151565B00", + "askForValue": true, + "askForData": true, + "askNeedHint": [5, 8, 10], + "hints": [ + "TG9vayBmb3IgYSBmdW5jdGlvbiAoYWthIEpVTVBzIHRvIHRoZSBzYW1lIGxvY2F0aW9uKSBpbiB0aGUgaW5zdHJ1Y3Rpb25zIGFib3Zl", + "VGhlcmUgaXMgYSBDUkVBVEUgb3Bjb2RlIGluIHRoZSBpbnN0cnVjdGlvbnMgYWJvdmUuIE1heWJlIHlvdSBuZWVkIHRvIHN1cHBseSBhIGNvbnRyYWN0J3MgYnl0ZWNvZGU/", + "cHJhZ21hIHNvbGlkaXR5IDAuOC4xMDsKCmNvbnRyYWN0IEZsb29yMjBQZXJjZW50IHsKICAgIGNvbnN0cnVjdG9yKCkgcGF5YWJsZSB7fQoKICAgIGZhbGxiYWNrICgpIGV4dGVybmFsIHBheWFibGUgewogICAgICAgIHVpbnQyNTYgYmFsYW5jZSA9IGFkZHJlc3ModGhpcykuYmFsYW5jZTsKICAgICAgICB1aW50MjU2IHZhbCA9ICgoYmFsYW5jZS0oYmFsYW5jZSAlIDUpKS81KTsKICAgICAgICAoYm9vbCBzdWNjZXNzLCApID0gbXNnLnNlbmRlci5jYWxse3ZhbHVlOiB2YWx9KCIiKTsKICAgIH0KfQ==" + ] +} diff --git a/src/play.js b/src/play.js index e1d82a3..65414cc 100644 --- a/src/play.js +++ b/src/play.js @@ -6,6 +6,7 @@ const chalk = require("chalk"); const { getOpcode } = require("./opcodes"); module.exports.play = async function play() { + let attempts = 0; while (true) { const puzzle = getNextPuzzle(); @@ -17,6 +18,7 @@ module.exports.play = async function play() { const solution = await playPuzzle(puzzle); if (solution) { + attempts = 0; saveSolution(puzzle.number, solution); if (await askPlayNext()) { @@ -25,6 +27,8 @@ module.exports.play = async function play() { process.exit(0); } } else { + await checkHints(puzzle, ++attempts); + if (!(await askTryAgain())) { console.log("Thanks for playing!"); process.exit(0); @@ -86,6 +90,31 @@ async function askTryAgain() { return answers.tryAgain; } +async function askNeedHint() { + const answers = await inquirer.prompt([ + { + type: "confirm", + name: "needHint", + message: "Would you like a hint?" + } + ]); + + console.log(); + + return answers.needHint; +} + +async function checkHints(puzzle, attempts) { + const numHints = puzzle.hints ? puzzle.hints.length : 0 ; + if (numHints > 0 && + puzzle.askNeedHint.includes(attempts) && + await askNeedHint()) { + const hintIndex = puzzle.askNeedHint.indexOf(attempts); + console.log(`This is hint ${chalk.yellow(`#${hintIndex+1}`)} out of ${chalk.blueBright(numHints)}. Base64 decode the following:\n`); + console.log(chalk.green(puzzle.hints[hintIndex]), "\n"); + } +} + function printCode(code) { code = code.toUpperCase(); let i = 0;