-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineBlock.java
83 lines (76 loc) · 3.26 KB
/
LineBlock.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.cis120.tetris;
import java.awt.Color;
import java.awt.Graphics;
public class LineBlock extends Piece {
private Position[] coordinates;
public LineBlock(int courtWidth, int courtHeight) {
super(30, 90, 0, 180, 570, courtWidth, courtHeight, 2);
// coordinates = new Position[4];
// coordinates[0] = new Position(90, 0);
// coordinates[1] = new Position(120, 0);
// coordinates[2] = new Position(150, 0);
// coordinates[3] = new Position(180, 0);
coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx() + 30, this.getPy());
coordinates[2] = new Position(this.getPx() + 60, this.getPy());
coordinates[3] = new Position(this.getPx() + 90, this.getPy());
super.setCoordinates(coordinates);
}
@Override
public void draw(Graphics g) {
int[] xAxis = this.getxAxis();
// int[] yAxis = this.getyAxis();
int[] d1 = new int[]{30 * xAxis[0], 30 * xAxis[1]};
int[] d2 = new int[]{60 * xAxis[0], 60 * xAxis[1]};
int[] d3 = new int[]{90 * xAxis[0], 90 * xAxis[1]};
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx() + d1[0], this.getPy() + d1[1]);
coordinates[2] = new Position(this.getPx() + d2[0], this.getPy() + d2[1]);
coordinates[3] = new Position(this.getPx() + d3[0], this.getPy() + d3[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.CYAN
);
curr.draw(g);
g.setColor(Color.GRAY);
g.drawRect(coordinates[i].getX(), coordinates[i].getY(), 30, 30);
}
}
@Override
public void updateCoords() {
int[] xAxis = this.getxAxis();
// int[] yAxis = this.getyAxis();
int dx1, dx2, dx3, dy1, dy2, dy3;
int[] d1 = new int[]{30 * xAxis[0], 30 * xAxis[1]};
int[] d2 = new int[]{60 * xAxis[0], 60 * xAxis[1]};
int[] d3 = new int[]{90 * xAxis[0], 90 * xAxis[1]};
dx1 = d1[0];
dx2 = d2[0];
dx3 = d3[0];
dy1 = d1[1];
dy2 = d2[1];
dy3 = d3[1];
this.coordinates = new Position[4];
coordinates[0] = new Position(this.getPx(), this.getPy());
coordinates[1] = new Position(this.getPx() + dx1, this.getPy() + dy1);
coordinates[2] = new Position(this.getPx() + dx2, this.getPy() + dy2);
coordinates[3] = new Position(this.getPx() + dx3, this.getPy() + dy3);
super.setCoordinates(coordinates);
}
}