-
Notifications
You must be signed in to change notification settings - Fork 0
/
Landed.js
80 lines (75 loc) · 2.32 KB
/
Landed.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
var Storage = require('./Storage');
exports.Airports = [];
exports.PlaneLanded = function(plane) {
let destination = plane.destination;
let foundAirport = findAirportinAirports(plane)
if(foundAirport == false){
foundAirport = NewAirport(destination);
}
let foundPlane = findPlaneinAirport(plane, foundAirport);
if(foundPlane == false){
foundAirport.Planes.push(plane)
}else{
foundPlane = plane;
}
}
exports.PlaneTookOff = function(plane) {
let destination = plane.destination
let foundAirport = findAirportinAirports(plane);
let foundPlane = findPlaneIndexinAirport(plane, foundAirport);
foundAirport.Planes.splice(foundPlane, 1);
}
function NewAirport(destination) {
exports.Airports.push(new Airport(destination))
return exports.Airports[exports.Airports.length - 1];
}
class Airport{
constructor(destination) {
this.iata = destination.iata;
this.latitude = destination.latitude
this.longitude = destination.longitude
this.Planes = [];
this.Marker = Marker;
}
}
function findAirportinAirports(plane){
for (let i = 0; i < exports.Airports.length; i++) {
let planeiata = plane.posData.destination.iata;
const airport = Airports[i];
if(airport.iata == planeiata){
return exports.Airports[i];
}else{
return false;
}
}
function findPlaneinAirport(plane, airport) {
const planes = airport.Planes;
for (let index = 0; index < planes.length; index++) {
const element = planes[index];
if(plane.hexcode == element.hexcode){
return element;
}else if(plane.tailNumber == element.tailNumber){
return element;
}else{
return false;
}
}
}
}
function createPlaneinAiport(plane,airport){
airport.push(plane);
//Do some stuff after
}
function findPlaneIndexinAirport(plane, airport) {
const planes = airport.Planes;
for (let index = 0; index < planes.length; index++) {
const element = planes[index];
if(plane.hexcode == element.hexcode){
return index;
}else if(plane.tailNumber == element.tailNumber){
return index;
}else{
return false;
}
}
}