net.sourceforge.cilib.games.game.tetris
Class TetrisGameState

java.lang.Object
  extended by net.sourceforge.cilib.games.states.GameState
      extended by net.sourceforge.cilib.games.states.GridGameState
          extended by net.sourceforge.cilib.games.game.tetris.TetrisGameState
All Implemented Interfaces:
Serializable, Cloneable

public class TetrisGameState
extends GridGameState

This class represents a Tetris game state.

Author:
leo
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.cilib.games.states.GridGameState
state
 
Fields inherited from class net.sourceforge.cilib.games.states.GameState
currentIteration, randomizer
 
Constructor Summary
TetrisGameState()
           
TetrisGameState(TetrisGameState other)
           
 
Method Summary
 void calculateScore(int rowsCleared)
          Calculate the score based on the amount of rows cleared
 int clearFullRows()
          Clear any full rows in the current game grid.
static int clearFullRows(GameItem[][] state, int Width, int Height)
          Clear all full rows for a given game grid
 void clearState()
          Clear the state and reset it to a start state.
 boolean collides(AbstractShape shape)
          Check whether one of the blocks in the AbstractShape collides in the current grid
 boolean collides(List<TetrisBlock> blocks)
          Check whether one of the blocks in the list collides in the current grid
 void createNewShape()
          Create a new random Tetris shape at the top of the grid
 boolean currentShapeCollides()
          Check whether one of the blocks in the current shape of the game collides in the grid
 boolean FitShapeInGridTopDown()
          Fit the current shape in the current grid from its current position moving down untill it either collides or is at the bottowm of the grid
 TetrisGameState getClone()
          Create a cloned copy of the current object and return it.
 int getCurrentLevel()
           
 double getCurrentScore()
           
 AbstractShape getCurrentShape()
           
 double getCurrentSpeed()
           
 int getEmptyCellsBeforeOccupied(int x, int startY)
          Get the number of empty cells in the grid before an occupied one
 int getErodedShapeCount()
          Get the number of blocks form the current AbstractShape that will be removed if the shape was to be merged at its current position
 int getTotalRowsCleared()
           
 void mergeCurrentShape()
          Merge the current AbstractShape into the grid
 boolean moveRight()
          Move the current piece one position to the right if it doesn't collide there.
 void setCurrentShape(AbstractShape newShape)
           
 void setItem(int i, int j, GameItem item)
          Set an item at a specific index in the matrix
 boolean setShapeLeftGrid()
          Set the current AbstractShape as far to the left of the current grid as it can go
 
Methods inherited from class net.sourceforge.cilib.games.states.GridGameState
getGridHeight, getGridWidth, getItem, setGridHeight, setGridWidth
 
Methods inherited from class net.sourceforge.cilib.games.states.GameState
getCurrentIteration, getRandomizer, increaseIteration, resetIterationCount, setRandomizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TetrisGameState

public TetrisGameState()

TetrisGameState

public TetrisGameState(TetrisGameState other)
Method Detail

getClone

public TetrisGameState 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
Overrides:
getClone in class GridGameState
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

createNewShape

public void createNewShape()
Create a new random Tetris shape at the top of the grid


setItem

public void setItem(int i,
                    int j,
                    GameItem item)
Description copied from class: GridGameState
Set an item at a specific index in the matrix

Overrides:
setItem in class GridGameState
Parameters:
i - the specified Column
j - the specified Row
item - the item to set. This method does not check if an item already exists, and will simply override what is in that position.

mergeCurrentShape

public void mergeCurrentShape()
Merge the current AbstractShape into the grid


calculateScore

public void calculateScore(int rowsCleared)
Calculate the score based on the amount of rows cleared

Parameters:
rowsCleared -

getErodedShapeCount

public int getErodedShapeCount()
Get the number of blocks form the current AbstractShape that will be removed if the shape was to be merged at its current position

Returns:
the number of eroded blocks

getEmptyCellsBeforeOccupied

public int getEmptyCellsBeforeOccupied(int x,
                                       int startY)
Get the number of empty cells in the grid before an occupied one

Parameters:
x - the row to look in
startY - the column to start looking at
Returns:
the number of empty cells

clearFullRows

public static int clearFullRows(GameItem[][] state,
                                int Width,
                                int Height)
Clear all full rows for a given game grid

Parameters:
state - the grid of blocks
Width - the with of the grid
Height - the heigth of the grid
Returns:
the amount of rows cleared.

clearFullRows

public int clearFullRows()
Clear any full rows in the current game grid.

Returns:

setShapeLeftGrid

public boolean setShapeLeftGrid()
Set the current AbstractShape as far to the left of the current grid as it can go


FitShapeInGridTopDown

public boolean FitShapeInGridTopDown()
Fit the current shape in the current grid from its current position moving down untill it either collides or is at the bottowm of the grid

Returns:

moveRight

public boolean moveRight()
Move the current piece one position to the right if it doesn't collide there.

Returns:

currentShapeCollides

public boolean currentShapeCollides()
Check whether one of the blocks in the current shape of the game collides in the grid

Returns:
A boolean that indicates if a collision occurred

collides

public boolean collides(AbstractShape shape)
Check whether one of the blocks in the AbstractShape collides in the current grid

Parameters:
blocks - The given AbstractShape
Returns:
A boolean that indicates if a collision occurred

collides

public boolean collides(List<TetrisBlock> blocks)
Check whether one of the blocks in the list collides in the current grid

Parameters:
blocks - A list of TetrisBlocks
Returns:
A boolean that indicates if a collision occurred

clearState

public void clearState()
Clear the state and reset it to a start state.

Overrides:
clearState in class GridGameState

getCurrentLevel

public int getCurrentLevel()

getCurrentScore

public double getCurrentScore()

getCurrentShape

public AbstractShape getCurrentShape()

setCurrentShape

public void setCurrentShape(AbstractShape newShape)

getCurrentSpeed

public double getCurrentSpeed()

getTotalRowsCleared

public int getTotalRowsCleared()


Copyright © 2009 CIRG. All Rights Reserved.