ALL_ZONES added to Player, some functions in AllZone now use GameState

This commit is contained in:
Maxmtg
2011-09-19 04:52:39 +00:00
parent 894cd44d0c
commit 18a7b1b433
4 changed files with 37 additions and 78 deletions

View File

@@ -425,19 +425,21 @@ public final class AllZone implements NewConstants {
* @return a {@link forge.PlayerZone} object. * @return a {@link forge.PlayerZone} object.
*/ */
public static PlayerZone getZone(final Card c) { public static PlayerZone getZone(final Card c) {
if (AllZoneUtil.isCardInZone(getStackZone(), c)) { final FGameState gameState = Singletons.getModel().getGameState();
return getStackZone(); if (gameState == null) { return null; }
if (AllZoneUtil.isCardInZone(gameState.getStackZone(), c)) {
return gameState.getStackZone();
} }
Player[] players = new Player[]{ AllZone.getHumanPlayer(), AllZone.getComputerPlayer() }; for (Player p : gameState.getPlayers()) {
Zone[] zones = new Zone[]{ Zone.Battlefield, Zone.Library, Zone.Graveyard, Zone.Hand, Zone.Exile, Zone.Command }; for(Zone z : Player.ALL_ZONES) {
for (Player p : players) {
for(Zone z : zones) {
PlayerZone pz = p.getZone(z); PlayerZone pz = p.getZone(z);
if ( AllZoneUtil.isCardInZone(pz, c) ) if ( AllZoneUtil.isCardInZone(pz, c) )
return pz; return pz;
} }
} }
return null; return null;
} }
@@ -445,16 +447,13 @@ public final class AllZone implements NewConstants {
* <p>resetZoneMoveTracking.</p> * <p>resetZoneMoveTracking.</p>
*/ */
public static void resetZoneMoveTracking() { public static void resetZoneMoveTracking() {
resetZoneMoveTracking(getHumanPlayer()); final FGameState gameState = Singletons.getModel().getGameState();
resetZoneMoveTracking(getComputerPlayer()); if (gameState == null) { return; }
} for (Player p : gameState.getPlayers()) {
for(Zone z : Player.ALL_ZONES) {
private static void resetZoneMoveTracking(Player player) { p.getZone(z).resetCardsAddedThisTurn();
player.getZone(Zone.Command).resetCardsAddedThisTurn(); }
player.getZone(Zone.Library).resetCardsAddedThisTurn(); }
player.getZone(Zone.Hand).resetCardsAddedThisTurn();
player.getZone(Zone.Battlefield).resetCardsAddedThisTurn();
player.getZone(Zone.Graveyard).resetCardsAddedThisTurn();
} }
/** /**
@@ -495,8 +494,11 @@ public final class AllZone implements NewConstants {
getDisplay().showCombat(""); getDisplay().showCombat("");
getDisplay().loadPrefs(); getDisplay().loadPrefs();
resetAllZones(getHumanPlayer()); for (Player p : Singletons.getModel().getGameState().getPlayers()) {
resetAllZones(getComputerPlayer()); for(Zone z : Player.ALL_ZONES) {
p.getZone(z).reset();
}
}
getInputControl().clearInput(); getInputControl().clearInput();
@@ -510,15 +512,6 @@ public final class AllZone implements NewConstants {
getTriggerHandler().clearRegistered(); getTriggerHandler().clearRegistered();
} }
private static void resetAllZones(Player player) {
player.getZone(Zone.Command).reset();
player.getZone(Zone.Library).reset();
player.getZone(Zone.Hand).reset();
player.getZone(Zone.Battlefield).reset();
player.getZone(Zone.Graveyard).reset();
player.getZone(Zone.Exile).reset();
}
/** /**
* Getter for matchState. * Getter for matchState.

View File

@@ -70,16 +70,18 @@ public final class AllZoneUtil {
*/ */
public static CardList getCardsIn(final Constant.Zone zone) { public static CardList getCardsIn(final Constant.Zone zone) {
CardList cards = new CardList(); CardList cards = new CardList();
cards.addAll(AllZone.getHumanPlayer().getZone(zone).getCards()); for (Player p : Singletons.getModel().getGameState().getPlayers()) {
cards.addAll(AllZone.getComputerPlayer().getZone(zone).getCards()); cards.addAll(p.getZone(zone).getCards());
}
return cards; return cards;
} }
public static CardList getCardsIn(final List<Constant.Zone> zones) { public static CardList getCardsIn(final List<Constant.Zone> zones) {
CardList cards = new CardList(); CardList cards = new CardList();
for (Zone z: zones) { for (Zone z: zones) {
cards.addAll(AllZone.getHumanPlayer().getZone(z).getCards()); for (Player p : Singletons.getModel().getGameState().getPlayers()) {
cards.addAll(AllZone.getComputerPlayer().getZone(z).getCards()); cards.addAll(p.getZone(z).getCards());
}
} }
return cards; return cards;
} }
@@ -149,27 +151,7 @@ public final class AllZoneUtil {
//////// HAND //////// HAND
/**
* answers the question "is a certain, specific card in this player's hand?".
*
* @param player the player's hand to check
* @param card the specific card to look for
* @return true if the card is present in this player's hand; false otherwise
*/
public static boolean isCardInPlayerHand(final Player player, final Card card) {
return isCardInZone(player.getZone(Constant.Zone.Hand), card);
}
/**
* answers the question "is a specific card in this player's library?".
*
* @param player the player's library to check
* @param card the specific card to look for
* @return true if the card is present in this player's library; false otherwise
*/
public static boolean isCardInPlayerLibrary(final Player player, final Card card) {
return isCardInZone(player.getZone(Constant.Zone.Library), card);
}
/** /**
* answers the question "is a specific card in the specified zone?". * answers the question "is a specific card in the specified zone?".
@@ -183,10 +165,8 @@ public final class AllZoneUtil {
return false; return false;
} }
CardList cl = getCardsInZone(pz); for (Card c : pz.getCards()) {
if (c.equals(card)) {
for (int i = 0; i < cl.size(); i++) {
if (cl.get(i).equals(card)) {
return true; return true;
} }
} }
@@ -204,15 +184,6 @@ public final class AllZoneUtil {
return getCardsIn(Zone.Exile).contains(c); return getCardsIn(Zone.Exile).contains(c);
} }
/**
* <p>isCardInGrave.</p>
*
* @param c a {@link forge.Card} object.
* @return a boolean.
*/
public static boolean isCardInGrave(final Card c) {
return getCardsIn(Zone.Graveyard).contains(c);
}
///Check if a certain card is in play ///Check if a certain card is in play

View File

@@ -47,6 +47,7 @@ public abstract class Player extends GameEntity {
protected Object mustAttackEntity = null; protected Object mustAttackEntity = null;
Map<Constant.Zone, PlayerZone> zones = new EnumMap<Constant.Zone, PlayerZone>(Constant.Zone.class); Map<Constant.Zone, PlayerZone> zones = new EnumMap<Constant.Zone, PlayerZone>(Constant.Zone.class);
public final static List<Zone> ALL_ZONES = Collections.unmodifiableList(Arrays.asList(Zone.Battlefield, Zone.Library, Zone.Graveyard, Zone.Hand, Zone.Exile, Zone.Command));
/** /**
* <p>Constructor for Player.</p> * <p>Constructor for Player.</p>
@@ -65,19 +66,9 @@ public abstract class Player extends GameEntity {
* @param myPoisonCounters a int. * @param myPoisonCounters a int.
*/ */
public Player(String myName, int myLife, int myPoisonCounters) { public Player(String myName, int myLife, int myPoisonCounters) {
PlayerZone battlefield = new PlayerZone_ComesIntoPlay(Constant.Zone.Battlefield, this); for (Zone z : ALL_ZONES) {
PlayerZone hand = new DefaultPlayerZone(Constant.Zone.Hand, this); zones.put(z, new DefaultPlayerZone(z, this));
PlayerZone graveyard = new DefaultPlayerZone(Constant.Zone.Graveyard, this); }
PlayerZone library = new DefaultPlayerZone(Constant.Zone.Library, this);
PlayerZone exile = new DefaultPlayerZone(Constant.Zone.Exile, this);
PlayerZone command = new DefaultPlayerZone(Constant.Zone.Command, this);
zones.put(Constant.Zone.Graveyard, graveyard);
zones.put(Constant.Zone.Hand, hand);
zones.put(Constant.Zone.Library, library);
zones.put(Constant.Zone.Battlefield, battlefield);
zones.put(Constant.Zone.Exile, exile);
zones.put(Constant.Zone.Command, command);
reset(); reset();

View File

@@ -73,6 +73,10 @@ public class FGameState {
protected final void setComputerPlayer(final Player computerPlayer0) { protected final void setComputerPlayer(final Player computerPlayer0) {
this.computerPlayer = computerPlayer0; this.computerPlayer = computerPlayer0;
} }
public final Player[] getPlayers() {
return new Player[]{ humanPlayer, computerPlayer };
}
/** /**