-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (79 loc) · 2.68 KB
/
index.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
const inquirer = require('inquirer');
const figlet = require('figlet');
const chalk = require('chalk');
const clear = require('clear');
const _ = require('lodash');
const say = require('say');
const pjson = require('./package.json');
const menu = require('./modules/menu');
inquirer.registerPrompt('emoji', require('inquirer-emoji'))
clear();
console.log(
chalk.yellow(
figlet.textSync("eePC", { horizontalLayout: 'full' })
),
chalk.white(
`\n${pjson.description}`,
`\nv${pjson.version}`,
`\nAuthor: ${pjson.author}`,
)
)
let inquiry = (choice) => {
let answer = _.isNil(choice) ? _.sample(_.keysIn(menu.structure)) : choice
say.speak(`Let's play ${answer}`, null, null, () => {
let questionType = menu.structure[answer].type;
let randomNumber = _.sample(menu.structure[answer].opcs);
let instructions = `Type on the keyboard the ${questionType} ${randomNumber}`;
clear();
console.log(
chalk.white(
figlet.textSync(_.toUpper(randomNumber))
)
);
say.speak(instructions, null, null, () => {
inquirer.prompt([
{
type: 'input',
name: 'typed',
message: `Your guess:`
}
])
.then(answer => answer.typed)
.then(typed => {
let result = {
state: _.isEqual(_.toString(typed), _.toString(randomNumber)),
text: _.isEqual(_.toString(typed), _.toString(randomNumber)) ? 'correct' : 'incorrect'
}
let response = `You typed ${typed}, which is ${result.text}`
console.log(
chalk.yellow(
figlet.textSync(_.toUpper(typed))
),
chalk.white(
figlet.textSync('is')
),
result.state ? chalk.green(
figlet.textSync(result.text)
) : chalk.red(
figlet.textSync(result.text)
),
)
say.speak(response, null, null, () => {
inquiry()
})
})
})
})
}
// let menus = () => {
// return inquirer.prompt([
// {
// type: 'list',
// name: 'choice',
// message: 'What do you want?',
// choices: _.keysIn(menu.structure)
// },
// ]).then(answers => {
// })
// }
inquiry()