-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinglePiece.java
More file actions
163 lines (157 loc) · 3.67 KB
/
SinglePiece.java
File metadata and controls
163 lines (157 loc) · 3.67 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Represent a piece of the Tetris game
* @author Acosta and Chen
* @version 1.5 4/8/14
*/
public class SinglePiece
{
//Represent each status of each shape in a 4*4 grid: [shape][status][grid]:
public static final int[][][] PIECES =
{
// Shape "I" (has a vertical and a horizontal status)
{ {0, 0, 0, 0,
1, 1, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0},//first status of "I"
{0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0},//second status of "I"
{0, 0, 0, 0,
1, 1, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0},//third status of "I"
{0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0}},//fourth status of "I"
// Shape "O" (all status are the same)
{ {1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//first status of "O"
{1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//second status of "O"
{1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//third status of "O"
{1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0}},//fourth status of "O"
// Shape "S" (has two different status)
{ {0, 1, 1, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//first status of "S"
{1, 0, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0},//second status of "S"
{0, 1, 1, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//third status of "S"
{1, 0, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0}},//fourth status of "S"
// Shape "Z" (has two different status)
{ {1, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},//first status of "Z"
{0, 1, 0, 0,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0},//second status of "Z"
{1, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},//third status of "Z"
{0, 1, 0, 0,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0}},//fourth status of "Z"
// Shape "J" (has four different status)
{ {0, 1, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0},//first status of "J"
{1, 0, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},//second status of "J"
{1, 1, 0, 0,
1, 0, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0},//third status of "J"
{1, 1, 1, 0,
0, 0, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0}},//fourth status of "J"
// Shape "L" (has four different status)
{ {1, 0, 0, 0,
1, 0, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0},//first status of "L"
{1, 1, 1, 0,
1, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//second status of "L"
{1, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0},//third status of "L"
{0, 0, 1, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0}},//fourth status of "L"
// Shape "T" (has four different status)
{ {1, 1, 1, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},//first status of "T"
{0, 1, 0, 0,
0, 1, 1, 0,
0, 1, 0, 0,
0, 0, 0, 0},//second status of "T"
{0, 1, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},//third status of "T"
{0, 1, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0}}//fourth status of "T"
};
private int shape;
private int status;
/**
* Constructor, set the shape and status of this piece
* @param shape the shape of this piece
* @param status the status of this piece
*/
public SinglePiece(int shape, int status)
{
this.shape = shape;
this.status = status;
}
/**
* @return the shape of this piece.
*/
public int getShape()
{
return shape;
}
/**
* @return the status of this piece.
*/
public int getStatus()
{
return status;
}
}