frog.demo
Class DemoGame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by frog.demo.DemoGame
All Implemented Interfaces:
KeyListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class DemoGame
extends JFrame
implements Runnable, KeyListener

The main class for the Demo mode of FROG. DemoGame features a four-player game in which cows are abducted by UFOs and it is up to the players to save the cows from their otherworldly fate. Players perform the gestures that appear on the UFOs coming for the cows. Successfully performed gestures will destroy a UFO of that type, awarding points to the killing player, and buying a little more time before the next UFO swoops in.

DemoGame is responsible for setting up all the internals of the game such as the sounds and images that will be used. After starting the DemoController which manages input and output, the DemoGame will continue to maintain a stable FPS until the game has been exited by pressing the ESC key.

Author:
Team Better Recognize
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 Clip[] ABDUCT_SOUND
          Sounds
(package private) static int ABDUCT_VARIANCE
          How many of that sound file there is
 BufferedImage BG_IMG
          Image for the game
 Clip[] BOOSH_SOUND
          Sounds
(package private) static int BOOSH_VARIANCE
          How many of that sound file there is
 DemoController controller
          The controller for this DemoGame.
static float COW_HEIGHT
          Proportional dimension of the CowSprite
 BufferedImage[] COW_IMG
          Animated image for the game
static float COW_WIDTH
          Proportional dimension of the CowSprite
(package private) static int DELAYS_PER_YIELD
           
(package private) static long DESIRED_FPS
           
 Clip[] EXPLOSION_SOUND
          Sounds
(package private) static int EXPLOSION_VARIANCE
          How many of that sound file there is
 JFrame frame
          The fullscreen frame that will be displaying this game
 BufferedImage GAMEOVER_IMG
          Image for the game
 int height
          The 4:3 aspect ratio dimension for the user's monitor
(package private) static int MAX_FRAME_SKIPS
          Maximum allowed frame skips before updates begin to slow down
 Clip[] MOO_SOUND
          Sounds
(package private) static int MOO_VARIANCE
          How many of that sound file there is
(package private) static int NUM_BUFFERS
          Number of buffers for page flipping
 int offset
          The 4:3 aspect ratio dimension for the user's monitor
(package private) static long PERIOD
           
 Vector<Player> players
          Players for this game are stored here
 int SCREEN_HEIGHT
          The fullscreen dimension for the user's monitor
 int SCREEN_WIDTH
          The fullscreen dimension for the user's monitor
 BufferedImage[] UFO_C_IMG
          Animated image for the game
static float UFO_HEIGHT
          Proportional dimension of the UFOSprite
 BufferedImage[] UFO_S_IMG
          Animated image for the game
 BufferedImage[] UFO_T_IMG
          Animated image for the game
static float UFO_WIDTH
          Proportional dimension of the UFOSprite
 BufferedImage[] UFO_X_IMG
          Animated image for the game
 BufferedImage[] UFO_Z_IMG
          Animated image for the game
 int width
          The 4:3 aspect ratio dimension for the user's monitor
 Clip[] WOOSH_SOUND
          Sounds
(package private) static int WOOSH_VARIANCE
          How many of that sound file there is
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
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 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
DemoGame(Collection<User> players)
          Starts a new DemoGame with the given Players.
 
Method Summary
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
 void run()
          Sleep timing and draw/update calls based heavily on an example from the book "Killer Game Programming" by Andrew Davison.
 void stopGame()
          Signal game over.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, 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, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

controller

public final DemoController controller
The controller for this DemoGame.


width

public final int width
The 4:3 aspect ratio dimension for the user's monitor


height

public final int height
The 4:3 aspect ratio dimension for the user's monitor


offset

public final int offset
The 4:3 aspect ratio dimension for the user's monitor


SCREEN_WIDTH

public final int SCREEN_WIDTH
The fullscreen dimension for the user's monitor


SCREEN_HEIGHT

public final int SCREEN_HEIGHT
The fullscreen dimension for the user's monitor


frame

public final JFrame frame
The fullscreen frame that will be displaying this game


BG_IMG

public final BufferedImage BG_IMG
Image for the game


GAMEOVER_IMG

public final BufferedImage GAMEOVER_IMG
Image for the game


COW_IMG

public final BufferedImage[] COW_IMG
Animated image for the game


UFO_C_IMG

public final BufferedImage[] UFO_C_IMG
Animated image for the game


UFO_S_IMG

public final BufferedImage[] UFO_S_IMG
Animated image for the game


UFO_T_IMG

public final BufferedImage[] UFO_T_IMG
Animated image for the game


UFO_X_IMG

public final BufferedImage[] UFO_X_IMG
Animated image for the game


UFO_Z_IMG

public final BufferedImage[] UFO_Z_IMG
Animated image for the game


MOO_SOUND

public final Clip[] MOO_SOUND
Sounds


EXPLOSION_SOUND

public final Clip[] EXPLOSION_SOUND
Sounds


ABDUCT_SOUND

public final Clip[] ABDUCT_SOUND
Sounds


WOOSH_SOUND

public final Clip[] WOOSH_SOUND
Sounds


BOOSH_SOUND

public final Clip[] BOOSH_SOUND
Sounds


MOO_VARIANCE

static final int MOO_VARIANCE
How many of that sound file there is

See Also:
Constant Field Values

EXPLOSION_VARIANCE

static final int EXPLOSION_VARIANCE
How many of that sound file there is

See Also:
Constant Field Values

ABDUCT_VARIANCE

static final int ABDUCT_VARIANCE
How many of that sound file there is

See Also:
Constant Field Values

WOOSH_VARIANCE

static final int WOOSH_VARIANCE
How many of that sound file there is

See Also:
Constant Field Values

BOOSH_VARIANCE

static final int BOOSH_VARIANCE
How many of that sound file there is

See Also:
Constant Field Values

players

public final Vector<Player> players
Players for this game are stored here


NUM_BUFFERS

static final int NUM_BUFFERS
Number of buffers for page flipping

See Also:
Constant Field Values

MAX_FRAME_SKIPS

static final int MAX_FRAME_SKIPS
Maximum allowed frame skips before updates begin to slow down

See Also:
Constant Field Values

DELAYS_PER_YIELD

static final int DELAYS_PER_YIELD
See Also:
Constant Field Values

DESIRED_FPS

static final long DESIRED_FPS
See Also:
Constant Field Values

PERIOD

static final long PERIOD
See Also:
Constant Field Values

UFO_WIDTH

public static final float UFO_WIDTH
Proportional dimension of the UFOSprite

See Also:
Constant Field Values

UFO_HEIGHT

public static final float UFO_HEIGHT
Proportional dimension of the UFOSprite

See Also:
Constant Field Values

COW_WIDTH

public static final float COW_WIDTH
Proportional dimension of the CowSprite

See Also:
Constant Field Values

COW_HEIGHT

public static final float COW_HEIGHT
Proportional dimension of the CowSprite

See Also:
Constant Field Values
Constructor Detail

DemoGame

public DemoGame(Collection<User> players)
         throws Exception
Starts a new DemoGame with the given Players.

Parameters:
players - the Players for this game.
Throws:
Exception - if full screen mode is not supported.
Method Detail

run

public void run()
Sleep timing and draw/update calls based heavily on an example from the book "Killer Game Programming" by Andrew Davison.

Specified by:
run in interface Runnable

stopGame

public void stopGame()
Signal game over. Leaves Game Over message on the screen until the ESC key is pressed.


keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener