-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquareBlock.java
54 lines (46 loc) · 2 KB
/
SquareBlock.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
package org.cis120.tetris;
import java.awt.Color;
import java.awt.Graphics;
public class SquareBlock extends Piece {
private Position[] coordinates;
public SquareBlock(int courtWidth, int courtHeight) {
super(30, 120, 0, 240, 540, courtWidth, courtHeight, 1);
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx(), this.getPy() + 30);
coordinates[2] = new Position(this.getPx() + 30, this.getPy() + 30);
coordinates[3] = new Position(this.getPx() + 30, this.getPy());
this.setCoordinates(coordinates);
}
public void updateCoordinates() {
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx(), this.getPy() + 30);
coordinates[2] = new Position(this.getPx() + 30, this.getPy() + 30);
coordinates[3] = new Position(this.getPx() + 30, this.getPy());
this.setCoordinates(coordinates);
}
@Override
public void draw(Graphics g) {
if (this.isMoving()) {
this.updateCoordinates();
for (int i = 0; i < coordinates.length; i++) {
Square curr = new Square(
coordinates[i].getX(), coordinates[i].getY(), Color.YELLOW
);
curr.draw(g);
g.setColor(Color.GRAY);
g.drawRect(coordinates[i].getX(), coordinates[i].getY(), 30, 30);
}
}
}
@Override
public void updateCoords() {
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx(), this.getPy() + 30);
coordinates[2] = new Position(this.getPx() + 30, this.getPy() + 30);
coordinates[3] = new Position(this.getPx() + 30, this.getPy());
this.setCoordinates(coordinates);
}
}