import java.awt.Graphics; import java.awt.Color; /**Creates a stationary object "Wall," which is a polygon, and implements interface Polygon.*/ public class Block extends StationaryObject implements Polygon { private int numberOfPoints; /**The coordinates of the polygon are defined by an array of x coordinate values (all the x coordinates of the points of the polygon) * and an array of y coordinate values (all the y coordinates of the points of the polygon)*/ private int[] xPolygon = new int[numberOfPoints]; private int[] yPolygon = new int[numberOfPoints]; /**initializes Block as a rectangle with all coordinates at (0,0)*/ public Block() { super(); int[] x = {0, 1, 0, 0}; int[] y = {0, 0, 0, 0}; numberOfPoints = 4; setCoordinates(x, y, x.length); } /**Creates a polygonal block. * @param name s, color c * @param newXPolygon an array of x values * @param newYPolygon an array of y values*/ public Block(String s, Color c, int[] newXPolygon, int[] newYPolygon, int newNumberOfPoints) { super(s, c); numberOfPoints = newNumberOfPoints; xPolygon = newXPolygon; yPolygon = newYPolygon; } public void setCoordinates(int[] x, int[] y, int n) { xPolygon = x; yPolygon = y; numberOfPoints = n;//should be x.length } public int[] getXCoordinates() { return xPolygon; } public int[] getYCoordinates() { return yPolygon; } /**Draws the block onto Graphics object canvas. The block is filled with a solid color.*/ public void draw(Graphics canvas) { canvas.setColor(super.getColor()); canvas.fillPolygon(xPolygon, yPolygon, numberOfPoints); } }