-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathCommandLineApp.js
68 lines (58 loc) · 1.62 KB
/
CommandLineApp.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
var readlineSync = require('readline-sync')
var AdaCat = require('./AdaCat')
class CommandLineApp {
constructor() {
this.cat = null
}
start() {
this.setup()
var shouldContinue = true
while (shouldContinue) {
this.showCatStatus()
shouldContinue = this.runCommand()
}
}
setup() {
var owner = readlineSync.question('What is your name? ')
var name = readlineSync.question('What would you like to name your cat? ')
this.cat = new AdaCat(name, owner)
}
runCommand() {
var commandIndex = readlineSync.keyInSelect(
['Feed cat', 'Play with cat', 'Tell cat to nap', 'Wake up cat'],
'What would you like to do?'
)
if (commandIndex === -1) {
console.log('byeeeee')
return false
} else if (commandIndex === 0) {
console.log('You feed your cat.')
this.cat.feed()
} else if (commandIndex === 1) {
console.log('You play with your cat.')
this.cat.play()
} else if (commandIndex === 2) {
console.log('Your cat curls up to sleep.')
this.cat.nap()
} else if (commandIndex === 3) {
console.log('Your cat wakes up, yawns, and stretches.')
this.cat.wakeUp()
} else {
console.log("I don't understand :(")
}
return true
}
showCatStatus() {
console.log('')
console.log(' /\\___/\\')
console.log('( o o )')
console.log('( =^= )')
console.log('( )')
console.log('( )')
console.log('( ))))))))))) ')
console.log('')
var catDescription = this.cat.getDescription()
console.log(catDescription)
}
}
module.exports = CommandLineApp