-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStone.java
More file actions
58 lines (51 loc) · 1.51 KB
/
Copy pathStone.java
File metadata and controls
58 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import javax.swing.*;
/**
* The class that represents a component that draws a stone shape.
* @author: Hung Phan
* @author: Lien Cao
* @author: Wendy Ta
* @version: 1.0 11/28/25
*/
public class Stone extends JComponent{
private final static int SIZE = 10;
private double x, y; //x and y position of stone
private Ellipse2D stone;
/**
* Constructs a stone
* @param x the left of bounding rectangle
* @param y the top of bounding rectangle
*/
public Stone(double x, double y){
this.x = x;
this.y = y;
this.stone = new Ellipse2D.Double(x, y, SIZE, SIZE);
}
/**
* Draws the stone
* @param g2 the graphics context
*/
public void drawStone(Graphics2D g2) { //draw the stones
g2.setColor(Color.BLACK);
g2.fill(stone);
}
/**
* This method allows the shape to move.
* @param dx the changes from the left of the bounding rectangle
* @param dy the changes from the top of the bounding rectangle
*/
public void moveStone(int dx, int dy) {
x += dx;
y += dy;
}
/**
* Checks if the mouse is clicked on the specific area.
* @param p the mouse point
* @return true if mouse is clicked on the correct position, false otherwise
*/
public boolean contains(Point2D p) {
return x <= p.getX() && p.getX() <= x + SIZE && y <= p.getY() && p.getY() <= y + SIZE;
}
}