From c54ce8eb22f6659314c1f9210a9a814657b75c69 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 29 Dec 2010 12:26:00 +0300 Subject: [PATCH] [mage.core] Reimplemented Counters: using enums instead of strings. Now supports only P1P1, M1M1, POISON. Feel free to add more. --- Mage/src/mage/counters/CounterType.java | 81 +++++++++++++++++++++++ Mage/src/mage/counters/Counters.java | 6 ++ Mage/src/mage/counters/PoisonCounter.java | 47 +++++++++++++ Mage/src/mage/game/GameImpl.java | 3 +- 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 Mage/src/mage/counters/CounterType.java create mode 100644 Mage/src/mage/counters/PoisonCounter.java diff --git a/Mage/src/mage/counters/CounterType.java b/Mage/src/mage/counters/CounterType.java new file mode 100644 index 0000000000..6447dcc172 --- /dev/null +++ b/Mage/src/mage/counters/CounterType.java @@ -0,0 +1,81 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.counters; + +/** + * Enum for counters, names and instances. + * + * @author nantuko + */ +public enum CounterType { + P1P1(new PlusOneCounter().name), + M1M1(new MinusOneCounter().name), + POISON(new PoisonCounter().name); + + private String name; + + private CounterType(String name) { + this.name = name; + } + + /** + * Get counter string name. + * + * @return + */ + public String getName() { + return this.name; + } + + /** + * Get instance of counter type with amount equal to 1. + * + * @return + */ + public Counter getInstance() { + return getInstance(1); + } + + /** + * Get instance of counter type with defined amount of the given type. + * + * @param amount amount of counters of the given type. + * @return + */ + public Counter getInstance(int amount) { + switch(this) { + case P1P1: + return new PlusOneCounter(amount); + case M1M1: + return new MinusOneCounter(amount); + case POISON: + return new PoisonCounter(amount); + } + } +} diff --git a/Mage/src/mage/counters/Counters.java b/Mage/src/mage/counters/Counters.java index 625db5a855..3b14295742 100644 --- a/Mage/src/mage/counters/Counters.java +++ b/Mage/src/mage/counters/Counters.java @@ -86,6 +86,12 @@ public class Counters extends HashMap implements Serializable { return 0; } + public int getCount(CounterType type) { + if (this.containsKey(type.getName())) + return this.get(type.getName()).getCount(); + return 0; + } + public List getBoostCounters() { List boosters = new ArrayList(); for (Counter counter: this.values()) { diff --git a/Mage/src/mage/counters/PoisonCounter.java b/Mage/src/mage/counters/PoisonCounter.java new file mode 100644 index 0000000000..bbcf8dab39 --- /dev/null +++ b/Mage/src/mage/counters/PoisonCounter.java @@ -0,0 +1,47 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.counters; + +/** + * Poison counter. + * + * @author nantuko + */ +public class PoisonCounter extends Counter { + + public PoisonCounter() { + super("Poison"); + this.count = 1; + } + + public PoisonCounter(int amount) { + super("Poison"); + this.count = amount; + } +} diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 8cad1b1a18..f34f000181 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -28,6 +28,7 @@ package mage.game; +import mage.counters.CounterType; import mage.game.match.MatchType; import java.io.IOException; import mage.game.stack.SpellStack; @@ -582,7 +583,7 @@ public abstract class GameImpl> implements Game, Serializa //20091005 - 704.5a/704.5b/704.5c for (Player player: state.getPlayers().values()) { - if (!player.hasLost() && (player.getLife() <= 0 || player.isEmptyDraw() || player.getCounters().getCount("Poison") >= 10)) { + if (!player.hasLost() && (player.getLife() <= 0 || player.isEmptyDraw() || player.getCounters().getCount(CounterType.POISON) >= 10)) { player.lost(this); } }