com.jeffpalm.eggtris
Class Board

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by com.jeffpalm.eggtris.Board
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class Board
extends java.awt.Canvas

This public class is the surface on which an Eggtris game is played. The use it you must do the following:

(1) Construct one (see below)

(2) Set an active Shape

(3) Check for lines and when some are found do what you want

(4) If a Shape cannot move down, tell it to giveItsBricksTo this Board

(5) repeat......

Since:
10.23.1998
Author:
Jeffrey Palm
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Board(int x, int y, int width, int height, int brickSize)
          Instatiates a new Board from the given parameters.
 
Method Summary
 int checkForLines()
          Checks for any lines across the board, starting at the top, and returns the number of lines found.
 void clearRow(int row)
          CHANGE TO PROTECTED
 void dropRows(int bottomMostRow, int numberOfRows)
          CHANGE TO PROTECTED
 boolean hasAnEmptySpotIn(int x, int y)
          This is used by Brick to see if it can move to this spot
 void paint(java.awt.Graphics g)
          Paints the Graphics context passed in by first painting the back-drop (at the moment, that is just a colored background.
 void putBrick(Brick brick, int x, int y)
          This is used by Shape (or Brick, I'll come back) to put one of its Bricks on the Board.
 void setActiveShape(MyShape newActiveShape)
          VERY IMPORTANT!!!!!!!!
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Board

public Board(int x,
             int y,
             int width,
             int height,
             int brickSize)
Instatiates a new Board from the given parameters.

Parameters:
width - Number of bricks across.
height - Number of bricks tall.
brickSize - The size of the bricks that are created. This is needed by both Brick and Shape.
x - X position.
y - Y position.
Method Detail

paint

public void paint(java.awt.Graphics g)
Paints the Graphics context passed in by first painting the back-drop (at the moment, that is just a colored background. Then is paints all the locked bricks, and then the activeShape.

Overrides:
paint in class java.awt.Canvas
Parameters:
g - Graphics context on which to paint.

hasAnEmptySpotIn

public boolean hasAnEmptySpotIn(int x,
                                int y)
This is used by Brick to see if it can move to this spot

Parameters:
x - The possible s spot.
y - The possible y spot.
Returns:
True if this spot is not occupied (null) or not off the Board.

putBrick

public void putBrick(Brick brick,
                     int x,
                     int y)
This is used by Shape (or Brick, I'll come back) to put one of its Bricks on the Board. This is done when it cannot go any further.

Parameters:
brick - Brick to put on.
x - Array spot x in which to put it.
y - Array spot y in which to put it.

setActiveShape

public void setActiveShape(MyShape newActiveShape)
VERY IMPORTANT!!!!!!!!

This MUST be called by the Applet (or whatever the controller is) after a Shape is set. After the Shape giveItsBricks to this, the Applet must call this method so the board can treat the new Shape specially.

Parameters:
newActiveShape - Shape which becomes the new active Shape.
See Also:
#eggtris.Shape

clearRow

public void clearRow(int row)
CHANGE TO PROTECTED

Nullifies the row passed in, if it is within the range of rows.

Called by checkForLines.

Parameters:
row - Row to clear.
See Also:
#eggtris.Board.checkForLines()

dropRows

public void dropRows(int bottomMostRow,
                     int numberOfRows)
CHANGE TO PROTECTED

Drops all the rows by numberofRows, starting at bottomMostRow.

Parameters:
bottomMostRow - The furthest row down from which to start the drop.
numberOfRows - Number of rows to drop.
See Also:
#eggtris.Board.checkForLines()

checkForLines

public int checkForLines()
Checks for any lines across the board, starting at the top, and returns the number of lines found. Ths method takes care of clearing the found lines and dropping the remianing lines. DO NOT call dropRows() or clearRow() from an outside class.

Returns:
The number of lines found.