Revision: 135
http://mud4j.svn.sourceforge.net/mud4j/?rev=135&view=rev
Author: mpurland
Date: 2007-06-02 18:44:37 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
Fix javadoc, format, add source and target locations, and add move method to move to the target location.
Modified Paths:
--------------
trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java
Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-06-03 01:38:24 UTC (rev 134)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-06-03 01:44:37 UTC (rev 135)
@@ -17,27 +17,75 @@
package net.sf.mud4j.world;
/**
- * Direction to define different directions for dynamic
- * direction management to add west, east, north, south, etc...
+ * Direction to define different directions for dynamic direction management to
+ * add west, east, north, south, etc...
*
* @author Matthew Purland
*/
public class Direction {
-
+
private String directionName;
-
+
/**
+ * Direction is from source to target location. Example. If direction is
+ * east then Source (east to) --> Target
+ */
+ private TileLocation sourceLocation;
+ private TileLocation targetLocation;
+
+ /**
* Creates a direction with a name such as "north" or "south".
+ *
* @param directionName Name of the direction.
+ * @param sourceLocation Source of the location to the target
+ * @param targetLocation Target of the location from the source
*/
- public Direction(String directionName) {
+ public Direction(String directionName, TileLocation sourceLocation,
+ TileLocation targetLocation) {
this.directionName = directionName;
+ this.sourceLocation = sourceLocation;
+ this.targetLocation = targetLocation;
}
-
+
/**
* Get name of direction.
*/
public String getDirectionName() {
return directionName;
}
+
+ /**
+ * Get the source location.
+ *
+ * @return the source location.
+ */
+ public TileLocation getSourceLocation() {
+ return this.sourceLocation;
+ }
+
+ /**
+ * Get the target location.
+ *
+ * @return the target location.
+ */
+ public TileLocation getTargetLocation() {
+ return this.targetLocation;
+ }
+
+ /**
+ * Move the given placeable to the target location of the direction.
+ *
+ * @param placeable Placeable to place within the target location.
+ * @throws IllegalArgumentException when the given placeable is not in the
+ * source location.
+ */
+ public void move(Placeable placeable) throws IllegalArgumentException {
+ if (!placeable.getCurrentLocation().equals(getSourceLocation())) {
+ throw new IllegalArgumentException("Could not place placeable ("
+ + placeable
+ + ") because it is not currently in the source location.");
+ }
+
+ placeable.place(targetLocation);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|