-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-star.js
46 lines (40 loc) · 1.32 KB
/
main-star.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
var Packet = require('./Packet');
var Cable = require('./Cable');
var Computer = require('./Computer');
var Server = require('./Server');
var topology = document.getElementById('topology');
var server = new Server();
function generateStar(target, computersNum, cableLength) {
var computers = [];
var node;
var tmpCable;
var cableNode;
for (let i = 0; i < computersNum; i += 1) {
node = new Computer(null, `PC${i}`);
tmpCable = [];
for (let j = 0; j < cableLength; j += 1) {
cableNode = new Cable(null);
tmpCable.push(cableNode);
}
node.join(tmpCable[0], 0);
tmpCable[0].join(node, 1);
for (let j = 0; j < cableLength - 1; j += 1) {
tmpCable[j].join(tmpCable[j + 1], 0);
tmpCable[j + 1].join(tmpCable[j], 1);
}
tmpCable[tmpCable.length - 1].join(server, 0);
server.join(tmpCable[tmpCable.length - 1], node.label);
computers.push(node);
}
for (const me of computers) {
for (const node of computers) {
if (node !== me) {
me.addDestination(node);
}
}
}
}
var numComputers = prompt("Ile komputerów?", 4);
var numCable = prompt("Jaka długość kabla?", 4);
generateStar(topology, numComputers, numCable);
console.log(server);