RuneHive-Game
Loading...
Searching...
No Matches
Path.java
Go to the documentation of this file.
1package com.runehive.game.world.pathfinding.path;
2
3import com.runehive.game.world.entity.mob.movement.Movement;
4import com.runehive.game.world.position.Position;
5
6import java.util.Deque;
7
8/**
9 * Represents a single path in the path finding system.
10 *
11 * @author Artem Batutin <artembatutin@gmail.com>
12 */
13public class Path {
14
15 /** The deque of all the moves the path has. */
16 private final Deque<Position> moves;
17
18 /**
19 * Creates a new {@code Path}.
20 *
21 * @param moves All of the path moves.
22 */
23 public Path(Deque<Position> moves) {
24 this.moves = moves;
25 }
26
27 /**
28 * Gets the starting location of the path.
29 *
30 * @return the starting position.
31 */
33 return moves.getFirst();
34 }
35
36 /**
37 * Gets the ending location of the path.
38 *
39 * @return the ending position.
40 */
42 return moves.peekLast();
43 }
44
45 /**
46 * Gets the condition if the path is possible.
47 *
48 * @return the condition if the path is possible to be done.
49 */
50 public boolean isPossible() {
51 return moves != null && !moves.isEmpty();
52 }
53
54 /**
55 * Gets all moves of the {@code Path}.
56 *
57 * @return the deque containing the coordinates.
58 */
59 public Deque<Position> getMoves() {
60 return moves;
61 }
62
63 /**
64 * Removing one of the last(but first in the queue) walking points.
65 *
66 * @return true if removed, false otherwise.
67 */
68 public Position poll() {
69 return moves.pollFirst();
70 }
71
72 public void addSteps(final Movement movement) {
73 movement.reset();
74 while (!moves.isEmpty()) {
75 final Position next = moves.poll();
76 if (next == null) break;
77
78 movement.addStep(next.getX(), next.getY());
79 }
80 movement.finish();
81 }
82
83}
Handles the movement for the player.
Definition Movement.java:25
void finish()
Removes the first waypoint which is only used for calculating directions.
void reset()
Resets the walking queue so it contains no more steps.
void addStep(int x, int y)
Adds a single step to the walking queue, filling in the points to the previous point in the queue if ...
final Deque< Position > moves
The deque of all the moves the path has.
Definition Path.java:16
void addSteps(final Movement movement)
Definition Path.java:72
Position getOrigin()
Gets the starting location of the path.
Definition Path.java:32
Path(Deque< Position > moves)
Creates a new Path.
Definition Path.java:23
boolean isPossible()
Gets the condition if the path is possible.
Definition Path.java:50
Deque< Position > getMoves()
Gets all moves of the Path.
Definition Path.java:59
Position getDestination()
Gets the ending location of the path.
Definition Path.java:41
Position poll()
Removing one of the last(but first in the queue) walking points.
Definition Path.java:68
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41