Wegfindung wird jetzt ausgeführt, wenn auf ein Feld auf der Karte geklickt wird
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Collections.Generic;
|
||||
using WorldOfPeacecraft;
|
||||
using System.Threading;
|
||||
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
@@ -16,6 +16,7 @@ namespace WorldOfPeacecraft
|
||||
private Map Map;
|
||||
private Buffer SenderBuffer;
|
||||
private IGui Gui;
|
||||
private int SelfId;
|
||||
|
||||
public Backend (IGui gui)
|
||||
{
|
||||
@@ -30,9 +31,15 @@ namespace WorldOfPeacecraft
|
||||
Rec = new Receiver (Client, receiverBuffer);
|
||||
Send = new Sender (Client, SenderBuffer);
|
||||
SenderBuffer.AddLine ("get:map");
|
||||
SenderBuffer.AddLine ("get:me");
|
||||
SenderBuffer.AddLine ("get:ents");
|
||||
}
|
||||
|
||||
public void SetSelfId (int id)
|
||||
{
|
||||
this.SelfId = id;
|
||||
}
|
||||
|
||||
public IEnumerable<IPositionable> GetDragons ()
|
||||
{
|
||||
return Dragons.Values;
|
||||
@@ -139,6 +146,22 @@ namespace WorldOfPeacecraft
|
||||
SenderBuffer.AddLine("ask:mv:rgt");
|
||||
}
|
||||
|
||||
public void MoveTo (int x, int y)
|
||||
{
|
||||
new Thread(() => WalkTo(x,y)).Start();
|
||||
}
|
||||
|
||||
private void WalkTo (int x, int y)
|
||||
{
|
||||
LinkedList<Coordinate> path = Pathfinder.FindPath (Players [SelfId].Coord, new Coordinate (x, y), Map);
|
||||
Pathwalker walker = new Pathwalker ();
|
||||
walker.SetCoords (path);
|
||||
while (walker.HasMoreSteps()) {
|
||||
SenderBuffer.AddLine("ask:" + walker.NextStep());
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshGui()
|
||||
{
|
||||
Gui.PerformRefresh();
|
||||
@@ -157,3 +180,4 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace WorldOfPeacecraft
|
||||
void SendCommand (string command);
|
||||
|
||||
void moveUp();
|
||||
|
||||
void moveDown();
|
||||
void moveLeft();
|
||||
void moveRight();
|
||||
void MoveTo(int x, int y);
|
||||
|
||||
void StartThreads();
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ namespace WorldOfPeacecraft
|
||||
protected override void OnMouseClick (MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseClick (e);
|
||||
//TODO: Things.
|
||||
int targetX = e.X / TileSize;
|
||||
int targetY = e.Y / TileSize;
|
||||
Backend.MoveTo (targetX, targetY);
|
||||
}
|
||||
|
||||
public void DoPaint (object source, PaintEventArgs args)
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace WorldOfPeacecraft
|
||||
ProcessChallenge (block);
|
||||
break;
|
||||
case MessPlayer:
|
||||
ProcessPlayer (block);
|
||||
ProcessPlayerSelf (block);
|
||||
break;
|
||||
case MessYourid:
|
||||
ProcessYourid (block);
|
||||
@@ -287,6 +287,15 @@ namespace WorldOfPeacecraft
|
||||
Challenge c = new Challenge(id, type, accepted);
|
||||
}
|
||||
|
||||
private void ProcessPlayerSelf (Block playerBlock)
|
||||
{
|
||||
Player self = MapPlayer (playerBlock);
|
||||
lock (Backend) {
|
||||
Backend.SetSelfId(self.GetId());
|
||||
Backend.SetPlayer(self);
|
||||
}
|
||||
Backend.RefreshGui ();
|
||||
}
|
||||
|
||||
private void ProcessPlayer (Block playerBlock)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace WorldOfPeacecraft
|
||||
Coords = null;
|
||||
}
|
||||
|
||||
public bool HasMoreSteps()
|
||||
{
|
||||
return Coords != null && Coords.Count >= 2;
|
||||
}
|
||||
|
||||
public string NextStep ()
|
||||
{
|
||||
if (Coords == null) {
|
||||
@@ -30,13 +35,13 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
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) {
|
||||
} else if (src.X < dst.X) {
|
||||
command = "mv:rgt";
|
||||
} else if (src.Y > dst.Y) {
|
||||
command = "mv:up";
|
||||
} else if (src.Y < dst.Y) {
|
||||
command = "mv:dwn";
|
||||
} else {
|
||||
command = NextStep ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user