-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMini.java
89 lines (81 loc) · 2.24 KB
/
SMini.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
package animation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.Random;
/**
* A tetromini in the shape of an S.
*
* @author johnsonhsiung
*
*/
public class SMini extends Tetromini
{
/**
* Makes an object of SMini starting at a random location on the first row of
* the grid.
*/
public SMini()
{
generator = new Random();
topLeftX = Grid.BLOCK_LENGTH * generator.nextInt(Grid.COLUMNS - 2);
topLeftY = 0;
}
/**
* Draws the SMini based on its top left corner.
*
* @param g2 The graphics used to draw.
*/
@Override
public void draw(Graphics2D g2)
{
// TODO Auto-generated method stub
super.rect = new Rectangle2D[4];
if (rotationNumber == 0)
{
rect[0] = new Rectangle(topLeftX + 2 * Grid.BLOCK_LENGTH, topLeftY, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
rect[1] = new Rectangle(topLeftX + Grid.BLOCK_LENGTH, topLeftY, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
rect[2] = new Rectangle(topLeftX + Grid.BLOCK_LENGTH, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH,
Grid.BLOCK_LENGTH);
rect[3] = new Rectangle(topLeftX, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
} else
{
rect[0] = new Rectangle(topLeftX, topLeftY, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
rect[1] = new Rectangle(topLeftX, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
rect[2] = new Rectangle(topLeftX + Grid.BLOCK_LENGTH, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH,
Grid.BLOCK_LENGTH);
rect[3] = new Rectangle(topLeftX + Grid.BLOCK_LENGTH, topLeftY + 2 * Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH,
Grid.BLOCK_LENGTH);
}
g2.setColor(this.getColor());
g2.fill(rect[0]);
g2.fill(rect[1]);
g2.fill(rect[2]);
g2.fill(rect[3]);
g2.setColor(Color.GRAY.brighter());
g2.draw(rect[0]);
g2.draw(rect[1]);
g2.draw(rect[2]);
g2.draw(rect[3]);
}
/**
* Changes the rotationNumber of this object, so draw() can draw the correct
* rotation.
*/
@Override
public void rotate()
{
rotationNumber = generator.nextInt(2);
}
/**
* Gets the color of this object.
*
* @return SMini's are always GREEN, so it returns GREEN.
*/
@Override
public Color getColor()
{
return Color.GREEN;
}
}