Class Cell

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--Cell
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class Cell
extends Panel

A World is made up of a 2-dimensional grid of Cells. Each Cell is square in shape.

Author:
Phil Reakes after Ryan Heise
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.awt.Container
 
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
Cell(World world, int xpos, int ypos)
          Constructs a new Cell in the specified World.
 
Method Summary
 void addMarker()
          Adds a flag type marker to the Cell.
 void addMine()
          Adds a mine to the Cell.
 void cascade()
          Clear all adjacent cells if they are completely empty.
 void clear()
          Clears a non-mined Cell.
 void cycleMarker()
          Get a reference to the marker on this Cell.
 int getAdjacentMarkers()
          Gets the number of markers adjacent to the Cell.
 int getAdjacentMineNumbers()
          Gets the number of 'mine numbers' adjacent to the Cell.
 int getAdjacentMines()
          Gets the number of mines adjacent to the Cell.
 Marker getMarker()
          Get a reference to the marker on this Cell.
 Mine getMine()
          Get a reference to the mine on this Cell.
 Cell getNextCell(Direction direction)
          Gets the reference to a neighbouring Cell in the specified direction.
 Point getPosition()
          Gets the location of this Cell.
 Dimension getPreferredSize()
          This method lets the layout manager know what size this Cell would prefer to be.
 World getWorld()
          Get a reference to the World containing this Cell.
 boolean hasMarker()
          Reveals whether the Cell contains a marker or not.
 boolean hasMine()
          Reveals whether the Cell contains a mine or not.
 boolean isClear()
          Reveals whether the Cell is clear or not.
 void paintMineNumberColour()
          Paints a Cell's 'mine number colour' on that Cell.
 void removeMarker()
          Removes a marker from the Cell.
 void removeMine()
          Removes a mine from the Cell.
 String toString()
          Creates a String representation of this Cell.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cell

public Cell(World world,
            int xpos,
            int ypos)
Constructs a new Cell in the specified World.

Parameters:
world - the World this Cell will be a part of.
xpos - the x coordinate of the Cell.
ypos - the y coordinate of the Cell.
Method Detail

addMarker

public void addMarker()
Adds a flag type marker to the Cell.


addMine

public void addMine()
Adds a mine to the Cell.


cascade

public void cascade()
Clear all adjacent cells if they are completely empty. Beware -- contains recursion!


clear

public void clear()
Clears a non-mined Cell.


cycleMarker

public void cycleMarker()
Get a reference to the marker on this Cell.

Returns:
a reference to the marker on this Cell, or null if none present

getAdjacentMarkers

public int getAdjacentMarkers()
Gets the number of markers adjacent to the Cell.

Returns:
the number of markers adjacent to the Cell.

getAdjacentMineNumbers

public int getAdjacentMineNumbers()
Gets the number of 'mine numbers' adjacent to the Cell.

Returns:
the number of maine numbers adjacent to the Cell.

getAdjacentMines

public int getAdjacentMines()
Gets the number of mines adjacent to the Cell.

Returns:
the number of mines adjacent to the Cell.

getMarker

public Marker getMarker()
Get a reference to the marker on this Cell.

Returns:
a reference to the marker on this Cell, or null if none present

getMine

public Mine getMine()
Get a reference to the mine on this Cell.

Returns:
a reference to the mine on this Cell, or null if none present

getNextCell

public Cell getNextCell(Direction direction)
Gets the reference to a neighbouring Cell in the specified direction.

Parameters:
direction - the direction in which to grab the neighboring Cell. The Direction will be automatically rounded to the nearest Cell.
Returns:
the neighbouring Cell in the specified direction.

getPosition

public Point getPosition()
Gets the location of this Cell.

Returns:
the location of this Cell.

getPreferredSize

public Dimension getPreferredSize()
This method lets the layout manager know what size this Cell would prefer to be.

Overrides:
getPreferredSize in class Container
Returns:
the preferred size.

getWorld

public World getWorld()
Get a reference to the World containing this Cell.

Returns:
a reference to the world containing this Cell

hasMarker

public boolean hasMarker()
Reveals whether the Cell contains a marker or not.

Returns:
true if a marker is present, false otherwise

hasMine

public boolean hasMine()
Reveals whether the Cell contains a mine or not.

Returns:
true if a mine is present, false otherwise

isClear

public boolean isClear()
Reveals whether the Cell is clear or not.

Returns:
true if a cell is clear, false otherwise

paintMineNumberColour

public void paintMineNumberColour()
Paints a Cell's 'mine number colour' on that Cell. The 'mine number colour' differs depending on the the number of mines adjacent to the Cell. As a mnemonic it follows the colour spectrum from lowest wavelength to highest.

Key to 'mine colours':

Orange - 1 mine adjacent. Yellow - 2 mines adjacent. Green - 3 mines adjacent. Cyan - 4 mines adjacent. Blue - 5 mines adjacent. Magenta - 6 mines adjacent. Dark Grey - 7 mines adjacent. Black - 8 mines adjacent.


removeMarker

public void removeMarker()
Removes a marker from the Cell.


removeMine

public void removeMine()
Removes a mine from the Cell.


toString

public String toString()
Creates a String representation of this Cell. This is useful for debugging purposes.

Overrides:
toString in class Component
Returns:
a String representation of this Cell.


Generated by BlueJ