-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (52 loc) · 1.29 KB
/
app.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
var five = require("johnny-five"),
Robot = require('./robot'),
keypress = require('keypress'),
board = new five.Board();
board.on("ready", function () {
'use strict';
var Woodro = new Robot(board, five);
keypress(process.stdin);
console.log(Woodro.prototype);
this.repl.inject({
woodro: Woodro
});
process.stdin.on('keypress', function (ch, key){
if(key.name === 'up'){
Woodro.forward();
}
if(key.name === 'down'){
Woodro.reverse()
}
if(key.name === 'space'){
Woodro.stop();
}
if(key.name === 'left'){
Woodro.left();
}
if(key.name === 'right'){
Woodro.right();
}
if(key.name === 'm'){
Woodro.attackMode();
}
if(key.name === 'p'){
Woodro.peaceMode();
}
if(key.name === 'f'){
Woodro.fire();
}
if(key.name === 'a'){
Woodro.turret.left();
}
if(key.name === 'w'){
Woodro.turret.up();
}
if(key.name === 's'){
Woodro.turret.down();
}
if(key.name === 'd'){
Woodro.turret.right();
}
console.log(key.name);
});
});