* Used some default code to get opponents for Game classes.

This commit is contained in:
LevelX2 2018-05-31 12:52:05 +02:00
parent f249a819e9
commit 58d618e8d7
8 changed files with 30 additions and 142 deletions

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,21 +20,16 @@
* 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.game;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
import mage.game.match.MatchType;
import mage.players.Player;
/**
*
@ -67,22 +62,6 @@ public class FreeForAll extends GameImpl {
this.numPlayers = numPlayers;
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck) && player.getInRange().contains(playerToCheck);
}
@Override
public FreeForAll copy() {
return new FreeForAll(this);

View file

@ -27,8 +27,6 @@
*/
package mage.game;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -83,22 +81,6 @@ public class MomirDuel extends GameImpl {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId : this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
@Override
public MomirDuel copy() {
return new MomirDuel(this);

View file

@ -27,8 +27,6 @@
*/
package mage.game;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -44,13 +42,12 @@ import mage.game.match.MatchType;
import mage.game.turn.TurnMod;
import mage.players.Player;
/**
*
* @author nigelzor
*/
public class MomirGame extends GameImpl {
private int numPlayers;
public MomirGame(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) {
@ -59,8 +56,8 @@ public class MomirGame extends GameImpl {
public MomirGame(final MomirGame game) {
super(game);
}
}
@Override
public MatchType getGameType() {
return new MomirFreeForAllType();
@ -86,22 +83,6 @@ public class MomirGame extends GameImpl {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId : this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck) && player.getInRange().contains(playerToCheck);
}
@Override
public MomirGame copy() {
return new MomirGame(this);

View file

@ -24,19 +24,15 @@
* 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.game;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.MultiplayerAttackOption;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import mage.game.match.MatchType;
import mage.game.turn.TurnMod;
import mage.players.Player;
public class TwoPlayerDuel extends GameImpl {
@ -64,22 +60,6 @@ public class TwoPlayerDuel extends GameImpl {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
@Override
public TwoPlayerDuel copy() {
return new TwoPlayerDuel(this);

View file

@ -139,21 +139,37 @@ public interface Game extends MageItem, Serializable {
PlayerList getPlayerList();
/**
* Returns a Set of opponents in range for the given playerId
* Returns a Set of opponents in range for the given playerId This return
* also a player, that has dies this turn.
*
* @param playerId
* @return
*/
Set<UUID> getOpponents(UUID playerId);
default public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
Player player = getPlayer(playerId);
for (UUID opponentId : player.getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
/**
* Checks if the given playerToCheckId is an opponent of player
* Checks if the given playerToCheckId is an opponent of player As long as
* no team formats are implemented, this method returns always true for each
* playerId not equal to the player it is checked for. Also if this player
* is out of range. This method can't handle that only players in range are
* processed because it can only return TRUE or FALSE.
*
* @param player
* @param playerToCheckId
* @return
*/
boolean isOpponent(Player player, UUID playerToCheckId);
default public boolean isOpponent(Player player, UUID playerToCheckId) {
return !player.getId().equals(playerToCheckId);
}
Turn getTurn();

View file

@ -27,14 +27,13 @@
*/
package mage.game;
import java.util.*;
import mage.constants.MultiplayerAttackOption;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import mage.game.turn.TurnMod;
import mage.players.Player;
import java.util.*;
public abstract class GameCanadianHighlanderImpl extends GameImpl {
protected boolean startingPlayerSkipsDraw = true;
@ -160,19 +159,4 @@ public abstract class GameCanadianHighlanderImpl extends GameImpl {
super.endMulligan(playerId);
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId : getState().getPlayersInRange(playerId, this)) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
}

View file

@ -27,9 +27,7 @@
*/
package mage.game;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -200,22 +198,6 @@ public abstract class GameCommanderImpl extends GameImpl {
return super.checkStateBasedActions();
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId : getState().getPlayersInRange(playerId, this)) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
public void setAlsoHand(boolean alsoHand) {
this.alsoHand = alsoHand;
}

View file

@ -132,22 +132,6 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
return commander;
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
for (UUID opponentId : getState().getPlayersInRange(playerId, this)) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
public void setAlsoHand(boolean alsoHand) {
this.alsoHand = alsoHand;
}