/** * House.java * * @author David Tran * @version 1.0 */ package background; import java.awt.Graphics2D; import java.awt.Color; import java.awt.Stroke; import java.awt.BasicStroke; import java.awt.Point; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; /** * A background representing a house. */ public class House extends Background { /** * Initialize attributes for this House * * @param x x-coordinate of this House (leftmost position of background) * @param y y-coordinate of this House (uppermost position of background) * @param w width of this House * @param h height of this House */ public House(double x, double y, double w, double h) { super(x, y, w, h); super.externalName = "House"; } /** * Use the graphics system to draw the shapes representing this House * * @param g the graphics system to use */ public void draw(Graphics2D g) { // Draw rectangles for the hosue // RGB values for brown: Red:[222] Green:[184] Blue[135] g.setPaint(new Color(222, 184, 135)); Rectangle2D.Double houseBody = new Rectangle2D.Double(xCoor, yCoor, width, height); g.fill(houseBody); Rectangle2D.Double houseAtrium = new Rectangle2D.Double(xCoor + width/3, yCoor + height, width/3, height/3); g.fill(houseAtrium); // Draw the pathway to the house g.setPaint(Color.LIGHT_GRAY); g.fill(new Rectangle2D.Double(xCoor + width*5/12, yCoor + height*4/3, width*1/6, height*2/3)); // Draw outline of house g.setPaint(Color.BLACK); g.draw(new Rectangle2D.Double(xCoor, yCoor, width, height)); g.draw(new Rectangle2D.Double(xCoor + width/3, yCoor + height, width/3, height/3)); // Draw Roof g.draw(new Line2D.Double(xCoor, yCoor, xCoor + width/4, yCoor + height/2)); g.draw(new Line2D.Double(xCoor, yCoor + height, xCoor + width/4, yCoor + height/2)); g.draw(new Line2D.Double(xCoor + width/4, yCoor + height/2, xCoor + width*3/4, yCoor + height/2)); g.draw(new Line2D.Double(xCoor + width*3/4, yCoor + height/2, xCoor + width, yCoor)); g.draw(new Line2D.Double(xCoor + width*3/4, yCoor + height/2, xCoor + width, yCoor + height)); } }