package Server;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Queue;
import clientMessages.ClientEventIn;
import serverMessages.ClientEventOut;
public class ServerLogic extends Thread {
private GameTimer Clock;
private GameState currentState;
private UdpBroadCast udp;
public Queue<ClientEventOut> EventQue;
public ServerLogic(UdpBroadCast u, Queue<ClientEventOut> q) {
// Clock=new GameTimer();
currentState = new GameState(u);
udp = u; // alias
EventQue = q;
}
public void run() {
while (ServerMain.On) {
new javax.swing.Timer(60, new ActionListener() {
public void actionPerformed(ActionEvent e) {
// /process stuff
for (int i = 0; i < EventQue.size(); i++) {
ClientEventOut c = EventQue.poll(); // check if allowed....
if (!(c == null))
c.modifyGameState(currentState);
}
currentState.tick();
}
}).start();
try {
Thread.sleep(60);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// make sure at least 1/30th of second has passed.
}
}
}