forked from LaunchCodeEducation/launchcode.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrover.js
More file actions
36 lines (30 loc) · 1.39 KB
/
rover.js
File metadata and controls
36 lines (30 loc) · 1.39 KB
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
class Rover {
constructor(position, mode ='NORMAL', generatorWatts = 110){
this.position = position;
this.mode = mode;
this.generatorWatts = generatorWatts;
}
receiveMessage(message){
let response = {
message: message.name,
results: [],
};
for(let i=0; i<message.commands.length; i++){
if (message.commands[i].commandType === 'STATUS_CHECK'){
response.results.push({completed: true, roverStatus: {mode: this.mode, generatorWatts: this.generatorWatts, position: this.position}});
}else if (message.commands[i].commandType === 'MODE_CHANGE'){
this.mode = message.commands[i].value
response.results.push({completed: true, roverStatus: {mode: this.mode, generatorWatts: this.generatorWatts, position: this.position}});
}else if (message.commands[i].commandType === 'MOVE'){
if(this.mode === 'LOW_POWER'){
response.results.push({completed: false, roverStatus: {mode: this.mode, generatorWatts: this.generatorWatts, position: this.position}});
}else {
this.position = message.commands[i].value
response.results.push({completed: true, roverStatus: {mode: this.mode, generatorWatts: this.generatorWatts, position: this.position }});
}
}
}
return response
}
}
module.exports = Rover;