mdh.hephaestus2
Class Game

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--mdh.hephaestus2.gamelib.Application
                                |
                                +--mdh.hephaestus2.Game
All Implemented Interfaces:
Accessible, ActionListener, EventListener, ImageObserver, KeyListener, MenuContainer, Runnable, Serializable, WindowListener

public final class Game
extends Application
implements Runnable, KeyListener

Main application of Hephaestus 2. Adventure has a reference to the Game object as "game", or you can use Game.getGame() to get it. Game contains the graphics interface tools - alert boxes, menus, output, etc.

Author:
Copyright © 2002 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>
See Also:
Serialized Form

Field Summary
 
Fields inherited from class mdh.hephaestus2.gamelib.Application
ALT, CTRL, SHIFT
 
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
 
Constructor Summary
Game(String[] args)
           
 
Method Summary
 void actionPerformed(ActionEvent ae)
          Handles action events from menus - users should not call this method!
 void addGrid(Component comp, int x, int y, Container cont, GridBagLayout grid, GridBagConstraints gbc)
           
 void addToolbar(String cmd, String filename, int x, int y, Container cont, GridBagLayout grid, GridBagConstraints gbc)
           
 boolean getDebug()
           
static Game getGame()
          Returns the Game instance.
 Grid[] getVisibleGrid()
          Returns the array of Grids visible on the View.
 LocationReadOnly getVisibleLoc()
          Returns the world location at the center of the View.
 World getWorld()
           
static void main(String[] args)
           
 void output(String text)
          Displays some text in the output terminal.
 void output(String iconfile, Color fore, Color back, String text)
          Displays some text in the output terminal, with a given icon and colors.
 void output(String iconfile, String text)
          Displays some text in the output terminal, with a given icon.
 void outputError(String text)
          Displays an error message in the output terminal.
 void outputMarkup(String text)
          Displays text with markup in the output terminal.
 void playSound(String filename)
           
 void quit()
          Quits the program with exit code 0.
 void redraw()
          Forces an immediate redraw of the View, and the stats display if any stats have changed.
 void run()
          Reads commands from the queue, and sleeps when there aren't any - users should not call this method!
 void setPaused(boolean state)
          Pauses or resumes the automatic update of the View.
 void sleep(long time)
          Stops the program for the given time in milliseconds.
 
Methods inherited from class mdh.hephaestus2.gamelib.Application
addHelpMenu, addMenu, addMenuItem, addMenuSeparator, alert, audioCache, bindKey, endMenus, fileDialog, getApplication, getAudioClip, getImage, getStatus, getVerifyQuit, imageCache, input, keyPressed, keyReleased, keyTyped, makeButton, makeChoice, makeList, makeTextField, makeTextField, makeWhitePanel, menu, setScreen, setVerifyQuit, show, showError, showStatus, stopSounds, verifyQuit, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.awt.Frame
addNotify, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, 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, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, 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, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.event.KeyListener
keyPressed, keyReleased, keyTyped
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

Game

public Game(String[] args)
     throws HephaestusException
Method Detail

main

public static void main(String[] args)

getGame

public static Game getGame()
Returns the Game instance.


addGrid

public void addGrid(Component comp,
                    int x,
                    int y,
                    Container cont,
                    GridBagLayout grid,
                    GridBagConstraints gbc)

addToolbar

public void addToolbar(String cmd,
                       String filename,
                       int x,
                       int y,
                       Container cont,
                       GridBagLayout grid,
                       GridBagConstraints gbc)

actionPerformed

public final void actionPerformed(ActionEvent ae)
Handles action events from menus - users should not call this method!

Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class Application
See Also:
ActionListener

getDebug

public final boolean getDebug()

getVisibleGrid

public Grid[] getVisibleGrid()
Returns the array of Grids visible on the View. Index the array with [x+y*Global.VIEW_TILES]. It would be a Very Bad Idea to change this array in any way. The center of the array is at x=Global.VIEW_DIST, y=Global.VIEW_DIST.


getVisibleLoc

public LocationReadOnly getVisibleLoc()
Returns the world location at the center of the View. This is usually the location of the party, but you can set it with setVisibleLoc().


getWorld

public World getWorld()

output

public final void output(String text)
Displays some text in the output terminal.

Parameters:
text - Text to display.

output

public final void output(String iconfile,
                         String text)
Displays some text in the output terminal, with a given icon.

Parameters:
iconfile - Filename of the icon to display, or null for none.
text - Text to display.

output

public final void output(String iconfile,
                         Color fore,
                         Color back,
                         String text)
Displays some text in the output terminal, with a given icon and colors.

Parameters:
iconfile - Filename of the icon to display, or null for none.
fore - Foreground color to use for the line, or null for default.
back - Background color to use for the line, or null for default.
text - Text to display.

outputError

public final void outputError(String text)
Displays an error message in the output terminal.


outputMarkup

public final void outputMarkup(String text)
Displays text with markup in the output terminal.
{c [FORE [BACK]]}
Sets the color of the text. FORE sets the foreground color, BACK sets the background color. If BACK or both FORE and BACK are not included, the default colors are used. Colors are specified as six-digit hex strings. For example, {c} resets the colors to normal, {c ff0000} sets red text, {c ffffff ff0000} sets red text on white background.

See Also:
Global.rgb(java.awt.Color)

playSound

public void playSound(String filename)
Overrides:
playSound in class Application

quit

public void quit()
Quits the program with exit code 0.

Overrides:
quit in class Application

redraw

public final void redraw()
                  throws HephaestusException
Forces an immediate redraw of the View, and the stats display if any stats have changed.

HephaestusException

run

public final void run()
Reads commands from the queue, and sleeps when there aren't any - users should not call this method!

Specified by:
run in interface Runnable

setPaused

public void setPaused(boolean state)
Pauses or resumes the automatic update of the View. ALWAYS resume after you pause the display, or animation will stop. In particular, you have to watch out for exceptions. Any code using setPaused() should look like this:
 game.setPaused(true);
 try
 {
     // your code here
 }
 finally
 {
     game.setPaused(false);
 }
 


sleep

public final void sleep(long time)
Stops the program for the given time in milliseconds.