-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPiece.java
68 lines (54 loc) · 1.19 KB
/
IPiece.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
import javax.swing.JPanel;
public class IPiece extends Shape{
private enum dir {VERTICAL, HORIZONTAL};
private dir state;
public Block[] makeBlocks()
{
state = dir.HORIZONTAL;
for(int x = 0; x < 4; x++)
{
blocks[x] = new Block("cyan");
blocks[x].setLocation((x * 20)+ 15, 100);
}
return blocks;
}
public int addToPlayingBoard(TetrisModel model, int x, int y)
{
this.model = model;
xPos = x;
yPos = y;
for(int i = 0; i < 4; i++)
{
blocks[i].setLocation((i * 20)+60, 0);
if(this.model.addBlock(blocks[i], i+xPos, yPos) == -1)
{
return -1;
}
}
return 0;
}
public int rotate()
{
if(state == dir.HORIZONTAL)
{
if(model.isOpen(xPos+1, yPos-1) && model.isOpen(xPos+1, yPos+1)&& model.isOpen(xPos+1, yPos+2))
{
model.shift(blocks[0], 1, -1);
model.shift(blocks[2], -1, 1);
model.shift(blocks[3], -2, 2);
state = dir.VERTICAL;
}
}
else
{
if(model.isOpen(xPos, yPos+1) && model.isOpen(xPos+2, yPos+1) && model.isOpen(xPos+3, yPos+1))
{
model.shift(blocks[3], 2, -2);
model.shift(blocks[2], 1, -1);
model.shift(blocks[0], -1, 1);
state = dir.HORIZONTAL;
}
}
return 0;
}
}