-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPieceType.java
More file actions
125 lines (115 loc) · 3.66 KB
/
Copy pathPieceType.java
File metadata and controls
125 lines (115 loc) · 3.66 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.util.Random;
import java.util.Objects;
public class PieceType extends Object {
private static final Random random = new Random();
private final int maxOrientations;
private final Point[] points;
private final String pieceType;
public PieceType() {
points = new Point[4];
this.maxOrientations = -1;
this.pieceType = "";
}
public PieceType(String pieceType) {
this.pieceType = pieceType;
if(pieceType.equals("O")) {
points = new Point[4];
points[0] = new Point(-1,0);
points[1] = new Point(0,0);
points[2] = new Point(-1,-1);
points[3] = new Point(0,-1);
this.maxOrientations = 0;
}
else if(pieceType.equals("I")) {
points = new Point[4];
points[0] = new Point(-2, 0);
points[1] = new Point(-1, 0);
points[2] = new Point(0,0);
points[3] = new Point(1,0);
this.maxOrientations = 2;
}
else if(pieceType.equals("S")) {
points = new Point[4];
points[0] = new Point(0, 0);
points[1] = new Point(1, 0);
points[2] = new Point(-1, -1);
points[3] = new Point(0, -1);
this.maxOrientations = 2;
}
else if(pieceType.equals("Z")) {
points = new Point[4];
points[0] = new Point(-1, 0);
points[1] = new Point(0, 0);
points[2] = new Point(0, -1);
points[3] = new Point(1, -1);
this.maxOrientations = 2;
}
else if(pieceType.equals("L")) {
points = new Point[4];
points[0] = new Point(-1, 0);
points[1] = new Point(0, 0);
points[2] = new Point(1, 0);
points[3] = new Point(-1, -1);
this.maxOrientations = 4;
}
else if(pieceType.equals("J")) {
points = new Point[4];
points[0] = new Point(-1, 0);
points[1] = new Point(0, 0);
points[2] = new Point(1, 0);
points[3] = new Point(1, -1);
this.maxOrientations = 4;
}
else if(pieceType.equals("T")) {
points = new Point[4];
points[0] = new Point(-1, 0);
points[1] = new Point(0, 0);
points[2] = new Point(1, 0);
points[3] = new Point(0, -1);
this.maxOrientations = 4;
}
else {
points = new Point[4];
this.maxOrientations = -1;
}
}
public static PieceType getRandomPiece() {
PieceType randomPiece = new PieceType();
int randomNum = (int) (random.nextInt(6));
if(randomNum == 0) {
randomPiece = new PieceType("O");
}
else if(randomNum == 1) {
randomPiece = new PieceType("I");
}
else if(randomNum == 2) {
randomPiece = new PieceType("S");
}
else if(randomNum == 3) {
randomPiece = new PieceType("Z");
}
else if(randomNum == 4) {
randomPiece = new PieceType("L");
}
else if(randomNum == 5) {
randomPiece = new PieceType("J");
}
else if(randomNum == 6) {
randomPiece = new PieceType("T");
}
return randomPiece;
}
public Point[] getPoints() {
return points;
}
public int getMaxOrientations() {
return maxOrientations;
}
public String getPieceType() {
return pieceType;
}
@Override
public String toString() {
return "Piece Type: " + pieceType + "Max Orientations: " + maxOrientations;
}
}