Some change to match timer (in progress).

This commit is contained in:
LevelX2 2013-07-06 00:43:39 +02:00
parent f540e78045
commit 0eaf9dd268
4 changed files with 22 additions and 3 deletions

View file

@ -592,7 +592,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
protected void init(UUID choosingPlayerId, GameOptions gameOptions) { protected void init(UUID choosingPlayerId, GameOptions gameOptions) {
for (Player player: state.getPlayers().values()) { for (Player player: state.getPlayers().values()) {
player.beginTurn(this); player.beginTurn(this);
if (priorityTime > 0) { // init only if match is with timer (>0) and time left was not set yet (== MAX_VALUE).
// otherwise the priorityTimeLeft is set in {@link MatchImpl.initGame)
if (priorityTime > 0 && player.getPriorityTimeLeft() == Integer.MAX_VALUE) {
initTimer(player.getId()); initTimer(player.getId());
} }
} }

View file

@ -170,6 +170,10 @@ public abstract class MatchImpl implements Match {
game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId());
game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId());
game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck()); game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck());
// set the priority time left for the match
if (matchPlayer.getPriorityTimeLeft() > 0) {
matchPlayer.getPlayer().setPriorityTimeLeft(matchPlayer.getPriorityTimeLeft());
}
} }
} }
game.setPriorityTime(options.getPriorityTime()); game.setPriorityTime(options.getPriorityTime());
@ -185,6 +189,10 @@ public abstract class MatchImpl implements Match {
for (MatchPlayer player: this.players) { for (MatchPlayer player: this.players) {
Player p = game.getPlayer(player.getPlayer().getId()); Player p = game.getPlayer(player.getPlayer().getId());
if (p != null) { if (p != null) {
// get the left time from player priority timer
if (game.getPriorityTime() > 0) {
player.setPriorityTimeLeft(p.getPriorityTimeLeft());
}
if (p.hasQuitted()) { if (p.hasQuitted()) {
player.setQuitted(true); player.setQuitted(true);
} }

View file

@ -44,6 +44,7 @@ public class MatchPlayer {
private Player player; private Player player;
private boolean quitted; private boolean quitted;
private boolean doneSideboarding; private boolean doneSideboarding;
private int priorityTimeLeft;
public MatchPlayer(Player player, Deck deck) { public MatchPlayer(Player player, Deck deck) {
this.player = player; this.player = player;
@ -54,6 +55,14 @@ public class MatchPlayer {
this.quitted = false; this.quitted = false;
} }
public int getPriorityTimeLeft() {
return priorityTimeLeft;
}
public void setPriorityTimeLeft(int priorityTimeLeft) {
this.priorityTimeLeft = priorityTimeLeft;
}
public int getWins() { public int getWins() {
return wins; return wins;
} }

View file

@ -231,7 +231,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.passedTurn = player.passedTurn; this.passedTurn = player.passedTurn;
this.passedAllTurns = player.passedAllTurns; this.passedAllTurns = player.passedAllTurns;
this.priorityTimeLeft = player.getPriorityTimeLeft();
} }
@Override @Override
@ -278,7 +278,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.turnController = player.getTurnControlledBy(); this.turnController = player.getTurnControlledBy();
this.passed = player.isPassed(); this.passed = player.isPassed();
this.priorityTimeLeft = player.getPriorityTimeLeft();
} }
@Override @Override