mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Added comment explaining how createPlayerTimer works
This commit is contained in:
parent
286a65878d
commit
6ae4546ddb
1 changed files with 17 additions and 4 deletions
|
@ -234,16 +234,29 @@ public class GameController implements GameCallback {
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We create a timer that will run every 250 ms individually for a player decreasing his internal game counter.
|
||||||
|
* Later on this counter is used to get time left to play the whole match.
|
||||||
|
*
|
||||||
|
* What we also do here is passing Action to PriorityTimer that is the action that will be executed once game timer is over.
|
||||||
|
*
|
||||||
|
* @param playerId
|
||||||
|
* @param count
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private PriorityTimer createPlayerTimer(UUID playerId, int count) {
|
private PriorityTimer createPlayerTimer(UUID playerId, int count) {
|
||||||
final UUID initPlayerId = playerId;
|
final UUID initPlayerId = playerId;
|
||||||
long delay = 250L; // run each 250 seconds
|
long delayMs = 250L; // run each 250 ms
|
||||||
PriorityTimer timer = new PriorityTimer(count, delay, new Action() {
|
|
||||||
|
Action executeOnNoTimeLeft = new Action() {
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MageException {
|
public void execute() throws MageException {
|
||||||
game.concede(initPlayerId);
|
game.concede(initPlayerId);
|
||||||
logger.debug("Game timeout for player: " + initPlayerId + ". Conceding.");
|
logger.debug("Player has no time left to end the match: " + initPlayerId + ". Conceding.");
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
PriorityTimer timer = new PriorityTimer(count, delayMs, executeOnNoTimeLeft);
|
||||||
timers.put(playerId, timer);
|
timers.put(playerId, timer);
|
||||||
timer.init();
|
timer.init();
|
||||||
return timer;
|
return timer;
|
||||||
|
|
Loading…
Reference in a new issue