jfreerails.move
Class ChangeTrackPieceMove

java.lang.Object
  extended by jfreerails.move.ChangeTrackPieceMove
All Implemented Interfaces:
java.io.Serializable, MapUpdateMove, Move, TrackMove, FreerailsSerializable

public final class ChangeTrackPieceMove
extends java.lang.Object
implements TrackMove, MapUpdateMove

This Move adds, removes, or upgrades the track on a single tile.

Author:
Luke
See Also:
Serialized Form

Field Summary
private  ImPoint location
           
private static long serialVersionUID
           
private  TrackPiece trackPieceAfter
           
(package private)  TrackPiece trackPieceBefore
           
 
Constructor Summary
ChangeTrackPieceMove(TrackPiece before, TrackPiece after, ImPoint p)
           
 
Method Summary
protected static boolean canConnect2OtherRRsTrack(ReadOnlyWorld world)
           
protected static MoveStatus check4overlap(World w, ImPoint location, TrackPiece trackPiece)
          This method may be called under 3 possible conditions: (1) when a station is getting built, (2) when a station is getting upgraded, (3) when a staton is getting removed.
 MoveStatus doMove(World w, FreerailsPrincipal p)
          Executes this move on the specifed world object.
 boolean equals(java.lang.Object o)
           
 ImPoint getLocation()
           
 TrackPiece getNewTrackPiece()
           
 TrackPiece getOldTrackPiece()
           
 java.awt.Rectangle getUpdatedTiles()
           
 int hashCode()
           
private  void move(World w, TrackPiece oldTrackPiece, TrackPiece newTrackPiece)
           
private  boolean noDiagonalTrackConflicts(ImPoint point, int trackTemplate, World w)
           
 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.
private  MoveStatus tryMove(World w, TrackPiece oldTrackPiece, TrackPiece newTrackPiece)
           
 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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

trackPieceBefore

final TrackPiece trackPieceBefore

trackPieceAfter

private final TrackPiece trackPieceAfter

location

private final ImPoint location
Constructor Detail

ChangeTrackPieceMove

public ChangeTrackPieceMove(TrackPiece before,
                            TrackPiece after,
                            ImPoint p)
Method Detail

getLocation

public ImPoint getLocation()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getOldTrackPiece

public TrackPiece getOldTrackPiece()

getNewTrackPiece

public TrackPiece getNewTrackPiece()

tryDoMove

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

Specified by:
tryDoMove in interface Move

tryMove

private MoveStatus tryMove(World w,
                           TrackPiece oldTrackPiece,
                           TrackPiece newTrackPiece)

tryUndoMove

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

Specified by:
tryUndoMove in interface Move

doMove

public MoveStatus doMove(World w,
                         FreerailsPrincipal p)
Description copied from interface: Move
Executes this move on the specifed world object.

Specified by:
doMove in interface Move

move

private void move(World w,
                  TrackPiece oldTrackPiece,
                  TrackPiece newTrackPiece)

undoMove

public MoveStatus undoMove(World w,
                           FreerailsPrincipal p)
Description copied from interface: Move
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.

Specified by:
undoMove in interface Move

noDiagonalTrackConflicts

private boolean noDiagonalTrackConflicts(ImPoint point,
                                         int trackTemplate,
                                         World w)

getUpdatedTiles

public java.awt.Rectangle getUpdatedTiles()
Specified by:
getUpdatedTiles in interface MapUpdateMove

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

canConnect2OtherRRsTrack

protected static boolean canConnect2OtherRRsTrack(ReadOnlyWorld world)

check4overlap

protected static MoveStatus check4overlap(World w,
                                          ImPoint location,
                                          TrackPiece trackPiece)
This method may be called under 3 possible conditions: (1) when a station is getting built, (2) when a station is getting upgraded, (3) when a staton is getting removed.