de.unifreiburg.informatik.tetris.game.block
Class Block

java.lang.Object
  extended by de.unifreiburg.informatik.tetris.game.block.Block

public class Block
extends java.lang.Object


Constructor Summary
Block(CartPt coords, java.awt.Color c)
          Create a new Block at position (x,y) if (x,y) = coords.
Block(int x, int y, java.awt.Color c)
          Create a new Block at position (x,y) if (x,y) = coords.
 
Method Summary
 void draw(java.awt.Graphics g, int blocksize, int gap)
          Draws the block using the graphic g.
 void draw(java.awt.Graphics g, int blocksize, int gap, boolean turnpoint)
          Draws a block, and can draw the turnblocks also.
(package private)  int getY()
          This method is only allowed to use in the package
 boolean isFree(BlockList bl)
          This method is used by the add method to check if we can add the block to the blocklist bl.
 boolean isFree(CartPt coords)
          Use this method to check if the block is at the given position.
 boolean isMoveable(de.unifreiburg.informatik.tetris.game.Field f, CartPt coords)
          Checks if a move is possible.
 boolean isTurnableClockwise(de.unifreiburg.informatik.tetris.game.Field f, Block b)
          Checks if it's allowed to rotate the block (this) by 90 degrees clockwise around b.
 boolean isTurnableCounterClockwise(de.unifreiburg.informatik.tetris.game.Field f, Block b)
          See isTurnableClockwise.
 boolean move(de.unifreiburg.informatik.tetris.game.Field f, CartPt coords)
          Moves the block.
(package private)  void moveDown(int y)
          Moves the block y lines down without any check.
 boolean turnClockwise(de.unifreiburg.informatik.tetris.game.Field f, Block b)
          Turns the block (this) clockwise by 90 degree around the parameter b, if this is possible.
 boolean turnCounterClockwise(de.unifreiburg.informatik.tetris.game.Field f, Block b)
          See turnClockwise.
 void unsavemove(CartPt that)
          This method is used to move the turnpoints.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Block

public Block(CartPt coords,
             java.awt.Color c)
Create a new Block at position (x,y) if (x,y) = coords.

Parameters:
coords - the coordinates of the block
c - the color

Block

public Block(int x,
             int y,
             java.awt.Color c)
Create a new Block at position (x,y) if (x,y) = coords.

Parameters:
x - the x-coordinate
y - the y-coordinate
c - the color
Method Detail

isFree

public boolean isFree(CartPt coords)
Use this method to check if the block is at the given position.

Parameters:
coords - the coordinates to look at
Returns:
false if the block is at position coords.

isFree

public boolean isFree(BlockList bl)
This method is used by the add method to check if we can add the block to the blocklist bl. It returns true if there's no other block in the blocklist with position (x,y).

Parameters:
bl - the blocklist to check.
Returns:
if the position of b is free.

draw

public void draw(java.awt.Graphics g,
                 int blocksize,
                 int gap)
Draws the block using the graphic g. It draws a square with size blocksize pixel. The gap between two blocks is given in pixel.

Parameters:
g - the graphic device
blocksize - the size of a block in pixel
gap - the size of the gap in pixel

draw

public void draw(java.awt.Graphics g,
                 int blocksize,
                 int gap,
                 boolean turnpoint)
Draws a block, and can draw the turnblocks also. If the parameter turnpoint is true, the block is not a normal block draws as a square, but it is draw as a circle to indicate where stones have their center of rotation.

Parameters:
g - the graphic device
blocksize - the size of blocks in pixel
gap - the size of the gap in pixel
turnpoint - indicates if the block is a a normal block or not.

move

public boolean move(de.unifreiburg.informatik.tetris.game.Field f,
                    CartPt coords)
Moves the block. This method checks if the target is free.

Parameters:
f - the field with the blocklist to check.
coords - the offset
Returns:
true if the move was succesfull.

isMoveable

public boolean isMoveable(de.unifreiburg.informatik.tetris.game.Field f,
                          CartPt coords)
Checks if a move is possible.

Parameters:
f - the field.
coords - the offset
Returns:
if the move is possible.

isTurnableClockwise

public boolean isTurnableClockwise(de.unifreiburg.informatik.tetris.game.Field f,
                                   Block b)
Checks if it's allowed to rotate the block (this) by 90 degrees clockwise around b.

Parameters:
f - the field
b - the center of rotation
Returns:
if the rotation if allowed.

isTurnableCounterClockwise

public boolean isTurnableCounterClockwise(de.unifreiburg.informatik.tetris.game.Field f,
                                          Block b)
See isTurnableClockwise.

Parameters:
f -
b -
Returns:

turnCounterClockwise

public boolean turnCounterClockwise(de.unifreiburg.informatik.tetris.game.Field f,
                                    Block b)
See turnClockwise.

Parameters:
f -
b -
Returns:

turnClockwise

public boolean turnClockwise(de.unifreiburg.informatik.tetris.game.Field f,
                             Block b)
Turns the block (this) clockwise by 90 degree around the parameter b, if this is possible. If not, false is returned, and nothing is changed.

Parameters:
f - the field
b - the center of roation
Returns:
if the rotation was done.

getY

int getY()
This method is only allowed to use in the package

Returns:
the y coordinate of the block

moveDown

void moveDown(int y)
Moves the block y lines down without any check.

Parameters:
y - number of lines

unsavemove

public void unsavemove(CartPt that)
This method is used to move the turnpoints. Here we do not need checks, if the turnpoint is in the field, if other blocks are there, and so on.

Parameters:
that -