Example #1
0
 private void BroadcastShipEvent(ShipEvent e)
 {
     if (!EventCallbacks.ContainsKey(e))
     {
         return;
     }
     foreach (var callback in EventCallbacks[e])
     {
         callback(this);
     }
 }
 private void InsertInHistory(ShipEvent shipEvent)
 {
     lock (this._history)
     {
         if (!this._history.Any() || shipEvent.TimeStamp >= this._history.Last().TimeStamp)
         {
             this._history.Add(shipEvent);
         }
         else
         {
             this._history.Insert(this._history.FindIndex(ev => ev.TimeStamp > shipEvent.TimeStamp), shipEvent);
         }
     }
 }
Example #3
0
    public UnregisterEventCallback RegisterEventCallback(ShipEvent e, ShipEventCallback callback)
    {
        if (!EventCallbacks.ContainsKey(e))
        {
            EventCallbacks.Add(e, new HashSet <ShipEventCallback>());
        }
        HashSet <ShipEventCallback> callbacks = EventCallbacks[e];

        callbacks.Add(callback);
        UnregisterEventCallback unreg = () => {
            callbacks.Remove(callback);
        };

        return(unreg);
    }
Example #4
0
    public void LaunchEvent(ShipEvent incomingEvent)
    {
        switch (incomingEvent)
        {
        case ShipEvent.VISUAL:
            SendVisualMessage();
            currentScreens.Add(Screens.GLASS);
            break;

        case ShipEvent.BOMB:
            SendAttack();
            break;

        case ShipEvent.NONE:
            break;
        }
        currentShipEvent = incomingEvent;
    }