View Javadoc

1   package erland.game.tetris;
2   /*
3    * Copyright (C) 2003 Erland Isaksson (erland_i@hotmail.com)
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   *
19   */
20  
21  import java.awt.*;
22  
23  /***
24   * Represents the block:
25   * <br>0xx0
26   * <br>xx00
27   * @author Erland Isaksson
28   */
29  class Block6 extends Block
30  {
31  	/*** The color of the block */
32  	protected static Color color = Color.pink;
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,y-1) && !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+1,y) && !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,y+1) && !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-1,y) && !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,y-1);
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+1,y);
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,y+1);
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-1,y);
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,y-1,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+1,y,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,y+1,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-1,y,color);
126 			m.setUsed(x,y+1,color);
127 			m.setUsed(x-1,y-1,color);
128 		}
129 	}
130 }