-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverseLBlock.java
63 lines (58 loc) · 2.65 KB
/
ReverseLBlock.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
62
63
package org.cis120.tetris;
import java.awt.Color;
import java.awt.Graphics;
public class ReverseLBlock extends Piece {
private Position[] coordinates;
public ReverseLBlock(int courtWidth, int courtHeight) {
super(30, 90, 0, 210, 540, courtWidth, courtHeight, 7);
coordinates = new Position[4];
coordinates[0] = new Position(90, 0);
coordinates[1] = new Position(90, 30);
coordinates[2] = new Position(120, 30);
coordinates[3] = new Position(150, 30);
super.setCoordinates(coordinates);
}
@Override
public void draw(Graphics g) {
if (this.isMoving()) {
int[] xAxis = this.getxAxis();
int[] yAxis = this.getyAxis();
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx() + 30 * yAxis[0], this.getPy() + 30 * yAxis[1]);
coordinates[2] = new Position(this.getPx() + 30 * xAxis[0] + 30 * yAxis[0], this.getPy() + 30 * xAxis[1] + 30 * yAxis[1]);
coordinates[3] = new Position(this.getPx() + 60 * xAxis[0] + 30 * yAxis[0], this.getPy() + 60 * xAxis[1] + 30 * yAxis[1]);
super.setCoordinates(coordinates);
int diffRight = 0;
int diffBottom = 0;
for (int i = 0; i < coordinates.length; i++) {
if (this.getXDiffFromIntial(coordinates[i]) > diffRight) {
diffRight = this.getXDiffFromIntial(coordinates[i]);
}
if (this.getYDiffFromIntial(coordinates[i]) > diffBottom) {
diffBottom = this.getYDiffFromIntial(coordinates[i]);
}
}
this.setMaxX(this.courtWidth - diffRight - 30);
this.setMaxY(this.courtHeight - diffBottom - 30);
this.adjust();
for (int i = 0; i < coordinates.length; i++) {
Square curr = new Square(
coordinates[i].getX(), coordinates[i].getY(), Color.BLUE
);
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() + 60, this.getPy() + 30);
this.setCoordinates(coordinates);
}
}