mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Add ability to reverse turn order.
This commit is contained in:
80
forge-game/src/main/java/forge/game/Direction.java
Normal file
80
forge-game/src/main/java/forge/game/Direction.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Represents a direction (left or right).
|
||||
*/
|
||||
public enum Direction {
|
||||
Left,
|
||||
Right;
|
||||
|
||||
private static final String LEFT = "Left";
|
||||
private static final String RIGHT = "Right";
|
||||
/** Immutable list of all directions (in order, Left and Right). */
|
||||
private static final List<Direction> listOfDirections =
|
||||
ImmutableList.of(getDefaultDirection(), getDefaultDirection().getOtherDirection());
|
||||
|
||||
/** @return The default direction. */
|
||||
public static final Direction getDefaultDirection() { return Left; }
|
||||
|
||||
/** @return Immutable list of all directions (in order, Left and Right). */
|
||||
public static List<Direction> getListOfDirections() { return listOfDirections; }
|
||||
|
||||
/**
|
||||
* Get the index by which the turn order is shifted, given this Direction.
|
||||
* @return 1 or -1.
|
||||
*/
|
||||
public int getShift() {
|
||||
if (this.equals(getDefaultDirection())) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the other Direction.
|
||||
* @return Right if this is Left, and vice versa.
|
||||
*/
|
||||
public Direction getOtherDirection() {
|
||||
switch (this) {
|
||||
case Left:
|
||||
return Direction.Right;
|
||||
case Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
case Left:
|
||||
return LEFT;
|
||||
case Right:
|
||||
return RIGHT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,8 @@ public class Game {
|
||||
private final GameLog gameLog = new GameLog();
|
||||
|
||||
private final Zone stackZone = new Zone(ZoneType.Stack, this);
|
||||
|
||||
private Direction turnOrder = Direction.getDefaultDirection();
|
||||
|
||||
private long timestamp = 0;
|
||||
public final GameAction action;
|
||||
@@ -287,6 +289,19 @@ public class Game {
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the turn order.
|
||||
* @return the Direction in which the turn order of this Game currently
|
||||
* proceeds.
|
||||
*/
|
||||
public final Direction getTurnOrder() {
|
||||
return this.turnOrder;
|
||||
}
|
||||
|
||||
public final void reverseTurnOrder() {
|
||||
this.turnOrder = this.turnOrder.getOtherDirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the next timestamp.
|
||||
@@ -498,20 +513,25 @@ public class Game {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int shift = this.getTurnOrder().getShift();
|
||||
final int totalNumPlayers = allPlayers.size();
|
||||
if (-1 == iPlayer) { // if playerTurn has just lost
|
||||
int iAlive;
|
||||
iPlayer = allPlayers.indexOf(playerTurn);
|
||||
do {
|
||||
iPlayer = (iPlayer + 1) % allPlayers.size();
|
||||
iPlayer = (iPlayer + shift) % totalNumPlayers;
|
||||
if (iPlayer < 0) {
|
||||
iPlayer += totalNumPlayers;
|
||||
}
|
||||
iAlive = roIngamePlayers.indexOf(allPlayers.get(iPlayer));
|
||||
} while (iAlive < 0);
|
||||
iPlayer = iAlive;
|
||||
}
|
||||
else { // for the case noone has died
|
||||
if (iPlayer == roIngamePlayers.size() - 1) {
|
||||
iPlayer = -1;
|
||||
}
|
||||
iPlayer++;
|
||||
iPlayer = (iPlayer + shift) % totalNumPlayers;
|
||||
if (iPlayer < 0) {
|
||||
iPlayer += totalNumPlayers;
|
||||
}
|
||||
}
|
||||
|
||||
return roIngamePlayers.get(iPlayer);
|
||||
|
||||
@@ -109,6 +109,7 @@ public enum ApiType {
|
||||
RestartGame (RestartGameEffect.class),
|
||||
Reveal (RevealEffect.class),
|
||||
RevealHand (RevealHandEffect.class),
|
||||
ReverseTurnOrder (ReverseTurnOrderEffect.class),
|
||||
RollPlanarDice (RollPlanarDiceEffect.class),
|
||||
RunSVarAbility (RunSVarAbilityEffect.class),
|
||||
Sacrifice (SacrificeEffect.class),
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
|
||||
public class ReverseTurnOrderEffect extends SpellAbilityEffect {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.abilityfactory.SpellEffect#resolve(java.util.Map, forge.card.spellability.SpellAbility)
|
||||
*/
|
||||
@Override
|
||||
public void resolve(final SpellAbility sa) {
|
||||
final Card source = sa.getHostCard();
|
||||
final Game game = source.getGame();
|
||||
game.reverseTurnOrder();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user