erland.game.tetris
Class Block

java.lang.Object
  extended byerland.game.tetris.Block
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Block1, Block2, Block3, Block4, Block5, Block6, Block7

abstract class Block
extends java.lang.Object
implements java.lang.Cloneable

Represents a tetris block, all Block sub classes should be derived from this

Author:
Erland Isaksson

Field Summary
protected  int rotation
          rotation angle of block
protected  int x
          x position of block(This is a block coordinate and not a pixel coordinate)
protected  int y
          y position of block(This is a block coordinate and not a pixel coordinate)
 
Constructor Summary
(package private) Block()
           
 
Method Summary
protected abstract  boolean check(BlockMatrix m, int x, int y, int rotation)
          Check if it is possible to put the block in the specified position and rotation angle
 java.lang.Object clone()
           
abstract  java.awt.Color getColor()
          Get the color of the block
 int getRotation()
          Get the rotation of the block
 int getX()
           
 int getY()
           
protected  void init(int x, int y, int rotation)
          Initialize block
 boolean moveDown(BlockMatrix m)
          Move block once step down
 boolean moveLeft(BlockMatrix m)
          Move the block one step left
 boolean moveRight(BlockMatrix m)
          Move the block one step right
 boolean rotateLeft(BlockMatrix m)
          Rotate the block 90 degrees counter clockwize
 boolean rotateRight(BlockMatrix m)
          Rotate the block 90 degrees clockwize
protected abstract  void set(BlockMatrix m, int x, int y, int rotation)
          Put the block in the specified position and rotation angle
protected abstract  void unset(BlockMatrix m, int x, int y, int rotation)
          Remove the block from the specified position and rotation angle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rotation

protected int rotation
rotation angle of block


x

protected int x
x position of block(This is a block coordinate and not a pixel coordinate)


y

protected int y
y position of block(This is a block coordinate and not a pixel coordinate)

Constructor Detail

Block

Block()
Method Detail

getColor

public abstract java.awt.Color getColor()
Get the color of the block

Returns:
The color of the block

clone

public java.lang.Object clone()

getRotation

public int getRotation()
Get the rotation of the block

Returns:
The rotation of the block 0,1,2,3

getX

public int getX()

getY

public int getY()

init

protected void init(int x,
                    int y,
                    int rotation)
Initialize block

Parameters:
x - x position of block(Block coordinate)
y - y position of block(Block coordinate)
rotation - rotation angle of block

moveDown

public boolean moveDown(BlockMatrix m)
Move block once step down

Parameters:
m - The BlockMatrix in which the block resides
Returns:
true/false (Success/Failure)

moveRight

public boolean moveRight(BlockMatrix m)
Move the block one step right

Parameters:
m - The BlockMatrix in which the block resides
Returns:
true/false (Success/Failure)

moveLeft

public boolean moveLeft(BlockMatrix m)
Move the block one step left

Parameters:
m - The BlockMatrix in which the block resides
Returns:
true/false (Success/Failure)

rotateRight

public boolean rotateRight(BlockMatrix m)
Rotate the block 90 degrees clockwize

Parameters:
m - The BlockMatrix in which the block resides
Returns:
true/false (Success/Failure)

rotateLeft

public boolean rotateLeft(BlockMatrix m)
Rotate the block 90 degrees counter clockwize

Parameters:
m - The BlockMatrix in which the block resides
Returns:
true/false (Success/Failure)

check

protected abstract boolean check(BlockMatrix m,
                                 int x,
                                 int y,
                                 int rotation)
Check if it is possible to put the block in the specified position and rotation angle

Parameters:
m - The BlockMatrix in which the block resides
x - The x position which should be checked(Block coordinate)
y - The y position which should be checked(Block coordinate)
rotation - The rotation angle which should be checked
Returns:
true/false (Success/Failure)

set

protected abstract void set(BlockMatrix m,
                            int x,
                            int y,
                            int rotation)
Put the block in the specified position and rotation angle

Parameters:
m - The BlockMatrix in which the block resides
x - The x position (Block coordinate)
y - The y position (Block coordinate)
rotation - The rotation angle

unset

protected abstract void unset(BlockMatrix m,
                              int x,
                              int y,
                              int rotation)
Remove the block from the specified position and rotation angle

Parameters:
m - The BlockMatrix in which the block resides
x - The x position (Block coordinate)
y - The y position (Block coordinate)
rotation - The rotation angle


Copyright © 2003-2004 Erland Isaksson. All Rights Reserved.