-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.js
46 lines (39 loc) · 1.03 KB
/
hangman.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
36
37
38
39
40
41
42
43
44
45
46
//Require module dependencies
var inquirer = require('inquirer');
var Game = require('./_game.js');
//Initialize Game module with a new game
function newGame(){
var game = new Game();
game.setUpGame();
game.update();
playGame(game);
}
function playGame(game){
//Prompts the user to guess a later and runs the funcitons on the constructor
inquirer.prompt({
type: 'input',
name: 'guess',
message: 'Guess a letter: '
})
.then(function(answer){
game.guess(answer.guess);
//check if the user won or lost.
if(game.word.display().indexOf('_') === -1){
console.log('=========================\nCongrats you won the game\n=========================');
return newGame();
} else if (game.remainingGuesses === 0){
//Game Over and play Again
console.log("\nGame Over: The word was: " + game.word.currentWord + '\n');
return newGame();
}
//Recursively keep playing the game until one of the win conditions is met.
playGame(game);
})
}
//Start Game
newGame();
//Display Word
//Prompt Guess
//Guess logic
//Update
//If