-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameEngine.java
63 lines (39 loc) · 1.08 KB
/
GameEngine.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
// thread that makes mechanics go, executes actions at the right time, etc
public class GameEngine implements Runnable {
private Game parent;
private static final int delay=50; //in ms
private boolean running;
public GameEngine(Game g) {
parent=g;
running=false;
} //constructor
public synchronized void run() {
try {
while(true) {
wait(delay);
if(running) {
process();
}
}
} catch(InterruptedException e ) {
System.err.println("ERROR: game engine has been interrupted: "+e);
System.exit(1);
}
} //run
private synchronized void process() {
//allow each game character to act (if able and willing):
for(Character c:parent.getData().getAllCharacters()) {
c.decCooldown();
if(c.canAct()) parent.getData().submitAction(c.dequeueAction());
}
//--->all attacks/etc take effect
//send new info to all clients:
Server.updateClientData();
} //process
public synchronized void resume() {
running=true;
} //resume
public synchronized void pause() {
running=false;
} //pause
} //class