001 package components;
002
003 import java.util.Map;
004
005 /**
006 * GameObjectClassification is a tag that describes a GameObject
007 *
008 * This is the enum of GameObjectType that exists, it is useful for new gizmo construction.
009 *
010 *@specfield GameObjectFactory factory //this is the factory of the specified enum.
011 *@specfield String xmlname //This is the xml-valid object name
012 */
013
014 public enum GameObjectClassification {
015 /*
016 BALL,
017 SQUARE_BUMPER,
018 CIRCLE_BUMPER,
019 TRIANGLE_BUMPER,
020 FLIPPER,
021 RIGHTFLIPPER,
022 LEFTFLIPPER,
023 ABSORBER,
024 WALL */
025
026 BALL(new BallFactory(),"ball"),
027 CIRCLEBUMPER(new CircleFactory(),"circleBumper"),
028 SQUAREBUMPER(new SquareFactory(),"squareBumper"),
029 TRIANGLEBUMPER(new TriangleFactory(),"triangleBumper"),
030 FLIPPER(null,"flipper"),
031 ABSORBER(new AbsorberFactory(),"absorber"),
032 LEFTFLIPPER(new LeftFlipperFactory(),"leftFlipper"),
033 RIGHTFLIPPER(new RightFlipperFactory(),"rightFlipper"),
034 WALL(null,null),
035 SELECTED(null, null); // a hack for loading selected textures
036
037 private final GameObjectFactory <? extends GameObject> factory;
038 private final String xmlname;
039
040
041 private GameObjectClassification(GameObjectFactory <? extends GameObject> factory, String xmlname) {
042 this.factory = factory;
043 this.xmlname = xmlname;
044 }
045
046 /**
047 * Returns a GameObject with properties p that match this enum's value
048 * @requires p contains the required properties for p, and that this has a valid factory
049 * @return a new gameobject
050 */
051 public GameObject newInstance(Map<String,String> p, GameSpace g) {
052 if (factory == null) {
053 throw new RuntimeException("This object does not have a factory");
054 }
055 return factory.newInstance(p, g);
056 }
057
058 /**
059 * Returns the xmlname for this object
060 * @return string that is valid for the xml schema
061 */
062 public String getXMLName() {
063 if (xmlname == null) {
064 throw new RuntimeException("This object (" + this.toString() + ") does not have an xmlname");
065 }
066 return xmlname;
067 }
068
069
070 }