001    package breakout;
002    
003    import java.awt.Point;
004    import java.awt.Dimension;
005    import java.util.Iterator;
006    
007    /**
008     * public interface World encapsulates how BreakoutComponents and
009     * exterior entites interact with a game world.
010     *
011     * @see breakout.WorldListener
012     * @see breakout.BreakoutComponent
013     *
014     * @author benmv@olin.edu
015     * @version <tt>$Id</tt>
016     */
017    public interface World {
018        /** maximum X value */
019        public static final int MAXX = 320;
020    
021        /** maximum Y value */
022        public static final int MAXY = 200;
023            
024        /** 
025         * This is the maximum distance between any two consecutive points
026         * in a shape describing a {@link DefaultBreakoutComponent} 
027         * (in units of pixels)
028         */
029        public static final float SHAPE_PRECISION = 2.0f;
030    
031        /**
032         * tests to see if anything else in the world intersects with
033         * the given component.  If more than one component intersects,
034         * an implementation dependant choice will be made a one returned.
035         * 
036         * @param bc component to test
037         * @return BreakoutComponent or null if none.
038         */
039        public BreakoutComponent intersects(BreakoutComponent bc);
040        
041        /**
042         * rebound causes the two entities to rebound off each other, mutating
043         * their DX and DY values.
044         * if both objects are active, equal mass assumed.
045         * if only one object is active, the inactive one assumed to have infinite mass.
046         * if both are inactive, nothing happens.
047         *
048         * @param bc1 component to have rebound
049         * @param bc2 component to have rebound
050         */
051         public void rebound(BreakoutComponent bc1, BreakoutComponent bc2);
052        
053        /**
054         * adds a component to the world
055         *
056         * @param bc component to add.
057         */
058        public void add(BreakoutComponent bc);
059        
060        /**
061         * adds a component to the world and adds it to the MouseListeners
062         * and MouseMotionListeners
063         *
064         * @param bc component to add
065         * @throws ClassCastException if argument doesn't implement the
066         * required interfaces.
067         */
068        public void addMouseAware(BreakoutComponent bc);
069        
070        /**
071         * returns an iterator over the elements of the World
072         *
073         * @return Iterator that supports remove();
074         */
075        public Iterator iterator();
076        
077        /**
078         * removes the component at the given coordinates.  Coordinates
079         * must exactly match.  Removes at most one component.
080         *
081         * @param location coordinates of component to be removed.
082         */
083        public void removeAt(Point location);
084        
085        /**
086         * signal that the given ball has left the board for a better place
087         * (the other board).  The ball is kill()'ed.
088         *
089         * @param bc ball that has left.  Ball is killed.
090         */
091        public void ballLeft(Ball bc);
092        
093        /**
094         * kills all components except the walls and empties the vector.
095         * pauses for half a second to ensure all previous threads have died
096         * before continuing.  Resets the number of balls.
097         */
098        public void killAll();
099        
100        /**
101         * indicate that game should start.  releases a ball from the store.
102         */
103        public void startPlaying();
104        
105        /**
106         * returns true if a game is in progress.
107         *
108         * @return boolean true if a game is in progress.
109         */
110        public boolean playing();
111        
112        /**
113         * returns the number of balls left.
114         *
115         * @return int number of balls left
116         */
117        public int getBallsLeft();
118        
119        /**
120         * adds the given listener to the list of objects to be informed
121         * of changes in the world state
122         *
123         * @param wl WorldListener to add.
124         */
125        public void addWorldListener(WorldListener wl);
126    }
127    
128    /*
129     * $Log: World.java,v $
130     * Revision 1.2  2004/03/26 20:39:33  gus
131     * take ownership
132     *
133     * Revision 1.1  2003/07/10 21:33:47  jon
134     * Initial commit of spring03 breakout source.
135     *
136     * Revision 1.6  2003/03/07 19:53:51  bvandiver
137     * formatting and WorldState cleanup
138     *
139     * Revision 1.5  2003/03/07 16:58:57  gus
140     * added a constant to control the density of points in shapes describing
141     * our components
142     *
143     */
144