kill the next round timer when a game resets due to losing players
This commit is contained in:
parent
0f14cb781c
commit
3fd597b580
|
@ -68,6 +68,8 @@ public class Game {
|
||||||
private final int maxPlayers = 10;
|
private final int maxPlayers = 10;
|
||||||
private int judgeIndex = 0;
|
private int judgeIndex = 0;
|
||||||
private final static int ROUND_INTERMISSION = 8 * 1000;
|
private final static int ROUND_INTERMISSION = 8 * 1000;
|
||||||
|
private Timer nextRoundTimer;
|
||||||
|
private final Object nextRoundTimerLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Injection here would be much nicer, but that would need a Provider for the id... Too much
|
* TODO Injection here would be much nicer, but that would need a Provider for the id... Too much
|
||||||
|
@ -367,7 +369,12 @@ public class Game {
|
||||||
* previous game finished.
|
* previous game finished.
|
||||||
*/
|
*/
|
||||||
private void resetState(final boolean lostPlayer) {
|
private void resetState(final boolean lostPlayer) {
|
||||||
// Reset the game.
|
synchronized (nextRoundTimerLock) {
|
||||||
|
if (nextRoundTimer != null) {
|
||||||
|
nextRoundTimer.cancel();
|
||||||
|
nextRoundTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
synchronized (players) {
|
synchronized (players) {
|
||||||
for (final Player player : players) {
|
for (final Player player : players) {
|
||||||
player.getHand().clear();
|
player.getHand().clear();
|
||||||
|
@ -584,13 +591,15 @@ public class Game {
|
||||||
data.put(LongPollResponse.PLAYER_INFO, getPlayerInfo(cardPlayer));
|
data.put(LongPollResponse.PLAYER_INFO, getPlayerInfo(cardPlayer));
|
||||||
broadcastToPlayers(MessageType.GAME_PLAYER_EVENT, data);
|
broadcastToPlayers(MessageType.GAME_PLAYER_EVENT, data);
|
||||||
|
|
||||||
final Timer timer = new Timer();
|
synchronized (nextRoundTimerLock) {
|
||||||
timer.schedule(new TimerTask() {
|
nextRoundTimer = new Timer();
|
||||||
|
nextRoundTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
startNextRound();
|
startNextRound();
|
||||||
}
|
}
|
||||||
}, ROUND_INTERMISSION);
|
}, ROUND_INTERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue