tipgame
Class GameLoop

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by tipgame.GameWindow
                          extended by tipgame.FrameAdvancer
                              extended by tipgame.GameLoop
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowStateListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
GammaCentauriLoop, InputLoop, PongLoop, SpaceInvadersLoop, SpriteTestLoop

public abstract class GameLoop
extends FrameAdvancer

adds a mouse and keyboard interaction to FrameAdvancer

Author:
Jam Jenkins
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  boolean audible
          field which can be used to mute/enable sound
private  Client client
          used to stream keyboard/mouse information to/from the server/client
private  java.lang.String gameName
          name of game
private  int id
          which index belongs to this computer
protected  java.lang.Object[] messages
          messages
private  int numPlayers
          number of payers
protected  Keyboard[] playerKeyboard
          all keyboards
protected  Mouse[] playerMouse
          all mouses
static java.util.Random random
          used for random numbers
static long SEED
          seed for random numbers
private  java.lang.String server
          server name
private  java.lang.String sessionName
          name of session
 
Fields inherited from class tipgame.FrameAdvancer
canvas, timeInterval
 
Fields inherited from class tipgame.GameWindow
frame, gameLoop, hasFrame, help, helpPlay, mute, pause, quit, title
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
GameLoop()
          constructs a GameLoop with the default size AnimationCanvas (given in FrameAdvancer)
GameLoop(java.awt.Dimension size)
          constructs a GameLoop with the given size
 
Method Summary
 void connect(java.lang.String server, java.lang.String gameName, java.lang.String sessionName, int players)
          connects to the server and sets the game and session name and sets the number of players
 void disconnect()
          disconnects from server
 int getID()
           
 boolean isMuted()
          returns true if muted, false if not muted
 boolean isPaused()
          returns true if paused
 void pauseToggle()
          changes between paused and unpaused
 void postAdvanceFrame()
          clears the keyboard and mouse stuff
 void sendMessage(java.lang.Object localMessage)
          sends message
 void setGameName(java.lang.String gameName)
          sets the name of the game
 void setNumberOfPlayers(int numPlayers)
          sets the number of players
 void setServerName(java.lang.String server)
          sets the name of the server
 void setSessionName(java.lang.String sessionName)
          sets the name of the session
 void start()
          starts session
 void startGame()
          starts game
 void toggleAudible()
          switches between mute and audible
 
Methods inherited from class tipgame.FrameAdvancer
advanceFrame, cancelAlarm, clearAllAlarms, getCanvas, getScreenRefreshRate, getTime, refreshScreen, scheduleAbsolute, scheduleRelative, setCanvas, setMinimumModelFrameRate, updateModel
 
Methods inherited from class tipgame.GameWindow
actionPerformed, getDefaultSize, getHelpURL, init, runAsApplication, setTitle, setUseFrame, stop, windowStateChanged
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, 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, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

SEED

public static final long SEED
seed for random numbers

See Also:
Constant Field Values

random

public static java.util.Random random
used for random numbers


client

private Client client
used to stream keyboard/mouse information to/from the server/client


playerKeyboard

protected Keyboard[] playerKeyboard
all keyboards


playerMouse

protected Mouse[] playerMouse
all mouses


id

private int id
which index belongs to this computer


messages

protected java.lang.Object[] messages
messages


server

private java.lang.String server
server name


gameName

private java.lang.String gameName
name of game


sessionName

private java.lang.String sessionName
name of session


numPlayers

private int numPlayers
number of payers


audible

private boolean audible
field which can be used to mute/enable sound

Constructor Detail

GameLoop

public GameLoop()
constructs a GameLoop with the default size AnimationCanvas (given in FrameAdvancer)


GameLoop

public GameLoop(java.awt.Dimension size)
constructs a GameLoop with the given size

Parameters:
size - the size of the AnimationCanvas
Method Detail

toggleAudible

public void toggleAudible()
switches between mute and audible

Overrides:
toggleAudible in class GameWindow

isMuted

public boolean isMuted()
returns true if muted, false if not muted

Returns:
WhetherMuted

start

public void start()
starts session

Overrides:
start in class java.applet.Applet

startGame

public void startGame()
starts game

Specified by:
startGame in class GameWindow

postAdvanceFrame

public void postAdvanceFrame()
clears the keyboard and mouse stuff

Specified by:
postAdvanceFrame in class FrameAdvancer

setServerName

public void setServerName(java.lang.String server)
sets the name of the server

Specified by:
setServerName in class GameWindow
Parameters:
server -

setSessionName

public void setSessionName(java.lang.String sessionName)
sets the name of the session

Specified by:
setSessionName in class GameWindow
Parameters:
sessionName -

setGameName

public void setGameName(java.lang.String gameName)
sets the name of the game

Specified by:
setGameName in class GameWindow
Parameters:
gameName -

setNumberOfPlayers

public void setNumberOfPlayers(int numPlayers)
sets the number of players

Specified by:
setNumberOfPlayers in class GameWindow
Parameters:
numPlayers -

sendMessage

public void sendMessage(java.lang.Object localMessage)
sends message

Parameters:
localMessage -

connect

public void connect(java.lang.String server,
                    java.lang.String gameName,
                    java.lang.String sessionName,
                    int players)
connects to the server and sets the game and session name and sets the number of players

Parameters:
server -
gameName -
sessionName -
players -

disconnect

public void disconnect()
disconnects from server

Specified by:
disconnect in class GameWindow

isPaused

public boolean isPaused()
returns true if paused

Returns:
isPaused

pauseToggle

public void pauseToggle()
changes between paused and unpaused

Overrides:
pauseToggle in class GameWindow

getID

public int getID()