diff --git a/inf3.csproj b/inf3.csproj
index 5e11a0b..6f41c4a 100644
--- a/inf3.csproj
+++ b/inf3.csproj
@@ -71,6 +71,8 @@
+
+
\ No newline at end of file
diff --git a/src/Coordinate.cs b/src/Coordinate.cs
new file mode 100644
index 0000000..1dacfc0
--- /dev/null
+++ b/src/Coordinate.cs
@@ -0,0 +1,20 @@
+namespace WorldOfPeacecraft
+{
+ public class Coordinate
+ {
+ public int X { get; set; }
+ public int Y { get; set; }
+
+ public Coordinate (int x, int y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
+ public void setCoordinate(int x, int y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Entity.cs b/src/Entity.cs
index fdef504..d81589e 100644
--- a/src/Entity.cs
+++ b/src/Entity.cs
@@ -10,16 +10,14 @@ namespace WorldOfPeacecraft
public abstract class Entity : IPositionable
{
public int Id;
- public int PosX;
- public int PosY;
+ public Coordinate Coord;
public string Desc;
public bool Busy;
public Entity (int id, int posX, int posY, string desc, bool busy)
{
this.SetId (id);
- this.SetPosX (posX);
- this.SetPosY (posY);
+ this.SetCoord(new Coordinate(posX, posY));
this.SetDesc (desc);
this.SetBusy (busy);
}
@@ -36,22 +34,27 @@ namespace WorldOfPeacecraft
public void SetPosX (int x)
{
- this.PosX = x;
+ this.Coord.X = x;
}
public int getXPosition ()
{
- return PosX;
+ return Coord.X;
}
public void SetPosY (int y)
{
- this.PosY = y;
+ this.Coord.Y = y;
}
public int getYPosition ()
{
- return PosY;
+ return Coord.Y;
+ }
+
+ public void SetCoord (Coordinate coord)
+ {
+ this.Coord = coord;
}
public void SetDesc (string desc)
diff --git a/src/Pathwalker.cs b/src/Pathwalker.cs
new file mode 100644
index 0000000..36b1e98
--- /dev/null
+++ b/src/Pathwalker.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Runtime.Serialization;
+using System.Collections.Generic;
+
+namespace WorldOfPeacecraft
+{
+ class Pathwalker
+ {
+ private LinkedList Coords;
+
+ public void Stop()
+ {
+ Coords = null;
+ }
+
+ public string NextStep ()
+ {
+ if (Coords == null) {
+ throw new PathwalkerException ("There are no coordinates set");
+ }
+ if (Coords.Count < 2) {
+ throw new PathwalkerException ("There are no more steps to take");
+ }
+ Coordinate src = Coords.First.Value;
+ Coords.RemoveFirst ();
+ Coordinate dst = Coords.First.Value;
+ int distance = Math.Abs (src.X - dst.X) + Math.Abs (src.Y - dst.Y);
+ if (distance > 1) {
+ throw new PathwalkerException ("The distance between (" + src.X + "|" + src.Y + ") and (" + dst.X + "|" + dst.Y + ") is grater than 1");
+ }
+ string command;
+ if (src.X > dst.X) {
+ command = "mv:dwn";
+ } else if (src.X < dst.X) {
+ command = "mv:up";
+ } else if (src.Y > dst.Y) {
+ command = "mv:lft";
+ } else if (src.Y < dst.Y) {
+ command = "mv:rgt";
+ } else {
+ command = NextStep ();
+ }
+ return command;
+ }
+
+ public void SetCoords(LinkedList coords)
+ {
+ this.Coords = coords;
+ }
+ }
+
+ public class PathwalkerException : Exception
+ {
+ public PathwalkerException () : base()
+ {
+ }
+
+ public PathwalkerException (string message) : base(message)
+ {
+ }
+
+ public PathwalkerException (SerializationInfo info, StreamingContext context) : base(info, context)
+ {
+ }
+
+ public PathwalkerException (string message, Exception innerException) : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/src/Player.cs b/src/Player.cs
index 50a3e99..811b8f4 100644
--- a/src/Player.cs
+++ b/src/Player.cs
@@ -21,7 +21,7 @@ namespace WorldOfPeacecraft
public override string ToString()
{
- return "Player: " + Id + " " + PosX + " " + PosY + " " + Desc + " " + Busy + " " + Score;
+ return "Player: " + Id + " " + Coord.X + " " + Coord.Y + " " + Desc + " " + Busy + " " + Score;
}
}
}