This commit is contained in:
BetaSteward 2010-04-16 03:50:35 +00:00
parent ca4281ed2d
commit ee760de985
9 changed files with 52 additions and 15 deletions

View file

@ -82,7 +82,7 @@ public abstract class GameImpl implements Game, Serializable {
protected GameState state; protected GameState state;
protected UUID startingPlayerId; protected UUID startingPlayerId;
protected UUID choosingPlayerId; protected UUID choosingPlayerId;
protected String winner; protected Player winner;
protected GameStates gameStates; protected GameStates gameStates;
public GameImpl() { public GameImpl() {
@ -147,7 +147,9 @@ public abstract class GameImpl implements Game, Serializable {
@Override @Override
public String getWinner() { public String getWinner() {
return winner; if (winner == null)
return "Game is a draw";
return "Player " + winner.getName() + " is the winner";
} }
@Override @Override
@ -225,16 +227,18 @@ public abstract class GameImpl implements Game, Serializable {
} }
} }
for (Player player: state.getPlayers().values()) { winner = findWinner();
if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) {
winner = "Player " + player.getName() + " is the winner"; saveState();
break;
}
} }
if (winner == null) protected Player findWinner() {
winner = "Game is a draw"; for (Player player: state.getPlayers().values()) {
saveState(); if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) {
return player;
}
}
return null;
} }
protected void endOfTurn() { protected void endOfTurn() {

View file

@ -30,7 +30,6 @@ package mage.players;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Deque; import java.util.Deque;
import java.util.Iterator; import java.util.Iterator;
@ -49,6 +48,8 @@ import mage.util.Copier;
*/ */
public class Library implements Serializable { public class Library implements Serializable {
// private static final transient Copier<Library> copier = new Copier<Library>();
private static Random rnd = new Random(); private static Random rnd = new Random();
private boolean emptyDraw = false; private boolean emptyDraw = false;
@ -81,6 +82,10 @@ public class Library implements Serializable {
return card; return card;
} }
public Card getFromTop(Game game) {
return library.peekFirst();
}
public void putOnTop(Card card, Game game) { public void putOnTop(Card card, Game game) {
if (card.getOwnerId().equals(playerId)) if (card.getOwnerId().equals(playerId))
library.addFirst(card); library.addFirst(card);

View file

@ -136,6 +136,7 @@ public interface Player extends MageItem {
public void declareAttacker(UUID attackerId, UUID defenderId, Game game); public void declareAttacker(UUID attackerId, UUID defenderId, Game game);
public void declareBlocker(UUID blockerId, UUID attackerId, Game game); public void declareBlocker(UUID blockerId, UUID attackerId, Game game);
public boolean hasAvailableAttackers(Game game);
public void beginTurn(); public void beginTurn();
public void endOfTurn(Game game); public void endOfTurn(Game game);

View file

@ -51,6 +51,7 @@ import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.counters.Counters; import mage.counters.Counters;
import mage.filter.common.FilterCreatureForAttack;
import mage.game.Game; import mage.game.Game;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -67,6 +68,7 @@ import mage.util.Copier;
public abstract class PlayerImpl implements Player, Serializable { public abstract class PlayerImpl implements Player, Serializable {
// private static final transient Copier<Player> copier = new Copier<Player>();
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected UUID playerId; protected UUID playerId;
@ -661,4 +663,16 @@ public abstract class PlayerImpl implements Player, Serializable {
return false; return false;
} }
@Override
public boolean hasAvailableAttackers(Game game) {
return getAvailableAttackers(game).size() > 0;
}
protected List<Permanent> getAvailableAttackers(Game game) {
FilterCreatureForAttack attackFilter = new FilterCreatureForAttack();
attackFilter.getControllerId().add(playerId);
List<Permanent> attackers = game.getBattlefield().getActivePermanents(attackFilter);
return attackers;
}
} }

View file

@ -128,7 +128,7 @@ public abstract class TargetImpl implements Target {
@Override @Override
public boolean choose(Outcome outcome, Game game) { public boolean choose(Outcome outcome, Game game) {
Player player = game.getPlayer(this.source.getControllerId()); Player player = game.getPlayer(this.source.getControllerId());
while (!isChosen()) { while (!isChosen() && !doneChosing()) {
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= minNumberOfTargets;
if (!player.chooseTarget(outcome, this, game)) { if (!player.chooseTarget(outcome, this, game)) {
return chosen; return chosen;
@ -140,7 +140,7 @@ public abstract class TargetImpl implements Target {
break; break;
} }
} }
return true; return chosen = true;
} }

View file

@ -85,6 +85,10 @@ public class TargetPermanent extends TargetObject {
return false; return false;
} }
public void setTargetController(TargetController controller) {
this.controller = controller;
}
protected void setController(UUID controllerId, Game game) { protected void setController(UUID controllerId, Game game) {
filter.getControllerId().clear(); filter.getControllerId().clear();
switch (controller) { switch (controller) {

View file

@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.net.URLClassLoader;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -97,7 +96,7 @@ public class Copier<T> {
public T uncompressCopy(byte[] buffer) { public T uncompressCopy(byte[] buffer) {
T copy = null; T copy = null;
try { try {
ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(buffer))); ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer)));
copy = (T) in.readObject(); copy = (T) in.readObject();
} }
catch(IOException e) { catch(IOException e) {

View file

@ -36,6 +36,7 @@ import java.util.Date;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -54,6 +55,14 @@ public class Logging {
return logger; return logger;
} }
public static Level getLevel(Logger logger) {
Level level = logger.getLevel();
while (level == null && logger.getParent() != null) {
logger = logger.getParent();
level = logger.getLevel();
}
return level;
}
} }
class LogFormatter extends Formatter { class LogFormatter extends Formatter {

View file

@ -29,6 +29,7 @@
package mage.watchers; package mage.watchers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -50,9 +51,9 @@ public class Watchers extends ArrayList<Watcher> {
} }
} }
public Watcher get(String key) { public Watcher get(UUID controllerId, String key) {
for (Watcher watcher: this) { for (Watcher watcher: this) {
if (watcher.getKey().equals(key)) if (watcher.getControllerId().equals(controllerId) && watcher.getKey().equals(key))
return watcher; return watcher;
} }
return null; return null;