Class sailc1

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--sailc1
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class sailc1
extends java.awt.Frame
implements java.lang.Runnable, java.awt.event.KeyListener

This class acts as the game client for the sailing game. It loads the necessary game images and passes them to a new instance of the rendering class (Environment) that it creates in its animation thread. It also creates a UDP_Net_Connection which binds to a port and starts a listener, This class also overrides the paint() and update() methods and is responsible for scheduling repaint() events. This is accomplished using a java.util timer object which is used to schedule regular updates. All painting is done first to a buffer which is then blitted to the screen (known as double buffering). On certain platforms this seems to cause more of a performance hit than on others but is necessary to avoid unattractive, flickering animation.

See Also:
Serialized Form

Field Summary
 State_Container state_info
           
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
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
 
Method Summary
 void input_event(java.lang.String event)
          Purpose: This function is called by the key listener functions above for the purpose of buffering the admin inputs which are then sent to the server.
 void keyPressed(java.awt.event.KeyEvent evt)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
          Purpose: This functions are called by the key listener on the frame when a keyboard event occurs.
static void main(java.lang.String[] args)
          Purpose: Collects the server IP address as a command line argument or, if not provided it uses the default of "localhost".
 void paint(java.awt.Graphics g)
           
 void run()
          Purpose: This run method is the animation/game thread for the game.
 int set_options(int[] choices)
          Purpose: This function defines a list of strings describing game options.
 void update(java.awt.Graphics g)
          Description: The paint() and update() methods are defined by java for frames.
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, paramString, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, 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, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, 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, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, 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, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

state_info

public State_Container state_info
Method Detail

main

public static void main(java.lang.String[] args)
Purpose: Collects the server IP address as a command line argument or, if not provided it uses the default of "localhost". It then creates a new game client object (sailc1) which starts that actual game.


set_options

public int set_options(int[] choices)
Purpose: This function defines a list of strings describing game options. These options are then painted to the screen and the user is prompted to make a numerical choice of options 1,2, or 3. Once the user has made their choices the function returns. Returns: If the user chooses to load defaults then the function returns 0 It they choose to pick the mode then it displays all promps and waits for input. It returns 1 when complete. The options choices are stored in the choices int[] passed to the function.


run

public void run()
Purpose: This run method is the animation/game thread for the game. It declares a new Environment object with the game images and options information. It then constructs a start message and sends it to the server. This method also defines a animationtimer object which it then overrides the doRun() method of and writes all of the necessary game loop code in. This is based on the Java.util timertask and is then scheduled to be run every 20 ms.

Specified by:
run in interface java.lang.Runnable

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Purpose: This functions are called by the key listener on the frame when a keyboard event occurs. Currently, only the keyPressed event is monitored. When the game is in progress (GAME_IN_PROGRESS flag set) the sail and rudder control are monitored and implemented accordingly. If the user has chosen God-mode wind type then all of the admin commands are also activated. Also, delay compensation can be toggled on and off during the game. When the game is not in progress only the option choice keys for choosing game options are activated (1,2,3).

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
Specified by:
keyPressed in interface java.awt.event.KeyListener

input_event

public void input_event(java.lang.String event)
Purpose: This function is called by the key listener functions above for the purpose of buffering the admin inputs which are then sent to the server. This function allows the system to be changed without any need to alter the keylistener function..


update

public void update(java.awt.Graphics g)
Description: The paint() and update() methods are defined by java for frames. When a repaint() call is make a flag is set such that eventually the code in these two functions will be exectued (a paint event). By default, if not overwritten, the update method merely clears (whitewashes) the screen and the paint method does nothing. By default, update() is called before paint(). Below are the overridden methods for this frame which allow the game itself to be painted to the screen. Purpose: This function renders the contents of the double buffer once they have been painted to it by the drawScene function of the Environment rendering class. The double buffer (although causing a performance hit) makes for a higher quality animation with no visible flicker. All necessary drawing is done in update() with no need for anything in paint(). When the game is in progress the game is rendered. When the game is not in progress, the message string (used for the optioning system) is rendered.

Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container