001    package breakout;
002    
003    import java.awt.*;
004    
005    /** A basic implementation of the Brick interface. **/
006    public class BasicBrick implements Brick {
007            /** The location of this BasicBrick. **/
008            protected Point location;
009            /** The size of this BasicBrick. **/
010            protected Dimension size;
011    
012            /** Creates a new BasicBrick of the specified dimensions.
013              * @param width The intended width of the BasicBrick.
014              * @param height The intended height of the BasicBrick.
015            **/
016            public BasicBrick(int width, int height) {
017                    this.size = new Dimension(width, height);
018            }
019            
020            /** Sets the location of this BasicBrick.
021              * @param p a Point object representing the intended location
022              *  of this BasicBrick.
023            **/
024            public void setLocation(Point p) {
025                    this.location = new Point(p.x, p.y);
026            }
027            
028            /** Gets the location of this BasicBrick.
029              * @return a new Point object representing the location of this BasicBrick.
030            **/
031            public Point getLocation() {
032                    return this.location;
033            }
034            /** Gets the size of this BasicBrick.
035              * @return a new Dimension object representing the size of this BasicBrick.
036            **/
037            public Dimension getSize() {
038                    return this.size;
039            }
040            
041            /** Called by World every tick; by default does nothing. **/
042            public void update() {}
043            
044            /** Called by a Rebounding BreakoutComponent when it has detected an intersection
045              *  with this BasicBrick.
046              * @param bc the Rebounding/BreakoutComponent object that detected the intersection.
047              * @return <code>true</code> -- a BasicBrick dies when it is hit.
048            **/
049            public boolean hit(BreakoutComponent bc) {
050                return true;
051            }
052            
053            /** Gets the java.awt.Shape of this BasicBrick. 
054              * @return a new Shape label at the same location and of the same size/shape as this BasicBrick.
055            **/
056            public Shape getShape() {
057                return new Rectangle(this.location, this.size);
058            }
059            
060            /** Paints the BasicBrick.
061              * @param g Graphics object for this ball's coordinate frame(ie, already located where we are).
062            **/
063            public void paint(Graphics g) {
064                    g.setColor(Color.red);
065                    g.drawRect(0,0,this.size.width, this.size.height);
066            }
067    }