Currently showing ../../pathfinder/PathFindingTutorial/target/src/org/newdawn/slick/util/pathfinding/Path.java Line Numbers: [show|hide]

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155``` ```package org.newdawn.slick.util.pathfinding; import java.util.ArrayList; /** * A path determined by some path finding algorithm. A series of steps from * the starting location to the target location. This includes a step for the * initial location. * * @author Kevin Glass */ public class Path { /** The list of steps building up this path */ private ArrayList steps = new ArrayList(); /** * Create an empty path */ public Path() { } /** * Get the length of the path, i.e. the number of steps * * @return The number of steps in this path */ public int getLength() { return steps.size(); } /** * Get the step at a given index in the path * * @param index The index of the step to retrieve. Note this should * be >= 0 and < getLength(); * @return The step information, the position on the map. */ public Step getStep(int index) { return (Step) steps.get(index); } /** * Get the x coordinate for the step at the given index * * @param index The index of the step whose x coordinate should be retrieved * @return The x coordinate at the step */ public int getX(int index) { return getStep(index).x; } /** * Get the y coordinate for the step at the given index * * @param index The index of the step whose y coordinate should be retrieved * @return The y coordinate at the step */ public int getY(int index) { return getStep(index).y; } /** * Append a step to the path. * * @param x The x coordinate of the new step * @param y The y coordinate of the new step */ public void appendStep(int x, int y) { steps.add(new Step(x,y)); } /** * Prepend a step to the path. * * @param x The x coordinate of the new step * @param y The y coordinate of the new step */ public void prependStep(int x, int y) { steps.add(0, new Step(x, y)); } /** * Check if this path contains the given step * * @param x The x coordinate of the step to check for * @param y The y coordinate of the step to check for * @return True if the path contains the given step */ public boolean contains(int x, int y) { return steps.contains(new Step(x,y)); } /** * A single step within the path * * @author Kevin Glass */ public class Step { /** The x coordinate at the given step */ private int x; /** The y coordinate at the given step */ private int y; /** * Create a new step * * @param x The x coordinate of the new step * @param y The y coordinate of the new step */ public Step(int x, int y) { this.x = x; this.y = y; } /** * Get the x coordinate of the new step * * @return The x coodindate of the new step */ public int getX() { return x; } /** * Get the y coordinate of the new step * * @return The y coodindate of the new step */ public int getY() { return y; } /** * @see Object#hashCode() */ public int hashCode() { return x*y; } /** * @see Object#equals(Object) */ public boolean equals(Object other) { if (other instanceof Step) { Step o = (Step) other; return (o.x == x) && (o.y == y); } return false; } } } ```

 Total 155 Lines of Code. Source code formatted using showsrc by William Denniss