So I'm developing a game project that uses RMI (client / server) and needed to manage the players' time-out. For example, if a player takes more than one minute to make his or her respective play, he loses.
The plays run through a loop, so I would need to check each interaction to see if the time is up. I was currently trying to do with the Timer / Schedulel classes, but I do not find a way to "save" the time and check when it's gone.
My question: How can I save / return the time it's currently running? Is there any mick or any class for this? I'm trying to achieve something like, for example:
Timer timer;
int tempoAtual; // Variável para guardar tempo
boolean isAcabou = false; // Variável para verificar termino
public Temporizacao(int seconds) {
timer = new Timer(); // Cria um novo Timer
timer.schedule(new Teste(), seconds*1000); // set tarefa...
}
class Teste extends TimerTask {
public void run() {
// tempoAtual -> atualiza tempo atual (?)
timer.cancel();
isAcabou = true;
}
}
public static void main(String args[]) {
new Temporizacao(5); // set tarefa de 5seg
if(tempoAtual != isAcabou){ // Variável matem o tempo salvo para fazer validações
System.out.println("Acabou tempo.");
}
}