|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
gui.RushHourPanel
public class RushHourPanel
This class implements the GUI handler for constructing and manipulating a visual Rush Hour game board. It is built in a manner that it ties directly into a Rush Hour game board object that allows vehicle manipulations through the specified methods. It is expected that errors will be caught and handled within the Rush Hour game board object and not within this GUI. If they are to be thrown to the GUI, they should be thrown as a known exception for that particular event that the GUI knows to catch and handle.
This interface allows the user to add, remove, and move vehicles by dragging. Once the red vehicle is over the exit arrow, the game board is flagged as solved.
There are three main modes: Edit mode, Play! mode, and Cheat mode.
Edit mode is when most buttons are unlocked and the user is allowed to build the board freely. Though the user can technically move the red vehicle into a winning position to win the game, this is not what this mode is intended for. When the user is done building the board, he or she should click Play!
Play! mode is when all board editing buttons are locked, the number of moves made is reset to zero, and the user is expected to attempt to solve the game board from the given state of the board. The user can click the Edit at any point to return to Edit mode, but this will cause the number of moves made to be inaccurate from that point on. The user can also click the Solve button to run the solveFast() algorithm.
Once the user has pressed teh Solve button, a solution is either found or the game board is flagged as unsolvable. If a solution is found, it is not shown to the user immedietly. Rather, the Solve button turns into the Cheat button and the user must click this before being walked through the solution.
In Cheat mode, the user can either click the Next button to be automatically walked through the solution, or he or she may click and drag the vehicle they are instructed to move the specified number of spaces in the given direction. In Cheat mode, all vehicles except the vehicle currently being instructed to move are locked. To exit Cheat mode, click the Stop button to return to normal board solving. However, once you have entered cheat mode, the cheated flag is set and, even upon solving the game board, the user will be known as a cheater.
When the Solve button is pressed, two methods can be used to solve it, though solveFast() is significantly more efficient. The Solve button can also call solve() to acheive the same result.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
javax.swing.JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected javax.swing.JButton |
addCarButton
|
protected javax.swing.JButton |
addTruckButton
|
protected gui.RushHourGameBoardPanel |
boardPanel
The graphic object that represents the game board. |
protected javax.swing.JComboBox |
colorComboBox
|
protected java.lang.String |
DEFAULT_STATUS
The default status message. |
protected java.lang.String |
DEFAULT_USER_SOLVING_STATUS
The default status during a game solve. |
protected RushHourGameBoard |
gameBoard
The object that represents the game board. |
protected RushHourGameBoard |
lastUnsolved
The object that can be reverted to that represents the unsolved board state at the last press of the Solve button. |
protected javax.swing.JComboBox |
orientationComboBox
|
protected javax.swing.JButton |
removeVehicleButton
|
protected javax.swing.JButton |
resetButton
|
protected javax.swing.JButton |
solveButton
|
protected RushHourGameBoard |
startUnsolved
The object that can be reverted to that represents the unsolved board state at the start of the game. |
protected javax.swing.JTextField |
statusTextField
|
protected boolean |
userSolving
True if the user is currently userSolving the board on their own. |
protected boolean |
waitForLoad
True if the application is waiting for a game to be loaded. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 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 | |
|---|---|
RushHourPanel(RushHourApplet applet)
Constructs the interface for the Rush Hour game, knowing the application is applet-based. |
|
RushHourPanel(RushHourFrame frame)
Constructs the interface for the Rush Hour game, knowing the application is stand-alone. |
|
| Method Summary | |
|---|---|
protected void |
defaultStates()
Sets the default states when nothing is being placed, nothing is being removed, and no forms of solving are going on. |
void |
mouseClicked(java.awt.event.MouseEvent e)
After Add Car, Add Truck, or Remove Vehicle is pressed, the interface waits for a mouse click within the game board to place (or remove) the vehicle. |
void |
mouseDragged(java.awt.event.MouseEvent e)
So long as a vehicle is not being added or removed and selectedVehicle (set on mousePressed) is not null, the selected vehicle will be dragged in the horizontal or vertical (depending on the orientation of the vehicle) direction of the vehicle as long as that drag is valid. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Unused, but overriden since it's abstract. |
void |
mouseExited(java.awt.event.MouseEvent e)
Unused, but overriden since it's abstract. |
void |
mouseMoved(java.awt.event.MouseEvent e)
If the mouse is moved within the boardPanel and a car is being added or removed, the mouse coordinates are retrieved and appropriate visual measures are taken. |
void |
mousePressed(java.awt.event.MouseEvent e)
When the mouse is clicked, the interface grabs the vehicle (if any) that is located at the cursor coordinates and sets it as the selectedVehicle. |
void |
mouseReleased(java.awt.event.MouseEvent e)
When the mouse click is released, the selected vhiecle (if any) is snapped to its new closest (and valid) location on the game board. |
protected void |
resetGameBoard()
Reset the game board object as well as the interface to their default states. |
protected void |
revertButtonTexts()
Revert button for the Reset and Solve buttons back to their default states, "Reset" and "Play!" |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final java.lang.String DEFAULT_STATUS
protected final java.lang.String DEFAULT_USER_SOLVING_STATUS
protected RushHourGameBoard startUnsolved
protected RushHourGameBoard lastUnsolved
protected RushHourGameBoard gameBoard
protected gui.RushHourGameBoardPanel boardPanel
protected boolean userSolving
protected boolean waitForLoad
protected javax.swing.JButton addCarButton
protected javax.swing.JButton addTruckButton
protected javax.swing.JComboBox colorComboBox
protected javax.swing.JComboBox orientationComboBox
protected javax.swing.JButton removeVehicleButton
protected javax.swing.JButton resetButton
protected javax.swing.JButton solveButton
protected javax.swing.JTextField statusTextField
| Constructor Detail |
|---|
public RushHourPanel(RushHourFrame frame)
public RushHourPanel(RushHourApplet applet)
| Method Detail |
|---|
protected void defaultStates()
protected void resetGameBoard()
protected void revertButtonTexts()
public void mouseClicked(java.awt.event.MouseEvent e)
If waitForLoad is set, a mouse click is immedietly ignored.
mouseClicked in interface java.awt.event.MouseListenere - The mouse click event.public void mousePressed(java.awt.event.MouseEvent e)
If waitForLoad is set, a mouse press is immedietly ignored.
mousePressed in interface java.awt.event.MouseListenere - The mouse press event.public void mouseReleased(java.awt.event.MouseEvent e)
If the new location snapped to differs from the old location of the vehicle prior to dragging, the number of moves made is incremented. However, if the same vehicle is moved twice in a row, it only counts as one move, so the number of moves made will not be incremented the second time.
If the vehicle moved was the red car and the location it was moved to is the winning position, the winning message is displayed the the game board is set as solved. Additionally, the Solve button text then changes to "Revert."
If waitForLoad is set, a mouse release is immedietly ignored.
mouseReleased in interface java.awt.event.MouseListenere - The mouse release event.public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered in interface java.awt.event.MouseListenere - The mouse entering area of backPanel event.public void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenere - The mouse exiting area of backPanel event.public void mouseMoved(java.awt.event.MouseEvent e)
If waitForLoad is set, a mouse movement is immedietly ignored.
mouseMoved in interface java.awt.event.MouseMotionListenere - The mouse moving event.public void mouseDragged(java.awt.event.MouseEvent e)
If waitForLoad is set, a mouse drag is immedietly ignored.
mouseDragged in interface java.awt.event.MouseMotionListenere - The mouse drag event.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||