void CharacterChangedLocation(CharacterChangeLocationEventArgs e) { APerson ch = Characters.Find(c => c.id == e.characterId); var destination = Locations.Find(l => l.Position == e.DestinationTarget); var startLocation = Locations.Find(l => l.Position == e.PreviousLocation); try { startLocation.CharacterLeft(ch); } catch { Stopwatch stp = new Stopwatch(); stp.Start(); while (stp.ElapsedMilliseconds < 1000) { } stp.Stop(); CharacterChangedLocation(e); } destination.CharacterEnter(ch); ch.CurrentPosition = e.DestinationTarget; Console.WriteLine("{0} has left {1} and entered {2}", ch.Name, startLocation.Name, destination.Name); }
public void MoveTo(int destinationPosition) { CharacterChangeLocationEventArgs e = new CharacterChangeLocationEventArgs(); e.DestinationTarget = destinationPosition; e.PreviousLocation = CurrentPosition; e.characterId = id; OnChangeLocation(e); }
protected virtual void OnChangeLocation(CharacterChangeLocationEventArgs e) { ChangeLocationEventHandler?.Invoke(e); }