|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JLayeredPane
|
+--au.com.solidsoftware.multimahjong.mmc.usergui.PlayArea
A panel that contains the graphical representation of the current state of the Wall, the last discard, as well as the declared sets, concealed tiles and drawn tile for each of the four players. In addition, the wind, icon and name of each player will be displayed. A graphic will also be displayed next to the player's icon if the player is fishing for Mahjong. A wind-of-the-round indicator will be displayed next to the player who is East at the very start of the game.
The wall in the centre of the PlayArea will serve to inform
the user of how far the game has progressed by showing a graphical
representation of the current state of the Wall. When dealing out the tiles
at the start each hand, the players may draw from the front of the wall
either four, two or one tile(s). However, during actual game play, the user
may draw only one tile from either the front or back of the wall.
The last discard (the most recently discarded tile) is also displayed on the inner side of the Wall. This must be updated whenever a player discards a tile and cleared whenever a player picks up the discard and incorporates it into a declared set.

The user is seated at the bottom edge of the PlayArea. This
portion of the screen will contain the user's declared sets, concealed
tiles and drawn tile. When it is the user's turn to discard, they may
click on a concealed tile or the drawn tile, selecting the tile. The
user may not select tiles that have already been declared. Once a tile
has been selected, the user can then perform additional game actions
such as "Discard" and "Reveal Kong" in the ActionPane. The
user's wind, icon and name is displayed on the upper-right of the user's
concealed hand.

Each of the other three players will be seated along the left, top and right edges of the screen. Each player's declared sets will be visible. However, only the backs of their concealed tiles and drawn tile may be seen. Selecting tiles in another player's hand is not permitted.

| Inner Class Summary | |
private class |
PlayArea.WallTile
An inner class used primarily for storing the x- and y-coordinate of a wall tile, relative to the top-left corner of the PlayArea. |
| Inner classes inherited from class javax.swing.JLayeredPane |
javax.swing.JLayeredPane.AccessibleJLayeredPane |
| Inner classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent,
javax.swing.JComponent.IntVector,
javax.swing.JComponent.KeyboardBinding,
javax.swing.JComponent.KeyboardState |
| Inner classes inherited from class java.awt.Component |
java.awt.Component.AWTTreeLock |
| Field Summary | |
private java.awt.image.BufferedImage[] |
concealedImages
Images of the entire set of concealed tiles for each of the four players. |
private java.awt.image.BufferedImage[] |
declaredImages
Images of the entire set of declared tiles for each of the four players. |
private java.awt.Image |
discardImage
Image of the last discard. |
private java.awt.Image[] |
fishImages
Images of the fishing indicator of each of the four players. |
private static double |
H_GAP
A horizontal gap (between icons and their labels, between concealed tiles and drawn tile, etc.). |
private int |
hostID
The array index that refers to the host's entry in players
array. |
private static double |
ICON_H
The height of an icon image in pixels. |
private static double |
ICON_W
The width of an icon image in pixels. |
private java.awt.Image[] |
iconImages
Images of the icons of each of the four players. |
private int |
loosePos
The array index in wallTiles that refers to the next loose
tile in the wall to be picked up. |
private java.lang.String[] |
names
The names of each of the four players. |
private java.awt.Image[] |
roundWindImages
Images of the round wind indicator of each of the four players. |
private boolean |
selectionEnabled
Whether the user is permitted to select tiles from their concealed hand by clicking on the tiles within it. |
private Tile[] |
userConcealed
The user's concealed hand. |
private java.awt.image.BufferedImage |
userConcealedImage
Image of the user's concealed hand. |
private UserGUI |
userGUI
A reference to the parent UserGUI object. |
private int |
userID
The array index that refers to the user's entry in players
array. |
private static double |
V_GAP
A vertical gap (between declared sets and concealed tiles, between concealed tiles and icons, etc.). |
private static int |
WALL_SIZE
The number of tiles in the complete wall. |
private int |
wallPos
The array index in wallTiles that refers to the next tile
in the wall to be picked up. |
private static int |
WALLTILE_H
The height of a wall tile image in pixels. |
private static int |
WALLTILE_W
The width of a wall tile image in pixels. |
private PlayArea.WallTile[] |
wallTiles
An array containing the tiles in the wall. |
private java.awt.Image[] |
windImages
Images of the wind discs of each of the four players. |
| Fields inherited from class javax.swing.JLayeredPane |
componentToLayer,
DEFAULT_LAYER,
DRAG_LAYER,
FRAME_CONTENT_LAYER,
LAYER_PROPERTY,
MODAL_LAYER,
optimizedDrawingPossible,
PALETTE_LAYER,
POPUP_LAYER |
| Fields inherited from class javax.swing.JComponent |
_bounds,
accessibleContext,
alignmentX,
alignmentY,
ANCESTOR_USING_BUFFER,
ancestorNotifier,
autoscroller,
border,
changeSupport,
clientProperties,
flags,
HAS_FOCUS,
IS_DOUBLE_BUFFERED,
IS_OPAQUE,
IS_PAINTING_TILE,
KEYBOARD_BINDINGS_KEY,
listenerList,
maximumSize,
minimumSize,
NEXT_FOCUS,
paintImmediatelyClip,
preferredSize,
readObjectCallbacks,
REQUEST_FOCUS_DISABLED,
tmpRect,
TOOL_TIP_TEXT_KEY,
ui,
uiClassID,
UNDEFINED_CONDITION,
vetoableChangeSupport,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
WHEN_FOCUSED,
WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Container |
component,
containerListener,
containerSerializedDataVersion,
dispatcher,
layoutMgr,
maxSize,
ncomponents,
serialVersionUID |
| Fields inherited from class java.awt.Component |
actionListenerK,
adjustmentListenerK,
appContext,
assert,
background,
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
changeSupport,
componentListener,
componentListenerK,
componentOrientation,
componentSerializedDataVersion,
containerListenerK,
cursor,
dropTarget,
enabled,
eventMask,
focusListener,
focusListenerK,
font,
foreground,
hasFocus,
height,
incRate,
inputMethodListener,
inputMethodListenerK,
isInc,
isPacked,
itemListenerK,
keyListener,
keyListenerK,
LEFT_ALIGNMENT,
locale,
LOCK,
minSize,
mouseListener,
mouseListenerK,
mouseMotionListener,
mouseMotionListenerK,
name,
nameExplicitlySet,
newEventsOnly,
ownedWindowK,
parent,
peer,
peerFont,
popups,
prefSize,
RIGHT_ALIGNMENT,
serialVersionUID,
textListenerK,
TOP_ALIGNMENT,
valid,
visible,
width,
windowListenerK,
x,
y |
| Constructor Summary | |
PlayArea(UserGUI userGUI,
Player[] players,
int userID)
Creates an instance of PlayArea showing the wind, icon and
name of each of the players in the game. |
|
| Method Summary | |
private void |
autoSelect()
Signals to the player that the game is now ready to accept a discard by pre-selecting the right-most tile for the user to discard. |
private void |
highlightSelected(int tileID)
Highlights the specified tile in the user's concealed hand to inform the user that a tile has been selected. |
void |
initWall()
Initialises the graphical representation of the Wall by building a new, complete wall, and randomly generates a break position. |
static void |
main(java.lang.String[] args)
Driver code used only for unit testing. |
void |
mouseClicked(java.awt.event.MouseEvent e)
This function is invoked whenever the user clicks a mouse button while the cursor is in the PlayArea. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Empty function body required to implement MouseListener. |
void |
mouseExited(java.awt.event.MouseEvent e)
Empty function body required to implement MouseListener. |
void |
mousePressed(java.awt.event.MouseEvent e)
Empty function body required to implement MouseListener. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Empty function body required to implement MouseListener. |
void |
paint(java.awt.Graphics g)
Paints the contents of the entire PlayArea to the
screen. |
void |
pickUpLoose()
Updates the graphical representation of the wall, showing that a single tile has been picked up from the back of the wall. |
void |
pickUpTile()
Updates the graphical representation of the wall, showing that a single tile has been picked up from the front of the wall. |
void |
setFishing(boolean isFishing,
int playerID)
Shows/hides the fishing graphic for the specified player. |
void |
tileSelection(boolean selectionEnabled)
Sets whether the user is permitted to select tiles from their concealed hand by clicking on the tiles within it. |
void |
updateConcealed(Tile[] tiles,
boolean drawn,
int playerID)
Updates the concealed tiles for the player seated in position. |
void |
updateDeclared(Set[] sets,
int playerID)
Updates the declared sets for the player seated in position. |
void |
updateDiscard(Tile tile)
Updates the most recently discarded tile displayed on the inner side of the Wall. |
void |
updateRoundWind(int wind)
Update the round wind indicated associated with the host of the game (that is, the playerID of the player whose wind was initially East). |
void |
updateWind(int wind,
int playerID)
Update the wind disc graphic for the specified player. |
private int |
wallDecrement(int position)
Decrements a wall position in a "wrap-around" manner. |
private int |
wallIncrement(int position)
Increments a wall position in a "wrap-around" manner. |
| Methods inherited from class javax.swing.JLayeredPane |
|
| Methods inherited from class javax.swing.JComponent |
_paintImmediately,
addAncestorListener,
addNotify,
addPropertyChangeListener,
addVetoableChangeListener,
adjustPaintFlags,
alwaysOnTop,
bindingForKeyStroke,
computeVisibleRect,
computeVisibleRect,
contains,
createToolTip,
enableSerialization,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
firePropertyChange,
fireVetoableChange,
getActionForKeyStroke,
getAlignmentX,
getAlignmentY,
getAutoscrolls,
getBorder,
getBounds,
getClientProperties,
getClientProperty,
getComponentGraphics,
getConditionForKeyStroke,
getDebugGraphicsOptions,
getFlag,
getGraphics,
getHeight,
getInsets,
getInsets,
getLocation,
getMaximumSize,
getMinimumSize,
getNextFocusableComponent,
getPreferredSize,
getRegisteredKeyStrokes,
getRootPane,
getSize,
getToolTipLocation,
getToolTipText,
getToolTipText,
getTopLevelAncestor,
getUIClassID,
getVisibleRect,
getWidth,
getX,
getY,
grabFocus,
hasFocus,
isDoubleBuffered,
isFocusCycleRoot,
isFocusTraversable,
isLightweightComponent,
isManagingFocus,
isOpaque,
isPaintingTile,
isRequestFocusEnabled,
isValidateRoot,
keyboardBindings,
paintBorder,
paintChildren,
paintComponent,
paintImmediately,
paintImmediately,
paintWithBuffer,
processComponentKeyEvent,
processFocusEvent,
processKeyBinding,
processKeyBindings,
processKeyBindingsForAllComponents,
processKeyEvent,
processMouseMotionEvent,
putClientProperty,
readObject,
rectangleIsObscured,
registerKeyboardAction,
registerKeyboardAction,
registerWithKeyboardManager,
removeAncestorListener,
removeNotify,
removePropertyChangeListener,
removeVetoableChangeListener,
repaint,
repaint,
requestDefaultFocus,
requestFocus,
resetKeyboardActions,
reshape,
revalidate,
scrollRectToVisible,
setAlignmentX,
setAlignmentY,
setAutoscrolls,
setBackground,
setBorder,
setDebugGraphicsOptions,
setDoubleBuffered,
setEnabled,
setFlag,
setFont,
setForeground,
setMaximumSize,
setMinimumSize,
setNextFocusableComponent,
setOpaque,
setPreferredSize,
setRequestFocusEnabled,
setToolTipText,
setUI,
setVisible,
shouldDebugGraphics,
superProcessMouseMotionEvent,
unregisterKeyboardAction,
unregisterWithKeyboardManager,
update,
updateUI,
writeObject |
| Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
applyOrientation,
countComponents,
deliverEvent,
dispatchEventImpl,
dispatchEventToSelf,
doLayout,
eventEnabled,
findComponentAt,
findComponentAt,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents_NoClientCode,
getComponents,
getLayout,
getMouseEventTarget,
getWindow,
initIDs,
insets,
invalidate,
invalidateTree,
isAncestorOf,
layout,
lightweightPrint,
list,
list,
locate,
minimumSize,
nextFocus,
paintComponents,
postProcessKeyEvent,
postsOldMouseEvents,
preferredSize,
preProcessKeyEvent,
print,
printComponents,
printOneComponent,
processContainerEvent,
processEvent,
proxyEnableEvents,
proxyRequestFocus,
remove,
removeAll,
removeContainerListener,
setFocusOwner,
setLayout,
transferFocus,
validate,
validateTree |
| Methods inherited from class java.awt.Component |
action,
add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addPropertyChangeListener,
areInputMethodsEnabled,
bounds,
checkImage,
checkImage,
coalesceEvents,
constructComponentName,
contains,
createImage,
createImage,
disable,
disableEvents,
dispatchEvent,
enable,
enable,
enableEvents,
enableInputMethods,
getBackground,
getBounds,
getColorModel,
getComponentOrientation,
getCursor,
getDropTarget,
getFont_NoClientCode,
getFont,
getFontMetrics,
getForeground,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocationOnScreen,
getName,
getNativeContainer,
getParent_NoClientCode,
getParent,
getPeer,
getSize,
getToolkit,
getToolkitImpl,
getTreeLock,
getWindowForObject,
gotFocus,
handleEvent,
hide,
imageUpdate,
inside,
isDisplayable,
isEnabled,
isEnabledImpl,
isLightweight,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
list,
list,
list,
location,
lostFocus,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paintAll,
postEvent,
prepareImage,
prepareImage,
printAll,
processComponentEvent,
processInputMethodEvent,
processMouseEvent,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
resize,
resize,
setBounds,
setBounds,
setComponentOrientation,
setCursor,
setDropTarget,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setSize,
show,
show,
size,
toString,
transferFocus |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
wait,
wait,
wait |
| Field Detail |
private static final double ICON_W
private static final double ICON_H
private static final int WALLTILE_W
private static final int WALLTILE_H
private static final double H_GAP
private static final double V_GAP
private UserGUI userGUI
UserGUI object.private int hostID
players
array. Since there are a maximum of four players in a game of Mahjong,
this value is in the range [0,3]. The initial value of -1 serves as a
sentinel to indicate that the hostID has not been set previously.private int userID
players
array. Since there are a maximum of four players in a game of Mahjong,
this value is in the range [0,3].private Tile[] userConcealed
updateConcealed method and used by the
mouseClicked method to set the selected tile in the
ActionPane.private java.awt.image.BufferedImage userConcealedImage
setSelected method to restore the original appearance of
the user's concealed hand (before highlighting the selected tile).private boolean selectionEnabled
private java.lang.String[] names
private java.awt.Image[] iconImages
private java.awt.Image[] windImages
private java.awt.Image[] fishImages
private java.awt.Image[] roundWindImages
private java.awt.image.BufferedImage[] declaredImages
private java.awt.image.BufferedImage[] concealedImages
private static final int WALL_SIZE
private PlayArea.WallTile[] wallTiles
private int wallPos
wallTiles that refers to the next tile
in the wall to be picked up.private int loosePos
wallTiles that refers to the next loose
tile in the wall to be picked up.private java.awt.Image discardImage
| Constructor Detail |
public PlayArea(UserGUI userGUI,
Player[] players,
int userID)
PlayArea showing the wind, icon and
name of each of the players in the game. The wind-of-the-round indicator
will also be displayed next to the player who is East at the start of
the game. All other elements, that is, the Wall, the last discard, and
the declared sets, concealed tiles and drawn tile for each of the
players are not visible.userGUI - A reference to the parent UserGUI object.players - An array which stores information specific for each of
the players. In this method, we are interested only in
extracting the players' icons and names.userID - The array index that refers to the user's entry in
players array. Since there are a maximum of
four players in a game of Mahjong, this value is in the
range [0,3].| Method Detail |
public void updateWind(int wind,
int playerID)
wind - The wind of the specified player. This is distinct from
the "round wind".playerID - The array index that refers to the player's entry in
players array. Since there are a maximum
of four players in a game of Mahjong, this value is in
the range [0,3].public void updateRoundWind(int wind)
wind - The round wind. This is distinct from the wind
associated with each player.
public void setFishing(boolean isFishing,
int playerID)
isFishing - A flag indicating whether a player is fishing for
Mahjong. The fishing graphic is displayed if this flag
is set to true.playerID - The array index that refers to the player's entry in
players array. Since there are a maximum
of four players in a game of Mahjong, this value is in
the range [0,3].
public void updateDeclared(Set[] sets,
int playerID)
position.sets - The sets that have been declared by the player. If this
is null, the player's declared sets are
cleared from the display.playerID - The array index that refers to the player's entry in
players array. Since there are a maximum
of four players in a game of Mahjong, this value is in
the range [0,3].
public void updateConcealed(Tile[] tiles,
boolean drawn,
int playerID)
position.tiles - The tiles in the players concealed hand. If this is
null, all of the player's concealed tiles
are cleared from the display.drawn - Whether the last concealed tile is a drawn tile.playerID - The array index that refers to the player's entry in
players array. Since there are a maximum
of four players in a game of Mahjong, this value is in
the range [0,3].public void updateDiscard(Tile tile)
tile - The most recently discarded tile. If this is
null, last discard is cleared from the
display.public void initWall()
WallTile.public void pickUpTile()
public void pickUpLoose()
private int wallIncrement(int position)
position - The array index that refers to a wall tile in the
wallTiles array. Since there are a maximum
of 136 tiles in a game of Mahjong, this value is in
the range [0,135].private int wallDecrement(int position)
position - The array index that refers to a wall tile in the
wallTiles array. Since there are a maximum
of 136 tiles in a game of Mahjong, this value is in
the range [0,135].public void paint(java.awt.Graphics g)
PlayArea to the
screen.private void autoSelect()
private void highlightSelected(int tileID)
tileID - The position of the tile (the leftmost tile being 0) to
highlight in the user's concealed hand. If this is a negative number,
the original concealed hand image is restored, removing any existing
highlights.public void tileSelection(boolean selectionEnabled)
selectionEnabled - if true, then the user is permitted to select
tiles from their concealed hand.public void mouseClicked(java.awt.event.MouseEvent e)
PlayArea. If they click on a tile in
their concealed hand, the tile will become highlighted. The selected
tile is also set in the ActionPane. Otherwise, any existing
highlighting is removed and the selected tile in the
ActionPane is set to null.e - A mouse action that occurred in the component.public void mouseEntered(java.awt.event.MouseEvent e)
MouseListener.public void mouseExited(java.awt.event.MouseEvent e)
MouseListener.public void mousePressed(java.awt.event.MouseEvent e)
MouseListener.public void mouseReleased(java.awt.event.MouseEvent e)
MouseListener.public static void main(java.lang.String[] args)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||