-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
91 lines (83 loc) · 2.31 KB
/
test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Heirarchical conversation example
*/
'use strict';
var inquirer = require('..');
var directionsPrompt = {
type: 'list',
name: 'direction',
message: 'Which direction would you like to go?',
choices: ['Forward', 'Right', 'Left', 'Back']
};
function main() {
console.log('You find youself in a small room, there is a door in front of you.');
exitHouse();
}
function exitHouse() {
inquirer.prompt(directionsPrompt).then(answers => {
if (answers.direction === 'Forward') {
console.log('You find yourself in a forest');
console.log(
'There is a wolf in front of you; a friendly looking dwarf to the right and an impasse to the left.'
);
encounter1();
} else {
console.log('You cannot go that way. Try again');
exitHouse();
}
});
}
function encounter1() {
inquirer.prompt(directionsPrompt).then(answers => {
var direction = answers.direction;
if (direction === 'Forward') {
console.log('You attempt to fight the wolf');
console.log(
'Theres a stick and some stones lying around you could use as a weapon'
);
encounter2b();
} else if (direction === 'Right') {
console.log('You befriend the dwarf');
console.log('He helps you kill the wolf. You can now move forward');
encounter2a();
} else {
console.log('You cannot go that way');
encounter1();
}
});
}
function encounter2a() {
inquirer.prompt(directionsPrompt).then(answers => {
var direction = answers.direction;
if (direction === 'Forward') {
var output = 'You find a painted wooden sign that says:';
output += ' \n';
output += ' ____ _____ ____ _____ \n';
output += '(_ _)( _ )( _ \\( _ ) \n';
output += ' )( )(_)( )(_) ))(_)( \n';
output += ' (__) (_____)(____/(_____) \n';
console.log(output);
} else {
console.log('You cannot go that way');
encounter2a();
}
});
}
function encounter2b() {
inquirer
.prompt({
type: 'list',
name: 'weapon',
message: 'Pick one',
choices: [
'Use the stick',
'Grab a large rock',
'Try and make a run for it',
'Attack the wolf unarmed'
]
})
.then(() => {
console.log('The wolf mauls you. You die. The end.');
});
}
module.exports = main;