package dtmgame; import java.awt.Graphics; import java.awt.Point; /** * @author Shaohan Hu * */ public class Circle { private static final long serialVersionUID = 1L; private int x, y; private int r; public Circle(int r, Point p) { this.x = p.x; this.y = p.y; this.r = r; } public void setPosition(Point p) { this.x = p.x; this.y = p.y; } public void drawCircle(Graphics g) { g.fillOval(x - r, y - r, 2 * r, 2 * r); } public void drawPreview(Graphics g) { g.drawOval(x - r, y - r, 2 * r, 2 * r); } public boolean isTouched(Point p) { if (Math.sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)) <= r) { return true; } else { return false; } } }