-
Notifications
You must be signed in to change notification settings - Fork 0
/
Airport.java
120 lines (103 loc) · 3.29 KB
/
Airport.java
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
import java.io.*;
import java.util.*;
public class Airport {
public static final int NORTH = 1, EAST = 2, SOUTH = 3, WEST = 4;
private int id, direction, category;
private Position position; // In miles
private PrecisePosition precisePosition;
private Position gridPosition;
private boolean open;
private String name;
private PrecisePosition gatePoint;
public Airport(int id, int positionRow, int positionColumn, String name, int direction, int category, boolean open) {
this.id = id;
this.gridPosition = new Position(positionRow, positionColumn);
this.name = name;
this.direction = direction;
this.category = category;
this.open = open;
double x = CONSTANTS.TILE_SIZE_IN_MILES * positionColumn + CONSTANTS.TILE_SIZE_IN_MILES / 2;
double y = CONSTANTS.TILE_SIZE_IN_MILES * positionRow + CONSTANTS.TILE_SIZE_IN_MILES / 2;
this.precisePosition = new PrecisePosition(x, y);
this.position = new Position((int) x, (int) y);
this.gatePoint = findGatePoint();
}
public PrecisePosition getPrecisePosition() {
return precisePosition;
}
public int getDegrees() {
return (direction - 1) * 90;
}
public boolean isOpen() {
return open;
}
public int getID() {
return id;
}
public Position getPosition() {
return position;
}
public Position getGridPosition() {
return gridPosition;
}
public int getDirection() {
return direction;
}
public int getCategory(){
return category;
}
public String getName() {
return name;
}
public PrecisePosition getGatePoint() {
return gatePoint;
}
public void print() {
System.out.println("Airport ID:" + id + " name:" + name + " direction:" + direction + " category:" + category + " open:" + open);
position.print();
}
public boolean acceptsAircraft(AircraftSpecs aircraft) {
int aircraftType = aircraft.getType();
if (this.category == 3) {
return true;
}
if (this.category == 2) {
if (aircraftType == CONSTANTS.JET ||
aircraftType == CONSTANTS.TURBO) {
return true;
}
return false;
}
if (this.category == 1) {
if (aircraftType == CONSTANTS.SINGLE_ENGINE) {
return true;
}
return false;
}
return false;
}
// Findts the gate point (place for entrance) for the airport area
private PrecisePosition findGatePoint() {
double x = (double) position.getX();
double y = (double) position.getY();
switch (this.getDirection()) {
case Airport.NORTH :
y -= CONSTANTS.TILE_SIZE_IN_MILES / 2;
break;
case Airport.EAST :
x += CONSTANTS.TILE_SIZE_IN_MILES / 2;
break;
case Airport.SOUTH :
y += CONSTANTS.TILE_SIZE_IN_MILES / 2;
break;
case Airport.WEST :
x -= CONSTANTS.TILE_SIZE_IN_MILES / 2;
break;
}
return new PrecisePosition(x, y);
}
public String stringify() {
String s = "ID:" + id + " | Name:" + name + " | Direction: " + direction + " | category: " + category + " | open: " + open + "\n";
return s;
}
}