Tetris/Java: Difference between revisions

Content added Content deleted
mNo edit summary
m (each Shape should just have one shape)
Line 214: Line 214:
g.translate(offsetX, offsetY);
g.translate(offsetX, offsetY);


for (int[] p : preSelectedShape.shapes[idx])
for (int[] p : preSelectedShape.shape)
drawSquare(g, idx, p[1], p[0]);
drawSquare(g, idx, p[1], p[0]);


Line 457: Line 457:


enum Shape {
enum Shape {
ZShape, SShape, Straight, TShape, Square, LShape, JShape;
ZShape(new int[][]{{0, -1}, {0, 0}, {-1, 0}, {-1, 1}}),
SShape(new int[][]{{0, -1}, {0, 0}, {1, 0}, {1, 1}}),
Straight(new int[][]{{0, -1}, {0, 0}, {0, 1}, {0, 2}}),
TShape(new int[][]{{-1, 0}, {0, 0}, {1, 0}, {0, 1}}),
Square(new int[][]{{0, 0}, {1, 0}, {0, 1}, {1, 1}}),
LShape(new int[][]{{-1, -1}, {0, -1}, {0, 0}, {0, 1}}),
JShape(new int[][]{{1, -1}, {0, -1}, {0, 0}, {0, 1}});


private Shape() {
private Shape(int[][] shape) {
this.shape = shape;
pos = new int[4][2];
pos = new int[4][2];
reset();
reset();
Line 466: Line 473:
void reset() {
void reset() {
for (int i = 0; i < pos.length; i++) {
for (int i = 0; i < pos.length; i++) {
pos[i] = shapes[ordinal()][i].clone();
pos[i] = shape[i].clone();
}
}
}
}


final int[][] pos;
final int[][] pos, shape;

final int[][][] shapes = {
{{0, -1}, {0, 0}, {-1, 0}, {-1, 1}},
{{0, -1}, {0, 0}, {1, 0}, {1, 1}},
{{0, -1}, {0, 0}, {0, 1}, {0, 2}},
{{-1, 0}, {0, 0}, {1, 0}, {0, 1}},
{{0, 0}, {1, 0}, {0, 1}, {1, 1}},
{{-1, -1}, {0, -1}, {0, 0}, {0, 1}},
{{1, -1}, {0, -1}, {0, 0}, {0, 1}}};
}
}