mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
latest
This commit is contained in:
parent
ca4281ed2d
commit
ee760de985
9 changed files with 52 additions and 15 deletions
|
@ -82,7 +82,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
protected GameState state;
|
||||
protected UUID startingPlayerId;
|
||||
protected UUID choosingPlayerId;
|
||||
protected String winner;
|
||||
protected Player winner;
|
||||
protected GameStates gameStates;
|
||||
|
||||
public GameImpl() {
|
||||
|
@ -147,7 +147,9 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
@Override
|
||||
public String getWinner() {
|
||||
return winner;
|
||||
if (winner == null)
|
||||
return "Game is a draw";
|
||||
return "Player " + winner.getName() + " is the winner";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -225,16 +227,18 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
winner = findWinner();
|
||||
|
||||
saveState();
|
||||
}
|
||||
|
||||
protected Player findWinner() {
|
||||
for (Player player: state.getPlayers().values()) {
|
||||
if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) {
|
||||
winner = "Player " + player.getName() + " is the winner";
|
||||
break;
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
if (winner == null)
|
||||
winner = "Game is a draw";
|
||||
saveState();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void endOfTurn() {
|
||||
|
|
|
@ -30,7 +30,6 @@ package mage.players;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
|
@ -49,6 +48,8 @@ import mage.util.Copier;
|
|||
*/
|
||||
public class Library implements Serializable {
|
||||
|
||||
// private static final transient Copier<Library> copier = new Copier<Library>();
|
||||
|
||||
private static Random rnd = new Random();
|
||||
|
||||
private boolean emptyDraw = false;
|
||||
|
@ -81,6 +82,10 @@ public class Library implements Serializable {
|
|||
return card;
|
||||
}
|
||||
|
||||
public Card getFromTop(Game game) {
|
||||
return library.peekFirst();
|
||||
}
|
||||
|
||||
public void putOnTop(Card card, Game game) {
|
||||
if (card.getOwnerId().equals(playerId))
|
||||
library.addFirst(card);
|
||||
|
|
|
@ -136,6 +136,7 @@ public interface Player extends MageItem {
|
|||
|
||||
public void declareAttacker(UUID attackerId, UUID defenderId, Game game);
|
||||
public void declareBlocker(UUID blockerId, UUID attackerId, Game game);
|
||||
public boolean hasAvailableAttackers(Game game);
|
||||
|
||||
public void beginTurn();
|
||||
public void endOfTurn(Game game);
|
||||
|
|
|
@ -51,6 +51,7 @@ import mage.cards.Cards;
|
|||
import mage.cards.CardsImpl;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.common.FilterCreatureForAttack;
|
||||
import mage.game.Game;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -67,6 +68,7 @@ import mage.util.Copier;
|
|||
|
||||
public abstract class PlayerImpl implements Player, Serializable {
|
||||
|
||||
// private static final transient Copier<Player> copier = new Copier<Player>();
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected UUID playerId;
|
||||
|
@ -661,4 +663,16 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ public abstract class TargetImpl implements Target {
|
|||
@Override
|
||||
public boolean choose(Outcome outcome, Game game) {
|
||||
Player player = game.getPlayer(this.source.getControllerId());
|
||||
while (!isChosen()) {
|
||||
while (!isChosen() && !doneChosing()) {
|
||||
chosen = targets.size() >= minNumberOfTargets;
|
||||
if (!player.chooseTarget(outcome, this, game)) {
|
||||
return chosen;
|
||||
|
@ -140,7 +140,7 @@ public abstract class TargetImpl implements Target {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return chosen = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -85,6 +85,10 @@ public class TargetPermanent extends TargetObject {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setTargetController(TargetController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
protected void setController(UUID controllerId, Game game) {
|
||||
filter.getControllerId().clear();
|
||||
switch (controller) {
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
|
@ -97,7 +96,7 @@ public class Copier<T> {
|
|||
public T uncompressCopy(byte[] buffer) {
|
||||
T copy = null;
|
||||
try {
|
||||
ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(buffer)));
|
||||
ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer)));
|
||||
copy = (T) in.readObject();
|
||||
}
|
||||
catch(IOException e) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Date;
|
|||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -54,6 +55,14 @@ public class Logging {
|
|||
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 {
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.watchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
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) {
|
||||
if (watcher.getKey().equals(key))
|
||||
if (watcher.getControllerId().equals(controllerId) && watcher.getKey().equals(key))
|
||||
return watcher;
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue