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>0xx0
27   * @author Erland Isaksson
28   */
29  class Block2 extends Block
30  {
31  	/*** The color of the block */
32  	protected static Color color = Color.green;
33  	public Color getColor()
34  	{
35  		return color;
36  	}
37  
38  	protected boolean check(BlockMatrix m, int x, int y, int rotation)
39  	{
40  		if(rotation>=360) {
41  			rotation-=360;
42  		}else if(rotation<0) {
43  			rotation+=360;
44  		}
45  		if(!m.isUsed(x,y) && !m.isUsed(x+1,y) && !m.isUsed(x+1,y-1) && !m.isUsed(x,y-1)) {
46  			return true;
47  		}
48  		return false;
49  	}
50  	
51  	protected void unset(BlockMatrix m, int x, int y, int rotation)
52  	{
53  		if(rotation>=360) {
54  			rotation-=360;
55  		}else if(rotation<0) {
56  			rotation+=360;
57  		}
58  		
59  		m.setUnused(x,y);
60  		m.setUnused(x+1,y);
61  		m.setUnused(x+1,y-1);
62  		m.setUnused(x,y-1);
63  	}
64  	
65  	protected void set(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  		this.x = x;
74  		this.y = y;
75  		this.rotation = rotation;
76  		
77  		m.setUsed(x,y,color);
78  		m.setUsed(x+1,y,color);
79  		m.setUsed(x+1,y-1,color);
80  		m.setUsed(x,y-1,color);
81  	}
82  }