Observer-modell

This commit is contained in:
2014-05-15 13:40:29 +02:00
parent 0c50f3b801
commit 42fcc8a1f0
4 changed files with 29 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ namespace WorldOfPeacecraft
private int SelfId;
private AutoResetEvent InitializedEvent = new AutoResetEvent(false);
private bool initialized = false;
private Pathwalker Pathwalker = new Pathwalker();
public Backend (IGui gui)
{
@@ -40,6 +41,7 @@ namespace WorldOfPeacecraft
public void SetSelfId (int id)
{
this.SelfId = id;
Players[SelfId].LocationChanged += OnPlayerMoved;
}
public IEnumerable<IEntity> GetDragons ()
@@ -151,22 +153,21 @@ namespace WorldOfPeacecraft
public void MoveTo (int x, int y)
{
if (Map.GetTiles () [x, y].IsWalkable ()) {
Thread thread = new Thread (() => WalkTo (x, y));
thread.IsBackground = true;
thread.Start ();
}
// Hier müsste man locken
Pathwalker.Stop();
LinkedList<Coordinate> path = Pathfinder.FindPath (Players [SelfId].Coord, new Coordinate (x, y), Map);
Pathwalker.SetCoords (path);
}
private void WalkTo (int x, int y)
public void MoveStep ()
{
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(250);
}
if (Pathwalker.HasMoreSteps())
SenderBuffer.AddLine("ask:" + Pathwalker.NextStep());
}
public void OnPlayerMoved (int x, int y)
{
MoveStep();
}
public void RefreshGui ()