Exemplo n.º 1
0
    //Three parameters
    static public void Broadcast <T, U, V>(GameEventEnum eventType, T arg1, U arg2, V arg3)
    {
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
        Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
#endif
        OnBroadcasting(eventType);

        Delegate d;
        if (mEventTable.TryGetValue(eventType, out d))
        {
            Callback <T, U, V> callback = d as Callback <T, U, V>;

            if (callback != null)
            {
                callback(arg1, arg2, arg3);
            }
            else
            {
                throw CreateBroadcastSignatureException(eventType);
            }
        }
    }
Exemplo n.º 2
0
    static public void OnListenerRemoving(GameEventEnum eventType, Delegate listenerBeingRemoved)
    {
#if LOG_ALL_MESSAGES
        Debug.Log("MESSENGER OnListenerRemoving \t\"" + eventType + "\"\t{" + listenerBeingRemoved.Target + " -> " + listenerBeingRemoved.Method + "}");
#endif

        if (mEventTable.ContainsKey(eventType))
        {
            Delegate d = mEventTable[eventType];

            if (d == null)
            {
                throw new ListenerException(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType));
            }
            else if (d.GetType() != listenerBeingRemoved.GetType())
            {
                throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
            }
        }
        else
        {
            throw new ListenerException(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType));
        }
    }
Exemplo n.º 3
0
 //Four parameters
 static public void RemoveListener <T, U, V, X>(GameEventEnum eventType, Action <T, U, V, X> handler)
 {
     OnListenerRemoving(eventType, handler);
     mEventTable[eventType] = (Action <T, U, V, X>)mEventTable[eventType] - handler;
     OnListenerRemoved(eventType);
 }
Exemplo n.º 4
0
 //Four parameters
 static public void AddListener <T, U, V, X>(GameEventEnum eventType, Action <T, U, V, X> handler)
 {
     OnListenerAdding(eventType, handler);
     mEventTable[eventType] = (Action <T, U, V, X>)mEventTable[eventType] + handler;
 }
Exemplo n.º 5
0
 static public BroadcastException CreateBroadcastSignatureException(GameEventEnum eventType)
 {
     return(new BroadcastException(string.Format("Broadcasting message \"{0}\" but listeners have a different signature than the broadcaster.", eventType)));
 }
Exemplo n.º 6
0
 //Three parameters
 static public void RemoveListener <T, U, V>(GameEventEnum eventType, Callback <T, U, V> handler)
 {
     OnListenerRemoving(eventType, handler);
     mEventTable[eventType] = (Callback <T, U, V>)mEventTable[eventType] - handler;
     OnListenerRemoved(eventType);
 }
Exemplo n.º 7
0
 //Three parameters
 static public void AddListener <T, U, V>(GameEventEnum eventType, Callback <T, U, V> handler)
 {
     OnListenerAdding(eventType, handler);
     mEventTable[eventType] = (Callback <T, U, V>)mEventTable[eventType] + handler;
 }
Exemplo n.º 8
0
        private void GameEvent(GameEventEnum ev)
        {
            switch (ev)
            {
            case GameEventEnum.BRICK_DESTROYED:
                common_brick.Play(volume, pitch, pan);
                player.points += 10;
                int brickCounter = 0;
                foreach (Brick b in listOfBricks)
                {
                    if (!b.brickType.Equals(BrickTypeEnum.UNBREAKABLE))
                    {
                        brickCounter++;
                    }
                }
                if (brickCounter == 0)
                {
                    GameEvent(GameEventEnum.LEVEL_COMPLETED);
                }
                GenerateBonus();
                break;

            case GameEventEnum.BRICK_DECREASE_HP:
                common_brick.Play(volume, pitch, pan);
                break;

            case GameEventEnum.UNBREAKABLE_BRICK_HIT:
                unbreakable.Play(volume, pitch, pan);
                break;

            case GameEventEnum.LIFE_LOST:
                lost_life.Play(volume, pitch, pan);
                listOfBonus.Clear();
                player.holdingBall = false;
                player.lifes--;
                player.size           = 2;
                paddle.position.Width = 240;
                player.canShoot       = false;
                if (player.lifes < 1)
                {
                    GameEvent(GameEventEnum.GAME_OVER);
                }
                else
                {
                    ballDropped = true;
                    game.FadeOutEffect();
                }
                break;

            case GameEventEnum.GAME_OVER:
                Console.WriteLine("PRZEGRALES");
                showScoreboard = true;
                game.ShowCursor();
                break;

            case GameEventEnum.BALL_HIT_PADDLE:
                break;

            case GameEventEnum.BALL_HIT_WALL:
                break;

            case GameEventEnum.BONUS_PICKED:
                pick_bonus.Play(volume - .4f, pitch, pan);
                break;

            case GameEventEnum.GAME_WIN:
                Console.WriteLine("WYGRALES");
                showScoreboard = true;
                break;

            case GameEventEnum.LEVEL_COMPLETED:
                MediaPlayer.Volume = .5f;
                MediaPlayer.Play(level_up);
                Console.WriteLine("wygrales poziom");
                player.level++;
                if (player.level > 2)
                {
                    GameEvent(GameEventEnum.GAME_WIN);
                    return;
                }
                changeLevel = true;
                game.FadeOutEffect();
                break;

            case GameEventEnum.SHOOT:
                gunfire.Play(volume, pitch, pan);
                break;
            }
        }
Exemplo n.º 9
0
 public GameEvent(GameEventEnum type, String description = "")
 {
     EventType   = type;
     Timestamp   = DateTime.Now;
     Description = "";
 }