gecco.client
Class Game

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--gecco.client.Game
All Implemented Interfaces:
Accessible, Animator, Client, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

public class Game
extends JFrame
implements Client, Animator

This is the main game class. It contains the complete client for an arbitrary game.

Author:
Andreas Enblom
See Also:
Serialized Form

Inner Class Summary
(package private)  class Game.ActionMenuItem
          A menu item of the action menu.
 
Inner classes inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Inner classes inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Inner classes inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.AWTTreeLock
 
Field Summary
(package private)  Hashtable actionExecutingPieces
          The pieces that are currenlty executing some actions.
(package private)  Hashtable actionIds
          The action id of the currenlty executing action for some piece.
(package private)  JPopupMenu actionMenu
          The menu that is displayed with piece actions, ghost pieces or ghost actions.
(package private)  ActionListener actionMenuListener
          The listener that handles selections in the menu that displays the actions of a piece.
(package private)  Board board
          Description of the Field
(package private)  MouseListener boardClicks
          The listener that handles clicks on the board.
(package private)  MouseMotionListener boardDrags
          The listener that handles drags on the board.
(package private)  String gameTitle
          The title of the game, shown as title in window.
(package private)  JPopupMenu ghostActionMenu
          The menu that contains the actions of a ghost piece (so far only remove.
(package private)  Point ghostMenuClick
          The point that was clicked on the board to bring up the ghost menu.
(package private)  int lastExtraPieceId
          The handle of the ghost or explosion that was added last.
(package private)  HostPort lastHost
          Description of the Field
(package private)  Map map
          Description of the Field
(package private)  PieceInfoPanel pieceInfoPanel
          Description of the Field
(package private)  TreeMap pieces
          The pieces that are currenlty in the game, hashed on piece handle.
(package private)  Action selectedAction
          Description of the Field
(package private)  Piece selectedPiece
          Description of the Field
(package private)  Server server
          Description of the Field
(package private)  boolean useGhosts
          All things that has to do with ghost pieces are turned on or off by this flag.
 
Fields inherited from class javax.swing.JFrame
accessibleContext, defaultCloseOperation, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
base, CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, frameSerializedDataVersion, HAND_CURSOR, icon, ICONIFIED, mbManagement, menuBar, MOVE_CURSOR, N_RESIZE_CURSOR, nameCounter, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, ownedWindows, resizable, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, serialVersionUID, state, SW_RESIZE_CURSOR, TEXT_CURSOR, title, W_RESIZE_CURSOR, WAIT_CURSOR, weakThis
 
Fields inherited from class java.awt.Window
active, dbg, focusMgr, inputContext, inputContextLock, OPENED, ownedWindowList, warningString, windowListener, windowSerializedDataVersion
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Game(String gameTitle)
          Constructor for the Game object
 
Method Summary
 void abortExecutingAction(Piece p)
          Aborts the currently executing action of the given piece.
 void abortExecutingAction(Piece p, boolean abortAll)
          Aborts the currently executing action of the given piece.
 void actionReply(long id, boolean ok, String message)
          Description of the Method
(package private)  Piece addGhostPiece(Position pos, String type)
          Adds a ghost piece with the specified properties.
 void addPiece(int handle, String name, Position pos, Enumeration actions, Enumeration properties, String type)
          Adds the specified piece, as described in Client.java.
 void addPieceAction(int handle, Action a)
          Adds a feature to the PieceAction attribute of the Game object
 void animationDone(AnimatedPiece p)
          Description of the Method
 void connectionLost()
          Description of the Method
(package private)  void connectToGame()
          Description of the Method
(package private)  JPopupMenu createActionMenu(Piece p)
          Creates the menu that displays the actions of a piece.
 void destroyPiece(int handle)
          Description of the Method
(package private)  void destroyPiece(int handle, boolean animateExplosion)
          Removes the piece with the given handle (if any) from the game.
(package private)  void disconnectFromGame()
          Description of the Method
(package private)  void executeNextAction(Piece p)
          Description of the Method
(package private)  JPopupMenu getGhostActionMenu()
          Returns the menu that contains actions for the ghosts.
(package private)  JPopupMenu getGhostMenu()
          Returns the menu that displays all ghost pieces that are available.
 Piece getPieceAt(Point point)
          Returns the piece at the given point of the board, or null if no such piece exists.
 Enumeration getPiecesIntersecting(Rectangle rect)
          Returns all pieces of the game that intersect the given rectangle.
 Position getPreferredCenter()
          Returns the preferred center of the board.
 Enumeration getSelectedPiecePositions()
          Returns the positions of the queued actions (and the currently executing action) of the selected piece, or NULL if no piece is selected.
 void invisibilizeMapPoint(Point p)
          Description of the Method
 void invisibilizeMapPoints(Point[] points)
          Description of the Method
static void main(String[] argv)
          Main method for program start.
 void mapLoadingProgressUpdate(double progress)
          Description of the Method
 void mapUpdate(Point[] points, int[] colors)
          Description of the Method
 void mapUpdate(Point p, int color)
          Description of the Method
(package private)  void quit()
          Description of the Method
 void removePiece(int handle)
          Description of the Method
 void removePieceAction(int handle, Action a)
          Description of the Method
 void repaintAnimation(AnimatedPiece p)
          Description of the Method
(package private)  void selectAction(Action a)
          Description of the Method
(package private)  void selectPiece(Piece p)
          Description of the Method
 void unitMessage(int handle, String message)
          Description of the Method
(package private)  void unselectAction()
          Description of the Method
(package private)  void unselectPiece()
          Description of the Method
 void updatePiece(int handle, Position newPosition)
          Description of the Method
 void updatePiece(int handle, Property[] newProperties)
          Description of the Method
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, createRootPaneException, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
, addNotify, addToFrameList, constructComponentName, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, initIDs, isResizable, postProcessKeyEvent, readObject, remove, removeFromFrameList, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle, writeObject
 
Methods inherited from class java.awt.Window
addOwnedWindow, addWindowListener, adjustListeningChildren, applyResourceBundle, applyResourceBundle, connectOwnedWindow, dispatchEventImpl, dispose, eventEnabled, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isActive, isShowing, nextFocus, ownedInit, pack, postEvent, postWindowEvent, preProcessKeyEvent, processEvent, removeOwnedWindow, removeWindowListener, resetGC, setCursor, setFocusOwner, setWarningString, show, toBack, toFront, transferFocus
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventToSelf, doLayout, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, numListening, paint, paintComponents, paintHeavyweightComponents, postsOldMouseEvents, preferredSize, print, printComponents, printHeavyweightComponents, processContainerEvent, proxyEnableEvents, proxyRequestFocus, remove, removeAll, removeContainerListener, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

gameTitle

String gameTitle
The title of the game, shown as title in window.

server

Server server
Description of the Field

lastHost

HostPort lastHost
Description of the Field

board

Board board
Description of the Field

map

Map map
Description of the Field

pieceInfoPanel

PieceInfoPanel pieceInfoPanel
Description of the Field

pieces

TreeMap pieces
The pieces that are currenlty in the game, hashed on piece handle.

actionExecutingPieces

Hashtable actionExecutingPieces
The pieces that are currenlty executing some actions. These actions are those on top of the queue and are of course not instantaneous. Hashed on action id.

actionIds

Hashtable actionIds
The action id of the currenlty executing action for some piece. Hashed on piece handle. The inverse of actionExecutingPieces.

lastExtraPieceId

int lastExtraPieceId
The handle of the ghost or explosion that was added last. The handles of ghost pieces and explosion are created and maintianed by the client, and they should be negative as it is assumed that the handles that come from the server are positive.

selectedPiece

Piece selectedPiece
Description of the Field

selectedAction

Action selectedAction
Description of the Field

actionMenuListener

ActionListener actionMenuListener
The listener that handles selections in the menu that displays the actions of a piece.

boardClicks

MouseListener boardClicks
The listener that handles clicks on the board.

boardDrags

MouseMotionListener boardDrags
The listener that handles drags on the board.

actionMenu

JPopupMenu actionMenu
The menu that is displayed with piece actions, ghost pieces or ghost actions. Different from time to time.

ghostActionMenu

JPopupMenu ghostActionMenu
The menu that contains the actions of a ghost piece (so far only remove. It is created the first time it is used, then it remains the same.

ghostMenuClick

Point ghostMenuClick
The point that was clicked on the board to bring up the ghost menu. This point is used to place the new ghost piece where the mouse was clicked.

useGhosts

boolean useGhosts
All things that has to do with ghost pieces are turned on or off by this flag. Default: on.
Constructor Detail

Game

public Game(String gameTitle)
Constructor for the Game object
Parameters:
gameTitle - Description of Parameter
Method Detail

getPieceAt

public Piece getPieceAt(Point point)
Returns the piece at the given point of the board, or null if no such piece exists.
Parameters:
point - Description of Parameter
Returns:
The PieceAt value

getPiecesIntersecting

public Enumeration getPiecesIntersecting(Rectangle rect)
Returns all pieces of the game that intersect the given rectangle. The rectangle is in actual screen coordinates, relative to the component of the board where the map and the pieces are painted.
Parameters:
rect - Description of Parameter
Returns:
The PiecesIntersecting value

getPreferredCenter

public Position getPreferredCenter()
Returns the preferred center of the board. This is the center of the current screen or, if there is a selected piece, the position of the selected piece. The preferred center is the center around which the board will zoom in.
Returns:
The PreferredCenter value

getSelectedPiecePositions

public Enumeration getSelectedPiecePositions()
Returns the positions of the queued actions (and the currently executing action) of the selected piece, or NULL if no piece is selected. The position of an action is the position of its argument (if any). The collection points is started with the position of the selected piece.
Returns:
The SelectedPiecePositions value

mapUpdate

public void mapUpdate(Point[] points,
                      int[] colors)
Description of the Method
Specified by:
mapUpdate in interface Client
Parameters:
points - Description of Parameter
colors - Description of Parameter

mapUpdate

public void mapUpdate(Point p,
                      int color)
Description of the Method
Specified by:
mapUpdate in interface Client
Parameters:
p - Description of Parameter
color - Description of Parameter

invisibilizeMapPoints

public void invisibilizeMapPoints(Point[] points)
Description of the Method
Specified by:
invisibilizeMapPoints in interface Client
Parameters:
points - Description of Parameter

invisibilizeMapPoint

public void invisibilizeMapPoint(Point p)
Description of the Method
Specified by:
invisibilizeMapPoint in interface Client
Parameters:
p - Description of Parameter

unitMessage

public void unitMessage(int handle,
                        String message)
Description of the Method
Specified by:
unitMessage in interface Client
Parameters:
handle - Description of Parameter
message - Description of Parameter

addPiece

public void addPiece(int handle,
                     String name,
                     Position pos,
                     Enumeration actions,
                     Enumeration properties,
                     String type)
Adds the specified piece, as described in Client.java. If there is a ghost piece with the same type and position, that ghost piece will be removed and replaced with the new piece. If the ghost is selected, the selection will carry over to the new piece.
Specified by:
addPiece in interface Client
Parameters:
handle - The feature to be added to the Piece attribute
name - The feature to be added to the Piece attribute
pos - The feature to be added to the Piece attribute
actions - The feature to be added to the Piece attribute
properties - The feature to be added to the Piece attribute
type - The feature to be added to the Piece attribute

updatePiece

public void updatePiece(int handle,
                        Property[] newProperties)
Description of the Method
Specified by:
updatePiece in interface Client
Parameters:
handle - Description of Parameter
newProperties - Description of Parameter

updatePiece

public void updatePiece(int handle,
                        Position newPosition)
Description of the Method
Specified by:
updatePiece in interface Client
Parameters:
handle - Description of Parameter
newPosition - Description of Parameter

removePiece

public void removePiece(int handle)
Description of the Method
Specified by:
removePiece in interface Client
Parameters:
handle - Description of Parameter

destroyPiece

public void destroyPiece(int handle)
Description of the Method
Specified by:
destroyPiece in interface Client
Parameters:
handle - Description of Parameter

addPieceAction

public void addPieceAction(int handle,
                           Action a)
Adds a feature to the PieceAction attribute of the Game object
Specified by:
addPieceAction in interface Client
Parameters:
handle - The feature to be added to the PieceAction attribute
a - The feature to be added to the PieceAction attribute

removePieceAction

public void removePieceAction(int handle,
                              Action a)
Description of the Method
Specified by:
removePieceAction in interface Client
Parameters:
handle - Description of Parameter
a - Description of Parameter

actionReply

public void actionReply(long id,
                        boolean ok,
                        String message)
Description of the Method
Specified by:
actionReply in interface Client
Parameters:
id - Description of Parameter
ok - Description of Parameter
message - Description of Parameter

connectionLost

public void connectionLost()
Description of the Method
Specified by:
connectionLost in interface Client

mapLoadingProgressUpdate

public void mapLoadingProgressUpdate(double progress)
Description of the Method
Specified by:
mapLoadingProgressUpdate in interface Client
Parameters:
progress - Description of Parameter

repaintAnimation

public void repaintAnimation(AnimatedPiece p)
Description of the Method
Specified by:
repaintAnimation in interface Animator
Parameters:
p - Description of Parameter

animationDone

public void animationDone(AnimatedPiece p)
Description of the Method
Specified by:
animationDone in interface Animator
Parameters:
p - Description of Parameter

abortExecutingAction

public void abortExecutingAction(Piece p,
                                 boolean abortAll)
Aborts the currently executing action of the given piece. Optionally, all queued actions are aborted, if not the next action in queue is executed.
Parameters:
p - The piece.
abortAll - Indiactes whether or not all executing actions should be aborted.

abortExecutingAction

public void abortExecutingAction(Piece p)
Aborts the currently executing action of the given piece. The next action in queue is then executed.
Parameters:
p - Description of Parameter

getGhostMenu

JPopupMenu getGhostMenu()
Returns the menu that displays all ghost pieces that are available. Sets up the behavior so that the selected ghost is placed on the board.
Returns:
The GhostMenu value

getGhostActionMenu

JPopupMenu getGhostActionMenu()
Returns the menu that contains actions for the ghosts.
Returns:
The GhostActionMenu value

executeNextAction

void executeNextAction(Piece p)
Description of the Method
Parameters:
p - Description of Parameter

selectPiece

void selectPiece(Piece p)
Description of the Method
Parameters:
p - Description of Parameter

unselectPiece

void unselectPiece()
Description of the Method

selectAction

void selectAction(Action a)
Description of the Method
Parameters:
a - Description of Parameter

unselectAction

void unselectAction()
Description of the Method

destroyPiece

void destroyPiece(int handle,
                  boolean animateExplosion)
Removes the piece with the given handle (if any) from the game.
Parameters:
animateExplosion - Should there be an explosion?
handle - Description of Parameter

addGhostPiece

Piece addGhostPiece(Position pos,
                    String type)
Adds a ghost piece with the specified properties. The newly created ghost symbol is returned. If there is already a ghost piece with the same type at the exact same location, no ghost will be added. In the latter case, the existing ghost piece is returned. In the ghost functionality is disabled (useGhosts flag), nothing is done and null is returned.
Parameters:
pos - The feature to be added to the GhostPiece attribute
type - The feature to be added to the GhostPiece attribute
Returns:
Description of the Returned Value

createActionMenu

JPopupMenu createActionMenu(Piece p)
Creates the menu that displays the actions of a piece. The appropriate behavior of the menu is set up.
Parameters:
p - Description of Parameter
Returns:
Description of the Returned Value

quit

void quit()
Description of the Method

disconnectFromGame

void disconnectFromGame()
Description of the Method

connectToGame

void connectToGame()
Description of the Method

main

public static void main(String[] argv)
Main method for program start.
Parameters:
argv - The command line arguments