OOPI.tetris
Class Tetris

java.lang.Object
  extended byOOPI.tetris.Tetris
All Implemented Interfaces:
TetrisLogic

public class Tetris
extends java.lang.Object
implements TetrisLogic

Tetris - This is the skeleton solution for the Tetris game. The four methods of TetrisLogic must all be implemented properly to play the manual and automatic versions of Tetris properly.

Author:
Ben Bederson Copyright (C) 2004 University of Maryland
See Also:
TetrisFrame, TetrisLogic, Cell, Position

Constructor Summary
Tetris()
           
 
Method Summary
 Cell[][] collapseRows(Cell[][] board)
          Returns a new board based on the specified board where all rows that are completely filled are collapsed with higher rows falling down to replace collapsed rows.
 double computeMoveQuality(Cell[][] board, Cell[][] piece, Position position, Cell[][] nextPiece)
          Computes a measure of quality for the specified piece and position where larger values are better.
 boolean isLegalPosition(Cell[][] board, Cell[][] piece, Position position)
          Determines if the specified piece is in a legal position.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tetris

public Tetris()
Method Detail

main

public static void main(java.lang.String[] args)

isLegalPosition

public boolean isLegalPosition(Cell[][] board,
                               Cell[][] piece,
                               Position position)
Description copied from interface: TetrisLogic
Determines if the specified piece is in a legal position. A position is legal if it is entirely on the board, and does not overlap any filled board cell. This method is used to make sure that rotated pieces end up in legal positions, to generate potential piece positions in automatic mode, and to detect if the game is over. The board and piece must not be modified.

Specified by:
isLegalPosition in interface TetrisLogic
Parameters:
board - The current game board state
piece - The new piece for which position legality is being computed
position - The position of the new piece
Returns:
True if the piece is in a legal position.

collapseRows

public Cell[][] collapseRows(Cell[][] board)
Description copied from interface: TetrisLogic
Returns a new board based on the specified board where all rows that are completely filled are collapsed with higher rows falling down to replace collapsed rows. This method is used to remove full rows. The input board must not be modified.

Specified by:
collapseRows in interface TetrisLogic
Parameters:
board - The current game board state
Returns:
The new board with appropriate rows collapsed

computeMoveQuality

public double computeMoveQuality(Cell[][] board,
                                 Cell[][] piece,
                                 Position position,
                                 Cell[][] nextPiece)
Description copied from interface: TetrisLogic
Computes a measure of quality for the specified piece and position where larger values are better. This is guaranteed to not be called unless the piece is in a legal position, as determined by isLegalPosition(). This method is used by the automatic mode to determine which is the best position for a new piece. The board and piece must not be modified.

Specified by:
computeMoveQuality in interface TetrisLogic
Parameters:
board - The current game board state
piece - The new piece for which position quality is being computed
position - The position of the new piece
nextPiece - The piece that will be used after this one.
Returns:
The quality of the new piece position (larger values are better)