⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameobjecteventmulticaster.java

📁 Developing Games in Java 源代码
💻 JAVA
字号:
package com.brackeen.javagamebook.scripting;

import java.util.*;
import com.brackeen.javagamebook.game.GameObject;

/**
    Adapter to multicast GameObject notifications to multiple
    listeners.
*/
public class GameObjectEventMulticaster
    implements GameObjectEventListener
{

    private List listeners;

    public GameObjectEventMulticaster(GameObjectEventListener l1,
        GameObjectEventListener l2)
    {
        listeners = new LinkedList();
        addListener(l1);
        addListener(l2);
    }

    public void addListener(GameObjectEventListener l) {
        if (l != null) {
            listeners.add(l);
        }
    }


    public void removeListener(GameObjectEventListener l) {
        if (l != null) {
            listeners.remove(l);
        }
    }

    /**
        Notifies this GameObject whether it was visible or not
        on the last update.
    */
    public void notifyVisible(GameObject object, boolean visible) {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyVisible(object, visible);
        }
    }


    /**
        Notifies this GameObject that when it moved, it collided
        with the specified object.
    */
    public void notifyObjectCollision(GameObject object,
        GameObject otherObject)
    {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyObjectCollision(object, otherObject);
        }
    }


    public void notifyObjectTouch(GameObject object,
        GameObject otherObject)
    {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyObjectTouch(object, otherObject);
        }
    }


    public void notifyObjectRelease(GameObject object,
        GameObject otherObject)
    {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyObjectRelease(object, otherObject);
        }
    }


    /**
        Notifies this GameObject that when it moved, it collided
        with a floor.
    */
    public void notifyFloorCollision(GameObject object) {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyFloorCollision(object);
        }
    }


    /**
        Notifies this GameObject that when it moved, it collided
        with a ceiling.
    */
    public void notifyCeilingCollision(GameObject object) {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyCeilingCollision(object);
        }
    }


    /**
        Notifies this GameObject that when it moved, it collided
        with a wall.
    */
    public void notifyWallCollision(GameObject object) {
        Iterator i = listeners.iterator();
        while (i.hasNext()) {
            GameObjectEventListener l =
                (GameObjectEventListener)i.next();
            l.notifyWallCollision(object);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -