1 package erland.game.tetris;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.awt.*;
22
23 /***
24 * Represents the block:
25 * <br>x000
26 * <br>xxx0
27 * @author Erland Isaksson
28 */
29 class Block4 extends Block
30 {
31 /*** The color of the block */
32 protected static Color color = Color.cyan;
33 public Color getColor()
34 {
35 return color;
36 }
37 protected boolean check(BlockMatrix m, int x, int y, int rotation)
38 {
39 if(rotation>=360) {
40 rotation-=360;
41 }else if(rotation<0) {
42 rotation+=360;
43 }
44
45 if(rotation == 0) {
46 if(!m.isUsed(x,y) && !m.isUsed(x+1,y) && !m.isUsed(x-1,y) && !m.isUsed(x-1,y-1)) {
47 return true;
48 }
49 }else if(rotation == 90) {
50 if(!m.isUsed(x,y) && !m.isUsed(x,y+1) && !m.isUsed(x,y-1) && !m.isUsed(x+1,y-1)) {
51 return true;
52 }
53 }else if(rotation == 180) {
54 if(!m.isUsed(x,y) && !m.isUsed(x+1,y) && !m.isUsed(x-1,y) && !m.isUsed(x+1,y+1)) {
55 return true;
56 }
57 }else if(rotation == 270) {
58 if(!m.isUsed(x,y) && !m.isUsed(x,y+1) && !m.isUsed(x,y-1) && !m.isUsed(x-1,y+1)) {
59 return true;
60 }
61 }
62 return false;
63 }
64
65 protected void unset(BlockMatrix m, int x, int y, int rotation)
66 {
67 if(rotation>=360) {
68 rotation-=360;
69 }else if(rotation<0) {
70 rotation+=360;
71 }
72
73 if(rotation == 0) {
74 m.setUnused(x,y);
75 m.setUnused(x+1,y);
76 m.setUnused(x-1,y);
77 m.setUnused(x-1,y-1);
78 }else if(rotation == 90) {
79 m.setUnused(x,y);
80 m.setUnused(x,y+1);
81 m.setUnused(x,y-1);
82 m.setUnused(x+1,y-1);
83 }else if(rotation == 180) {
84 m.setUnused(x,y);
85 m.setUnused(x+1,y);
86 m.setUnused(x-1,y);
87 m.setUnused(x+1,y+1);
88 }else if(rotation == 270) {
89 m.setUnused(x,y);
90 m.setUnused(x,y+1);
91 m.setUnused(x,y-1);
92 m.setUnused(x-1,y+1);
93 }
94 }
95
96 protected void set(BlockMatrix m, int x, int y, int rotation)
97 {
98 if(rotation>=360) {
99 rotation-=360;
100 }else if(rotation<0) {
101 rotation+=360;
102 }
103
104 this.x = x;
105 this.y = y;
106 this.rotation = rotation;
107
108 if(rotation == 0) {
109 m.setUsed(x,y,color);
110 m.setUsed(x+1,y,color);
111 m.setUsed(x-1,y,color);
112 m.setUsed(x-1,y-1,color);
113 }else if(rotation == 90) {
114 m.setUsed(x,y,color);
115 m.setUsed(x,y+1,color);
116 m.setUsed(x,y-1,color);
117 m.setUsed(x+1,y-1,color);
118 }else if(rotation == 180) {
119 m.setUsed(x,y,color);
120 m.setUsed(x+1,y,color);
121 m.setUsed(x-1,y,color);
122 m.setUsed(x+1,y+1,color);
123 }else if(rotation == 270) {
124 m.setUsed(x,y,color);
125 m.setUsed(x,y+1,color);
126 m.setUsed(x,y-1,color);
127 m.setUsed(x-1,y+1,color);
128 }
129 }
130 }