forked from drom/animal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animal.js
executable file
·65 lines (57 loc) · 1.7 KB
/
animal.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
#!/usr/bin/env node
// http://pdp-11.trailing-edge.com/rsts11/rsts-11-013/ANIMAL.BAS
'use strict';
var readline = require('readline');
var msg = require('./text.json');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var start, traverse;
traverse = function (parent, path) {
var node = parent[path];
if (typeof node === 'string') {
rl.question(msg.isItA + node + ' ? ', function (answer) {
if (answer.match('y')) { // yes
console.log(msg.again);
start();
} else {
rl.question(msg.itWas, function(itWas) {
rl.question(
msg.differ + itWas + msg.fromA + node + ': ',
function (differ) {
parent[path] = [differ, itWas, node];
console.log(msg.again);
start();
}
);
});
}
});
} else {
rl.question(node[0] + ' ? ', function(answer) {
if (answer.match('y')) { // yes
traverse(node, 1);
} else {
traverse(node, 2);
}
});
}
};
start = function () {
rl.question(msg.mood, function(answer) {
if (answer.match('l')) { // list
console.log(msg.known + JSON.stringify(msg.data, null, 4));
start();
} else {
if (answer.match('y')) { // yes
traverse(msg, 'data');
} else {
console.log(msg.exit);
rl.close();
}
}
});
};
console.log(msg.start);
start();