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

@@ -4,6 +4,9 @@ namespace WorldOfPeacecraft
{
private int Score;
public delegate void LocationChangedEventHandler (int x, int y);
public event LocationChangedEventHandler LocationChanged;
public Player (int id, int posX, int posY, string desc, bool busy, int score) : base(id, posX, posY, desc, busy)
{
this.SetScore(score);
@@ -24,6 +27,16 @@ namespace WorldOfPeacecraft
return Desc;
}
public override void SetPos (int x, int y)
{
bool positionChanged = false;
if (x != GetX() || y != GetY ())
positionChanged = true;
base.SetPos (x, y);
if (LocationChanged != null)
LocationChanged(x, y);
}
public override string ToString()
{
return "Player: " + Id + " " + Coord.X + " " + Coord.Y + " " + Desc + " " + Busy + " " + Score;