forked from LaunchCodeEducation/Mars-Rover-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rover.js
41 lines (34 loc) · 1.02 KB
/
rover.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
class Rover {
constructor(position) {
this.position = position;
this.mode = 'NORMAL';
this.generatorWatts = 110;
}
receiveMessage(message) {
let status = [];
for (let command of message.commands) {
if (command.commandType === 'MODE_CHANGE') {
this.mode = command.value;
status.push({ completed: true });
} else if (command.commandType === 'MOVE') {
if (this.mode === 'LOW_POWER') {
status.push({ completed: false });
} else {
this.position = command.value;
status.push({ completed: true });
}
} else if (command.commandType === 'STATUS_CHECK') {
status.push({
completed: true,
roverStatus: {
mode: this.mode,
generatorWatts: this.generatorWatts,
position: this.position,
},
});
}
}
return { message: message.name, status };
}
}
module.exports = Rover;