jfreerails.move
Interface Move

All Superinterfaces:
FreerailsSerializable, java.io.Serializable
All Known Subinterfaces:
ListMove, MapUpdateMove, TrackMove
All Known Implementing Classes:
AddActiveEntityMove, AddCargoBundleMove, AddItemToListMove, AddItemToSharedListMove, AddPlayerMove, AddStationMove, AddTransactionMove, ChangeCargoBundleMove, ChangeGameSpeedMove, ChangeItemInListMove, ChangeProductionAtEngineShopMove, ChangeStationMove, ChangeTileMove, ChangeTrackPieceCompositeMove, ChangeTrackPieceMove, ChangeTrainMove, ChangeTrainScheduleMove, CompositeMove, NextActivityMove, RemoveCargoBundleMove, RemoveItemFromListMove, RemoveStationMove, RemoveTrainMove, TimeTickMove, TransferCargoAtStationMove, UndoMove, UpgradeTrackMove, WorldDiffMove

public interface Move
extends FreerailsSerializable

All moves should implement this interface and obey the contract described below.

(1) They should be immutable.

(2) They should overide Object.equals() to test for logical equality.

(3) They should store 'before' and 'after' values for all properties of the world object that they change.

(4) The changes they encapsulate should be stored in an address space independent way, so that a move generated on a client can be serialised, sent over a network, and then deserialised and executed on a server. To achieve this, they should refer to items in the game world via either their coorinates, e.g. tile 10,50, or their position in a list, e.g. train #4.

(5) They should be undoable. To achieve this, they need to store the information necessary to undo the change. E.g. a change-terrain-type move might store the tile coorindates, the terrain type before the change and the terrain type after the change.

(6) The tryDoMove and tryUndoMove methods should test whether the move is valid but leave the gameworld unchanged

Author:
lindsal
See Also:
MoveStatus, World, PreMove

Method Summary
 MoveStatus doMove(World w, FreerailsPrincipal p)
          Executes this move on the specifed world object.
 MoveStatus tryDoMove(World w, FreerailsPrincipal p)
          Tests whether this Move can be executed on the specifed world object, this method should leave the world object unchanged.
 MoveStatus tryUndoMove(World w, FreerailsPrincipal p)
          Tests whether this Move can be undone on the specifed world object, this method should leave the world object unchanged.
 MoveStatus undoMove(World w, FreerailsPrincipal p)
          If doMove has just been executed on the specified world object, calling this method changes the state of the world object back to how it was before doMove was called.
 

Method Detail

tryDoMove

MoveStatus tryDoMove(World w,
                     FreerailsPrincipal p)
Tests whether this Move can be executed on the specifed world object, this method should leave the world object unchanged.


tryUndoMove

MoveStatus tryUndoMove(World w,
                       FreerailsPrincipal p)
Tests whether this Move can be undone on the specifed world object, this method should leave the world object unchanged.


doMove

MoveStatus doMove(World w,
                  FreerailsPrincipal p)
Executes this move on the specifed world object.


undoMove

MoveStatus undoMove(World w,
                    FreerailsPrincipal p)
If doMove has just been executed on the specified world object, calling this method changes the state of the world object back to how it was before doMove was called.