-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brick.java
61 lines (50 loc) · 1.27 KB
/
Brick.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
58
59
60
61
import java.awt.geom.*;
import java.awt.*;
public class Brick extends ColorShape {
private int xPos = 0;
private int yPos = 0;
private int width =Parameters.BRICK_WIDTH;
private int height = Parameters.BRICK_HEIGHT;
private Rectangle2D.Double brick = new Rectangle2D.Double(xPos, yPos, width, height);
// constructor
public Brick(int x, int y, int w, int h) {
super(new Rectangle2D.Double(x, y, w, h));
//set brick x, y, width, and height
xPos = x;
yPos =y;
width =w;
height =h;
brick = (Rectangle2D.Double)super.shape;
// update shape
brick.setRect(xPos, yPos, width, height);
}
public int getX() {
return xPos;
}
public int getY() {
return yPos;
}
public void setY(int y){
yPos = y;
}
public void setX(int x){
xPos = x;
}
public Rectangle2D.Double getShape() {
return brick;
}
@Override
public void paint(Graphics2D brush) {
brush.setColor(Color.BLACK);
brush.draw(brick);
brush.setColor(Color.GREEN);
brush.fill(brick);
}
// make the super bricks blue to differentiate them
public void paintS(Graphics2D brush) {
brush.setColor(Color.BLACK);
brush.draw(brick);
brush.setColor(Color.BLUE);
brush.fill(brick);
}
}