00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 package org.classroomgaming.cgp;
00021
00022 import java.awt.*;
00023 import java.util.*;
00024
00025 public class GameObject extends GameModule implements GameModule.Renderable, GameModule.Configurable, GameModule.FrameListener, GameModule.Despawnable, GameObjectInterface {
00026
00027
00028 private LinkedHashMap<String, GameModule> modules;
00029
00030
00031 public GameObject() {
00032 modules = new LinkedHashMap<String, GameModule>();
00033 enabled = false;
00034
00035
00036 }
00037
00038
00039
00040 public boolean addModule(String n, GameModule m) {
00041 if (modules.containsKey(n)) {
00042 return false;
00043 }
00044 modules.put(n, m);
00045 return true;
00046 }
00047
00048 public void ponder(float t) {
00049 if (!enabled) {
00050 return;
00051 }
00052
00053 for (Iterator it = modules.values().iterator(); it.hasNext();) {
00054 try {
00055
00056 GameModule.FrameListener o = (GameModule.FrameListener) it.next();
00057 o.ponder(t);
00058 } catch (ClassCastException e) {
00059 }
00060 }
00061
00062 }
00063
00064 public void init(Configurator a) {
00065 for (Iterator it = modules.values().iterator(); it.hasNext();) {
00066 try {
00067 GameModule.Configurable o = (GameModule.Configurable) it.next();
00068 o.init(a);
00069 } catch (ClassCastException e) {
00070 }
00071 }
00072
00073
00074
00075 }
00076
00077 public void deinit() {
00078 for (Iterator it = modules.values().iterator(); it.hasNext();) {
00079 try {
00080 GameModule.Despawnable o = (GameModule.Despawnable) it.next();
00081 o.deinit();
00082 } catch (ClassCastException e) {
00083 }
00084 }
00085
00086 }
00087
00088 public GameModule getModule(String name) {
00089 if (modules.containsKey(name)) {
00090 return (GameModule) modules.get(name);
00091 } else {
00092 return null;
00093 }
00094 }
00095
00096 public void render(Graphics g) {
00097 if (!enabled) {
00098 return;
00099 }
00100
00101 for (Iterator it = modules.values().iterator(); it.hasNext();) {
00102 GameModule o = (GameModule) it.next();
00103 try {
00104 GameModule.Renderable r = (GameModule.Renderable) o;
00105 r.render(g);
00106 } catch (ClassCastException e) {
00107 }
00108
00109
00110 }
00111 }
00112
00113 }
00114