-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMini.java
81 lines (69 loc) · 1.65 KB
/
OMini.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
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 O.
*
* @author johnsonhsiung
*
*/
public class OMini extends Tetromini
{
/**
* Makes an object of OMini starting at a random location on the first row of
* the grid.
*/
public OMini()
{
generator = new Random();
topLeftX = Grid.BLOCK_LENGTH * generator.nextInt(Grid.COLUMNS - 1);
topLeftY = 0;
}
/**
* Draws the OMini 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];
rect[0] = new Rectangle(topLeftX, 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, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH);
rect[3] = new Rectangle(topLeftX + Grid.BLOCK_LENGTH, topLeftY + Grid.BLOCK_LENGTH, Grid.BLOCK_LENGTH,
Grid.BLOCK_LENGTH);
g2.setColor(getColor());
g2.fill(rect[0]);
g2.fill(rect[1]);
g2.fill(rect[2]);
g2.fill(rect[3]);
g2.setColor(Color.DARK_GRAY.brighter());
g2.draw(rect[0]);
g2.draw(rect[1]);
g2.draw(rect[2]);
g2.draw(rect[3]);
}
@Override
/**
* OMini's cannot rotate, so this method returns.
*/
public void rotate()
{
return;
}
/**
* Gets the color of this object.
*
* @return OMini's are always YELLOW, so it returns YELLOW.
*/
@Override
public Color getColor()
{
return Color.YELLOW;
}
}