-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tetromini.java
106 lines (90 loc) · 2.05 KB
/
Tetromini.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package animation;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.Random;
public abstract class Tetromini implements MoveableShape
{
/**
* Gets the maximum Y grid unit of a rectangle in this tetromini.
*
* @param rectNum the rectangle number of tetromini.
* @return the grid unit of the maximum y.
*/
public int getGridMaxYOfRect(int rectNum)
{
return getGridUnit((int) rect[rectNum].getMaxY());
}
/**
* Gets the X grid unit of a rectangle in this tetromini.
*
* @param rectNum rectNum the rectangle number of tetromini.
* @return the grid unit of the x.
*/
public int getGridXOfRect(int rectNum)
{
return getGridUnit((int) rect[rectNum].getMinX());
}
/**
* Gets the Y grid unit of a rectangle in this tetromini.
*
* @param rectNum the rectangle number of tetromini.
* @return the grid unit of the y.
*/
public int getGridYOfRect(int rectNum)
{
return getGridUnit((int) rect[rectNum].getMinY());
}
/**
* Gets the rotation range of this tetromini. Default is 3.
*
* @return The rotation range of the tetromini.
*/
public int getRotationRange()
{
return 3;
}
/**
* Translates the tetromini.
*
* @param dx x translation.
* @param dy y translation.
*/
@Override
public void translate(int dx, int dy)
{
// TODO Auto-generated method stub
topLeftY += dy;
topLeftX += dx;
}
/**
* Gets the rectangles that makes up this tetromini.
*
* @return The rectangles that make up this tetromini.
*/
public Rectangle2D[] getRectangles()
{
return rect;
}
/**
* Gets the color of this tetromini.
*
* @return The color.
*/
public abstract Color getColor();
/**
* Gets the unrounded (truncated) grid unit of a pixel
*
* @param pixel the pixel to convert
* @return the unrounded grid unit.
*/
public static int getGridUnit(int pixel)
{
return pixel / Grid.BLOCK_LENGTH;
}
public abstract void rotate();
protected Rectangle2D[] rect;
protected int topLeftX;
protected int topLeftY;
protected int rotationNumber;
protected Random generator;
}