mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
final UUID initPlayerId = playerId;
|
||||
long delay = 250L; // run each 250 seconds
|
||||
PriorityTimer timer = new PriorityTimer(count, delay, new Action() {
|
||||
long delayMs = 250L; // run each 250 ms
|
||||
|
||||
Action executeOnNoTimeLeft = new Action() {
|
||||
@Override
|
||||
public void execute() throws MageException {
|
||||
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);
|
||||
timer.init();
|
||||
return timer;
|
||||
|
|
Loading…
Reference in a new issue