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.Net.Sockets;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WorldOfPeacecraft;
|
using System.Threading;
|
||||||
|
|
||||||
namespace WorldOfPeacecraft
|
namespace WorldOfPeacecraft
|
||||||
{
|
{
|
||||||
@@ -16,6 +16,7 @@ namespace WorldOfPeacecraft
|
|||||||
private Map Map;
|
private Map Map;
|
||||||
private Buffer SenderBuffer;
|
private Buffer SenderBuffer;
|
||||||
private IGui Gui;
|
private IGui Gui;
|
||||||
|
private int SelfId;
|
||||||
|
|
||||||
public Backend (IGui gui)
|
public Backend (IGui gui)
|
||||||
{
|
{
|
||||||
@@ -30,9 +31,15 @@ namespace WorldOfPeacecraft
|
|||||||
Rec = new Receiver (Client, receiverBuffer);
|
Rec = new Receiver (Client, receiverBuffer);
|
||||||
Send = new Sender (Client, SenderBuffer);
|
Send = new Sender (Client, SenderBuffer);
|
||||||
SenderBuffer.AddLine ("get:map");
|
SenderBuffer.AddLine ("get:map");
|
||||||
|
SenderBuffer.AddLine ("get:me");
|
||||||
SenderBuffer.AddLine ("get:ents");
|
SenderBuffer.AddLine ("get:ents");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetSelfId (int id)
|
||||||
|
{
|
||||||
|
this.SelfId = id;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<IPositionable> GetDragons ()
|
public IEnumerable<IPositionable> GetDragons ()
|
||||||
{
|
{
|
||||||
return Dragons.Values;
|
return Dragons.Values;
|
||||||
@@ -139,6 +146,22 @@ namespace WorldOfPeacecraft
|
|||||||
SenderBuffer.AddLine("ask:mv:rgt");
|
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()
|
public void RefreshGui()
|
||||||
{
|
{
|
||||||
Gui.PerformRefresh();
|
Gui.PerformRefresh();
|
||||||
@@ -157,3 +180,4 @@ namespace WorldOfPeacecraft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ namespace WorldOfPeacecraft
|
|||||||
void SendCommand (string command);
|
void SendCommand (string command);
|
||||||
|
|
||||||
void moveUp();
|
void moveUp();
|
||||||
|
|
||||||
void moveDown();
|
void moveDown();
|
||||||
void moveLeft();
|
void moveLeft();
|
||||||
void moveRight();
|
void moveRight();
|
||||||
|
void MoveTo(int x, int y);
|
||||||
|
|
||||||
void StartThreads();
|
void StartThreads();
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ namespace WorldOfPeacecraft
|
|||||||
protected override void OnMouseClick (MouseEventArgs e)
|
protected override void OnMouseClick (MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseClick (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)
|
public void DoPaint (object source, PaintEventArgs args)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace WorldOfPeacecraft
|
|||||||
ProcessChallenge (block);
|
ProcessChallenge (block);
|
||||||
break;
|
break;
|
||||||
case MessPlayer:
|
case MessPlayer:
|
||||||
ProcessPlayer (block);
|
ProcessPlayerSelf (block);
|
||||||
break;
|
break;
|
||||||
case MessYourid:
|
case MessYourid:
|
||||||
ProcessYourid (block);
|
ProcessYourid (block);
|
||||||
@@ -287,6 +287,15 @@ namespace WorldOfPeacecraft
|
|||||||
Challenge c = new Challenge(id, type, accepted);
|
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)
|
private void ProcessPlayer (Block playerBlock)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ namespace WorldOfPeacecraft
|
|||||||
Coords = null;
|
Coords = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HasMoreSteps()
|
||||||
|
{
|
||||||
|
return Coords != null && Coords.Count >= 2;
|
||||||
|
}
|
||||||
|
|
||||||
public string NextStep ()
|
public string NextStep ()
|
||||||
{
|
{
|
||||||
if (Coords == null) {
|
if (Coords == null) {
|
||||||
@@ -30,13 +35,13 @@ namespace WorldOfPeacecraft
|
|||||||
}
|
}
|
||||||
string command;
|
string command;
|
||||||
if (src.X > dst.X) {
|
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";
|
command = "mv:lft";
|
||||||
} else if (src.Y < dst.Y) {
|
} else if (src.X < dst.X) {
|
||||||
command = "mv:rgt";
|
command = "mv:rgt";
|
||||||
|
} else if (src.Y > dst.Y) {
|
||||||
|
command = "mv:up";
|
||||||
|
} else if (src.Y < dst.Y) {
|
||||||
|
command = "mv:dwn";
|
||||||
} else {
|
} else {
|
||||||
command = NextStep ();
|
command = NextStep ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user