com.antelmann.game
Class GameBoardMove
java.lang.Object
com.antelmann.game.GameBoardMove
- All Implemented Interfaces:
- GameMove, Serializable, Cloneable
public class GameBoardMove
- extends Object
- implements GameMove, Cloneable
A specialized GameMove class suitable for board games to
implement moves of pieces from and to positions on a board.
- Author:
- Holger Antelmann
- See Also:
- Serialized Form
moveOption
protected Object moveOption
playerRole
protected int playerRole
positionTo
protected GameBoardPosition positionTo
positionFrom
protected GameBoardPosition positionFrom
GameBoardMove
public GameBoardMove(int playerRole,
GameBoardPosition position)
GameBoardMove
public GameBoardMove(int playerRole,
GameBoardPosition position,
Object option)
GameBoardMove
public GameBoardMove(int playerRole,
GameBoardPosition oldPosition,
GameBoardPosition newPosition)
GameBoardMove
public GameBoardMove(int playerRole,
GameBoardPosition oldPosition,
GameBoardPosition newPosition,
Object option)
getPlayer
public int getPlayer()
- Description copied from interface:
GameMove
- returns the game player role that plays this move
- Specified by:
getPlayer in interface GameMove
- See Also:
GamePlay.numberOfPlayers()
getOption
public Object getOption()
getPosition
public GameBoardPosition getPosition()
getNewPosition
public GameBoardPosition getNewPosition()
getOldPosition
public GameBoardPosition getOldPosition()
toString
public String toString()
- Overrides:
toString in class Object
equals
public boolean equals(Object obj)
- Overrides:
equals in class Object
clone
public Object clone()
throws CloneNotSupportedException
- Due to protected access of Object.clone() and the
Object type of moveOption, this clone() function
does not clone the moveOption, but only references
the same object is referenced from the original GameMove.
Thus, one should be aware that GameMove.clone() only does a
shallow copy!
The embedded GameBoardPositions are only shallow-copied
because they cannot be changed after instanciation, i.e.
it should not harm things; if derived classes are used,
though, that may chance of course.
Note: as a resolution, an overriding clone() function
that knows the type of the moveOption could cast the
Object type of the moveOption to something where the
clone() function of that object is accessible for a
deep copy; this overriding method could also take care
of cloning the GameBoardPositions if needed (in case
subclasses are used there, too).
- Overrides:
clone in class Object
- Throws:
CloneNotSupportedException
(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads