-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
118 lines (98 loc) · 2.5 KB
/
Piece.java
File metadata and controls
118 lines (98 loc) · 2.5 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
import java.awt.Color;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author UNA
*/
public class Piece {
/*
Pieces in order:
-
O
J
L
T
Z
S
*/
private int[][][] pieces = {{{-2, 0}, {-1, 0}, {0, 0}, {1, 0}},
{{0, 0}, {1, 0}, {0, 1}, {1, 1}},
{{0, 0}, {1, 0}, {2, 0}, {0, 1}},
{{0, 0}, {1, 0}, {2, 0}, {2, 1}},
{{0, 1}, {1, 0}, {1, 1}, {2, 1}},
{{0, 0}, {1, 0}, {1, 1}, {2, 1}},
{{0, 1}, {1, 1}, {1, 0}, {2, 0}}};
private Color[] colors = {new Color(0, 255, 255),
new Color(255, 255, 0),
new Color(0, 0, 255),
new Color(255, 128, 0),
new Color(127, 0, 255),
new Color(255, 0, 0),
new Color(0, 255, 0)};
private int[][] pieceCoords = new int[4][2];
private int typePiece;
private boolean isFilled = false;
private boolean isFall = false;
public Piece() {
}
public void newPiece() {
typePiece = (int) (Math.random() * 7);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 2; j++) {
pieceCoords[i][j] = pieces[typePiece][i][j];
}
}
}
private void setX(int i, int val){
pieceCoords[i][0] = val;
}
private int getX(int i){
return pieceCoords[i][0];
}
private void setY(int i, int val){
pieceCoords[i][1] = val;
}
private int getY(int i){
return pieceCoords[i][01];
}
public Piece rotate() {
if (typePiece == 1) {
return this;
}
Piece newPiece = new Piece();
newPiece.setTypePiece(this.getTypePiece());
for (int i = 0; i < 4; i++) {
newPiece.setX(i, -getY(i));
newPiece.setY(i, getX(i));
}
return newPiece;
}
public int[][] getPieceCoords() {
return pieceCoords;
}
public boolean isIsFilled() {
return isFilled;
}
public boolean isIsFall() {
return isFall;
}
public void setIsFilled(boolean isFilled) {
this.isFilled = isFilled;
}
public void setIsFall(boolean isFall) {
this.isFall = isFall;
}
public int getTypePiece() {
return typePiece;
}
public Color[] getColors() {
return colors;
}
public void setTypePiece(int typePiece) {
this.typePiece = typePiece;
}
}