net.sourceforge.cilib.games.game.tetris.shape
Class AbstractShape

java.lang.Object
  extended by net.sourceforge.cilib.games.game.tetris.shape.AbstractShape
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
BoxShape, LineShape, LShape, RLShape, RZigZagShape, TShape, ZigZagShape

public abstract class AbstractShape
extends Object
implements Cloneable

This class represents a Shape in tetris.

Author:
leo
See Also:
Serialized Form

Constructor Summary
AbstractShape()
           
AbstractShape(AbstractShape other)
          
 
Method Summary
 int countCellsInRow(int y)
          Count all the Blocks that are in the given row
 TetrisBlock getBlock(int x, int y)
           
 List<TetrisBlock> getBlocks()
          Get a list of all the TetrisBlocks for this shape
 List<TetrisBlock> getBottomBlocks()
           
 TetrisBlock getBottomMostBlock()
          Get the bottom most block in this shape
 TetrisBlock getBottomMostBlock(int x)
          Return the lowest block in a specific column
abstract  AbstractShape getClone()
          Create a cloned copy of the current object and return it.
 int getCurrentOrientation()
           
 List<TetrisBlock> getLeftBlocks()
           
 TetrisBlock getLeftMostBlock()
          Get the left most block in this shape
 TetrisBlock getLeftMostBlock(int y)
          Get the left most block in this shape for the given row
 TetrisBlock getRightMostBlock()
          Get the right most block in this shape
 TetrisBlock getStaticBlock()
          Each shape has one block that never changes position when it rotates.
 TetrisBlock getTopMostBlock()
          Get the top most block in this shape
 boolean isInCell(int x, int y)
          Check if there are any Blocks in the specified cell
protected  void moveBlock(TetrisBlock block, int amX, int amY)
          Move a specific block in this shape
 void moveShapeX(int amX)
          Move the shape on the X axes
 void moveShapeY(int amY)
          Move the shape on the Y axes
abstract  void rotate()
          Rotate the shape to its next possible orientation
 boolean rotate(int AmRotations)
          Rotate this shape for the specified amount of times
 void setShapeTopGrid()
          Set this shape at the top of the grid
 boolean update(double currentSpeed, GridGameState state)
          attempt to move each block in shape down if collides before successfull move dont change pos and return false if moves but lands on bottom or above other block return false else return true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractShape

public AbstractShape()

AbstractShape

public AbstractShape(AbstractShape other)

Method Detail

update

public boolean update(double currentSpeed,
                      GridGameState state)
attempt to move each block in shape down if collides before successfull move dont change pos and return false if moves but lands on bottom or above other block return false else return true

Parameters:
currentSpeed -
state -
Returns:

getClone

public abstract AbstractShape getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

rotate

public abstract void rotate()
Rotate the shape to its next possible orientation


rotate

public boolean rotate(int AmRotations)
Rotate this shape for the specified amount of times

Parameters:
AmRotations - the amount of Rotations to do
Returns:
Wheather or not the rotation was successfull

moveBlock

protected void moveBlock(TetrisBlock block,
                         int amX,
                         int amY)
Move a specific block in this shape

Parameters:
Block - the block to move
amX - The amount to move on the X axes
amY - The amount to move on the Y axes

moveShapeX

public void moveShapeX(int amX)
Move the shape on the X axes

Parameters:
amX - The amount to move on the X axes

moveShapeY

public void moveShapeY(int amY)
Move the shape on the Y axes

Parameters:
amY - The amount ot move on the Y axes

getBlocks

public List<TetrisBlock> getBlocks()
Get a list of all the TetrisBlocks for this shape

Returns:
the list

getStaticBlock

public TetrisBlock getStaticBlock()
Each shape has one block that never changes position when it rotates. This function returns that block

Returns:
The block that never rotates

getLeftMostBlock

public TetrisBlock getLeftMostBlock()
Get the left most block in this shape


getLeftMostBlock

public TetrisBlock getLeftMostBlock(int y)
Get the left most block in this shape for the given row

Parameters:
y - The specified row to look at

getLeftBlocks

public List<TetrisBlock> getLeftBlocks()
Returns:
A shape that only consists of the left most blocks for each row the current shape occupies.

getRightMostBlock

public TetrisBlock getRightMostBlock()
Get the right most block in this shape


getBottomMostBlock

public TetrisBlock getBottomMostBlock()
Get the bottom most block in this shape


getBottomMostBlock

public TetrisBlock getBottomMostBlock(int x)
Return the lowest block in a specific column

Parameters:
x - The given column to search in
Returns:
The lowest block in that column

getBottomBlocks

public List<TetrisBlock> getBottomBlocks()
Returns:
A shape that only consists of the lowest blocks for each column the current shape occupies.

getTopMostBlock

public TetrisBlock getTopMostBlock()
Get the top most block in this shape


setShapeTopGrid

public void setShapeTopGrid()
Set this shape at the top of the grid


countCellsInRow

public int countCellsInRow(int y)
Count all the Blocks that are in the given row

Parameters:
y - the given row
Returns:
the number of hits

isInCell

public boolean isInCell(int x,
                        int y)
Check if there are any Blocks in the specified cell

Parameters:
x - the X coord
y - the Y coord
Returns:
wheather or not any Blocks are in that Cell

getBlock

public TetrisBlock getBlock(int x,
                            int y)

getCurrentOrientation

public int getCurrentOrientation()


Copyright © 2009 CIRG. All Rights Reserved.