-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDART.java
57 lines (52 loc) · 1.41 KB
/
DART.java
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
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
/**
* Dart is a subclass Rectangle that holds a Color, a point, x coordinates, and
* y coordinates. It draws a point of 3x3 and keeps its own location and keep
* track if it lies within a cirle's radius.
*
* @author Warren Lee
*
*/
public class DART extends Rectangle {
Color col;
/**
* Class constructor depicting number of parameters
*
* @param x is a value for an x coordinate.
* @param y is a value for an y coordinate.
*/
public DART(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Checks if distance from (250,250) to a randomly generated point is less than
* an integer r, a radius value. If the distance value is less than r, then it
* changes color to green, otherwise it remains black.
*
* @param r is an integer radius value
* @return true if distance from (250,250) to most recently added dart's
* coordinates is less than r.
*/
public boolean isIn(int r) {
if (Math.hypot(x - 250, y - 250) < r) {
col = Color.GREEN;
return true;
} else {
col = Color.BLACK;
return false;
}
}
/**
* Draws a colored rectangle of dimensions 3 by 3.
*
* @param win is a Graphics2D object
*/
public void moveAndDraw(Graphics2D win) {
win.setColor(col);
win.fillRect(this.x - 1, this.y - 1, 3, 3);
}
}