|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet
|
+--Maze4D
Program allowing player to navigate a four dimensional labyrinth. This program draws a board sized to what is specified in its parameters or in the default values if parameters are not given; it may therefore be larger or smaller than the applet window that it is put in.
This program is a Java re-implementation of a maze originally written by Jonathan Hayward in eighth grade, in Apple ][ BASIC, and re-implemented in C during undergraduate studies. It retains a classic style of graphics and the original algorithms and basic data structures, but adds a recursive solvability verifier, configurability in invocation that was impossible under previous implementations, and a point-and-click interface. The applet may be seen at http://JonathansCorner.com/etc/maze/; it was slashdotted within a week of going online.
This is presented as a code sample for:
Jonathan Hayward
jonathan.hayward@pobox.com
Dimensions are as follows:
Within squares: ^ Y| +-> X Between squares: ^ Z| +-> W
This is disanalogous, but gives the most obvious place to the fourth (spatial) dimension after the first three dimensions have been assigned their usual letters. Therefore, I am keeping it that way.
Thanks to my father, John Hayward, for help with an AWT bug, James Holt for a bugfix and additional code to address bug which manifested in larger mazes, and Darren Edmonds for pointers on how to update the MouseEvent handling.
| 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 | |
Maze4D()
|
|
| Method Summary | |
void |
drawBoard()
Draw the board on the screen. |
void |
init()
Initializations performed when the applet is created. |
void |
mouseClicked(java.awt.event.MouseEvent theEvent)
Process a mouse click to see if it is corresponds to a legal move, and, if so, make that move. |
void |
mouseEntered(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse cursor entering the component. |
void |
mouseExited(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse cursor exiting the component. |
void |
mousePressed(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse button being pressed. |
void |
mouseReleased(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse button being released. |
void |
paint(java.awt.Graphics g)
This method is called when the display is to be painted. |
void |
run()
Display a success message for two seconds before generating a new maze. |
void |
update(java.awt.Graphics g)
This applet method is called to update the contents of the screen. |
| Methods inherited from class java.applet.Applet |
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop |
| Methods inherited from class java.awt.Panel |
addNotify |
| 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, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, 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, 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, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Maze4D()
| Method Detail |
public void drawBoard()
Draw the board on the screen.
public void init()
Initializations performed when the applet is created.
init in class java.applet.Appletpublic void mouseClicked(java.awt.event.MouseEvent theEvent)
Process a mouse click to see if it is corresponds to a legal move, and, if so, make that move. A legal move is one that takes to a space adjacent to his present space in hyperspace (not necessarily on the board).
mouseClicked in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse cursor entering the component. At present, this does nothing.
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse cursor exiting the component. At present, this does nothing.
mouseExited in interface java.awt.event.MouseListenerpublic void mousePressed(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse button being pressed. At present, this does nothing.
mousePressed in interface java.awt.event.MouseListenerpublic void mouseReleased(java.awt.event.MouseEvent theEvent)
Respond appropriately to the mouse button being released. At present, this does nothing.
mouseReleased in interface java.awt.event.MouseListenerpublic void paint(java.awt.Graphics g)
This method is called when the display is to be painted.
paint in class java.awt.Containerpublic void run()
Display a success message for two seconds before generating a new maze. This is done in a separate thread because if it is done in the mouse event handler, the screen is not updated until the end of the two seconds, where it flashes, subliminal message style.
run in interface java.lang.Runnablepublic void update(java.awt.Graphics g)
This applet method is called to update the contents of the screen.
update in class java.awt.Container
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||