OOPI.tetris
Class TetrisFrame

java.lang.Object
  extended byOOPI.tetris.TetrisFrame
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener

public class TetrisFrame
extends java.lang.Object
implements java.awt.event.KeyListener

TetrisFrame - The utility class for creating a frame for displaying and managing a game of Tetris. This manages the main event loop and interaction. It calls an instance of TetrisLogic to help manage the game board, and to evaluate potential game positions for automated play.

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

Constructor Summary
TetrisFrame(java.lang.String title)
          Constructor for a tetris game.
 
Method Summary
 Cell[][] addPieceToBoard(Cell[][] board, Cell[][] piece, Position pos)
          Utility method to add the specified piece at a given position to a board.
 Cell[][] cloneBoard(Cell[][] board)
          Makes a clone (i.e., copy) of the specified board.
 javax.swing.JPanel getPanel()
          Get the GUI component that contains the tetris game.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void paintComponent(java.awt.Graphics g)
          This paints the actual game.
 void setTetrisLogic(TetrisLogic logic)
          Sets the logic to be used by this game of tetris.
 void show()
          Creates a top-level window to put the tetris game in.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TetrisFrame

public TetrisFrame(java.lang.String title)
Constructor for a tetris game.

Parameters:
title - The window title (which will be appended with the current score)
Method Detail

setTetrisLogic

public void setTetrisLogic(TetrisLogic logic)
Sets the logic to be used by this game of tetris. Once the logic has been set, the game will start.

Parameters:
logic - The new game logic

show

public void show()
Creates a top-level window to put the tetris game in.


getPanel

public javax.swing.JPanel getPanel()
Get the GUI component that contains the tetris game.

Returns:
the panel.

addPieceToBoard

public Cell[][] addPieceToBoard(Cell[][] board,
                                Cell[][] piece,
                                Position pos)
Utility method to add the specified piece at a given position to a board.

Parameters:
board - The board to add the piece to
piece - The piece to be added
pos - The position of the piece to be added
Returns:
The new board

cloneBoard

public Cell[][] cloneBoard(Cell[][] board)
Makes a clone (i.e., copy) of the specified board. It reuses the cells, but since they are immutable, this is a safe thing to do.

Parameters:
board - The board to make a copy of
Returns:
The duplicated board

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

paintComponent

public void paintComponent(java.awt.Graphics g)
This paints the actual game.