-
Notifications
You must be signed in to change notification settings - Fork 0
/
Universe.java
138 lines (109 loc) · 2.79 KB
/
Universe.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.util.*;
import java.awt.event.*;
import javax.swing.Timer;
public class Universe {
private int simulatorClock, aircrafts, crashes, landings;
private static final Universe instance = new Universe();
private AircraftSpecsDatabase airSpecsDB;
private AirportDatabase airportsDB;
private Map myMap;
private FlightsDatabase flightDB;
private Display display;
private Timer timer;
private ArrayList<String> messages;
private String fileID = "default";
private Universe() {
};
// Updated universe after time dt in seconds
public void integrate(double dt) {
aircrafts = flightDB.countActiveFlights();
display.refresh();
flightDB.integrate(dt);
increaseSimulatorClock(CONSTANTS.DELAY);
}
public void loadNew(String id) {
simulatorClock = 0;
aircrafts = 0;
crashes = 0;
landings = 0;
messages = new ArrayList<String>();
myMap = new Map("data/world_" + id + ".txt");
airportsDB = new AirportDatabase("data/airports_" + id + ".txt");
flightDB = new FlightsDatabase("data/flights_" + id + ".txt");
display.putContent();
display.refresh();
this.init();
}
public void createDisplay() {
display = new Display();
display.putContent();
}
// Tells database to init simulation
private void init() {
flightDB.init();
display.refresh();
}
// Sets timer
public void setTimer(Timer timer) {
this.timer = timer;
}
public void startTimer() {
display.refresh();
timer.start();
}
public void stopTimer() {
display.refresh();
timer.stop();
}
public static Universe getInstance() {
return instance;
}
public int getSimulatorClock() {
return simulatorClock;
}
public int getAircrafts() {
return aircrafts;
}
public int getCrashes() {
return crashes;
}
public int getLandings() {
return landings;
}
public Display getDisplay() {
return display;
}
public void increaseAircrcafts() {
aircrafts++;
}
public void increaseCrashes() {
crashes++;
}
public void increaseLandings() {
landings++;
}
public void increaseSimulatorClock(int intervalInSeconds) {
simulatorClock += intervalInSeconds;
}
public void addMessage(String m) {
messages.add(m);
}
public ArrayList<String> getMessages() {
return messages;
}
public AirportDatabase getAirportsDatabase() {
return airportsDB;
}
public Map getMap() {
return myMap;
}
public FlightsDatabase getFlightsDatabase() {
return flightDB;
}
public String getFileID() {
return fileID;
}
public void setFileID(String id) {
fileID = id;
}
}