-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
199 lines (161 loc) · 3.09 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
var navigation = {
x: -2,
y: 4,
z: 7,
speed: "raaaaid"
};
var ship = {
powerOn: false,
modules: [],
antenna: {
active: false
}
};
var radio = {
range: {
low: 88,
high: 108,
},
frequency: 0,
message: "Bugs are cool.",
beacon: false
};
var essential;
function powerOn() {
if (ship.powerOn = false) {
ship.powerOn = true;
}
}
function countModules() {
return availableModules.length;
}
function countEssential() {
for(var i = 0; i < countModules(); i++) {
if(availableModules[i].essential) {
essential++;
}
}
return essential;
}
function loadModule(index) {
availableModules[index].enabled = true;
ship.modules.push(availableModules[index]);
}
function getLifeSupport() {
var arrayLength = countModules();
for(var i = 0; i < arrayLength; i++){
if(availableModules[i].name == "life-support") {
loadModule(i);
}
}
}
getLifeSupport();
function findModuleIndex(name) {
for(var i = 0; i < countModules(); i++) {
if(availableModules[i].essential && availableModules[i].name == name) {
return i;
}
}
}
loadModule(findModuleIndex("propulsion"));
loadModule(findModuleIndex("navigation"));
function resetLARRY() {
for(var i = 0; i < 10; i++) {
LARRY.quack();
}
}
resetLARRY();
findModuleIndex("communication");
loadModule(findModuleIndex("communication"));
function setMessage() {
radio.message = JSON.stringify(navigation);
}
setMessage();
function activateBeacon() {
radio.beacon = true;
}
activateBeacon();
function setFrequency() {
radio.frequency = (radio.range.low + radio.range.high) / 2;
}
function initialize() {
navigation.x = 0;
navigation.y = 0;
navigation.z = 0;
}
function calibrateX() {
for(var i = 0; i < 13; i++) {
var signal = checkSignal();
if(signal !== undefined) {
navigation.x = signal;
break;
}
}
}
function calibrateY() {
for(var i = 0; i < 61; i++) {
var signal = checkSignal();
if(signal !== undefined) {
navigation.y = signal;
break;
}
}
}
function calibrateZ() {
for(var i = 0; i < 61; i++) {
var signal = checkSignal();
if(signal !== undefined) {
navigation.z = signal;
break;
}
}
}
function calibrate() {
calibrateX();
calibrateY();
calibrateZ();
}
function setSpeed(speed) {
var speed = parseInt(speed);
if(speed >= 0) {
navigation.speed = speed;
}
}
function activateAntenna() {
ship.antenna.active = true;
}
activateAntenna();
function sendBroadcast() {
for(var i = 0; i < 101; i++) {
broadcast();
}
}
function disableFrequency() {
radio.frequency = 0;
}
function configureBroadcast() {
disableFrequency();
setFrequency();
activateAntenna();
sendBroadcast();
}
configureBroadcast();
function decodeMessage(message){
var decryptedMessage = message
.replace(/1/g,'i')
.replace(/2/g,'u')
.replace(/3/g,'e')
.replace(/4/g,'a')
.replace(/5/g,'y')
.replace(/0/g,'o');
return decryptedMessage;
}
function returnToEarth() {
var x = broadcast('x');
var y = broadcast('y');
var z = broadcast('z');
navigation.x = parseInt(decodeMessage(x), 16);
navigation.y = parseInt(decodeMessage(y), 16);
navigation.z = parseInt(decodeMessage(z), 16);
}
returnToEarth();