Observer-modell
This commit is contained in:
@@ -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 ()
|
||||
|
||||
Reference in New Issue
Block a user