mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
[mage.core] Reimplemented Counters: using enums instead of strings. Now supports only P1P1, M1M1, POISON. Feel free to add more.
This commit is contained in:
parent
6fcb471f7f
commit
c54ce8eb22
4 changed files with 136 additions and 1 deletions
81
Mage/src/mage/counters/CounterType.java
Normal file
81
Mage/src/mage/counters/CounterType.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -86,6 +86,12 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public int getCount(CounterType type) {
|
||||
if (this.containsKey(type.getName()))
|
||||
return this.get(type.getName()).getCount();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List<BoostCounter> getBoostCounters() {
|
||||
List<BoostCounter> boosters = new ArrayList<BoostCounter>();
|
||||
for (Counter counter: this.values()) {
|
||||
|
|
47
Mage/src/mage/counters/PoisonCounter.java
Normal file
47
Mage/src/mage/counters/PoisonCounter.java
Normal file
|
@ -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<PoisonCounter> {
|
||||
|
||||
public PoisonCounter() {
|
||||
super("Poison");
|
||||
this.count = 1;
|
||||
}
|
||||
|
||||
public PoisonCounter(int amount) {
|
||||
super("Poison");
|
||||
this.count = amount;
|
||||
}
|
||||
}
|
|
@ -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<T extends GameImpl<T>> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue