-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd-args.js
35 lines (30 loc) · 1.31 KB
/
cmd-args.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Nothing crazy but simple way I'll do a DEV_MODE for debugging purposes.
// Building a game from one of my students projects called Zork so I threw this in there.
// Way better and more effective ways to do this but it serves its purpose.
// More rigorous checks and protection would be needed if dev'ed further or handed out to others.
// --- START DEV DEBUGGING ---
let DEV_MODE = false
if (process.argv.find((arg) => arg === '--dev_mode' || arg === '-d')) DEV_MODE = true
// ---- END DEV DEBUGGING ----
// Then do stuff like this. You'll find this is a lot of libs.
// Wrapped in an IFEE also to get the game going vs calling a fx.
// Common in games to have a do/while type of loop since games are loops, respectively.
// I've rarely use while loops across my career so this is a less likely thing you'll see in my code.
const game = (async function () {
console.clear()
console.log(prompts.intro)
do {
if (DEV_MODE) {
console.log('\n------------ DEV MODE ------------')
console.log(state)
console.log('----------------------------------')
}
// Exit the game on win or replay
// if (state.winGame) {
// await sendResponse(prompts.win)
// handleGameEnd()
// }
const playerInput = await promptPlayer()
handlePlayerInput(playerInput)
} while (!state.winGame)
})()