import java.awt.Point;

public class SquarePoints2 implements PointGenerator, Displaceable {
    /** half-length of square side */
    private int r;
    
    /** center of star */
    private int x;

    /** center of star */
    private int y;

    /** list of points */
    private Point[] plist;

    /** constructor */
    public SquarePoints2(int r, int x, int y) {
        this.r = r;
        this.x = x;
        this.y = y;
        plist = new Point[5];
        plist[0] = new Point(x-r,y-r);
        plist[1] = new Point(x+r,y-r);
        plist[2] = new Point(x+r,y+r);
        plist[3] = new Point(x-r,y+r);
        plist[4] = new Point(x-r,y-r);
    }

    /** fulfill the PointGenerator contract */
    public Point[] getPointArray() {
        return plist;
    }

    /** accessor for x */
    public int getX() {return x;}

    /** accessor for y */
    public int getY() {return y;}

    /** move all points by given amount */
    public void move(int dx, int dy) {
        x += dx;
        y += dy;
        for (int i = 0; i < 5; i++) {
            plist[i].x += dx;
            plist[i].y += dy;
        }
    }
}
