public class GameGrid extends java.awt.Canvas implements GGActListener
Modifier and Type | Class and Description |
---|---|
static class |
GameGrid.ClosingMode
Modes to determine what happens when the title bar close button is hit.
|
Modifier and Type | Field and Description |
---|---|
static GameGrid.ClosingMode |
AskOnClose
ClosingMode AskOnClose.
|
java.awt.Color |
bgColor
The color of the background.
|
java.lang.String |
bgImagePath
Path of the background image.
|
int |
bgImagePosX
ULX of the background image with respect to playground.
|
int |
bgImagePosY
ULY of the background image with respect to playground.
|
static java.awt.Color |
BLACK
Short for Color.BLACK.
|
static java.awt.Color |
BLUE
Short for Color.BLUE.
|
int |
cellSize
Size of cells in pixels (square).
|
static java.awt.Color |
CYAN
Short for Color.CYAN.
|
static java.awt.Color |
DARKGRAY
Short for Color.DKGRAY.
|
static GameGrid.ClosingMode |
DisposeOnClose
ClosingMode DisposeOnClose.
|
static java.awt.Color |
GRAY
Short for Color.GRAY.
|
static java.awt.Color |
GREEN
Short for Color.GREEN.
|
java.awt.Color |
gridColor
Color of the grid.
|
static java.awt.Color |
LIGHTGRAY
Short for Color.LTGRAY.
|
static java.awt.Color |
MAGENTA
Short for Color.MAGENTY.
|
static java.lang.Object |
monitor
Object used for synchronizing access of methods accessing
the sceen list.
|
int |
nbHorzCells
Number of horizonal cells.
|
static int |
nbRotSprites
Number of rotated sprite images.
|
int |
nbVertCells
Number of vertical cells.
|
static GameGrid.ClosingMode |
NothingOnClose
ClosingMode NothingOnClose.
|
static java.awt.Color |
PINK
Short for Color.RED.
|
static java.awt.Color |
RED
Short for Color.RED.
|
int |
simulationPeriod
Simulation period (in ms).
|
static GameGrid.ClosingMode |
TerminateOnClose
ClosingMode TerminateOnClose.
|
static java.awt.Color |
TRANSPARENT
Short for transparent color Color(0, 0, 0, 0) (black with alpha = 0).
|
static java.awt.Color |
WHITE
Short for Color.WHITE.
|
static java.awt.Color |
YELLOW
Short for Color.YELLOW.
|
Constructor and Description |
---|
GameGrid()
Constructs the game playground with 10 by 10 cells
(20 pixels wide).
|
GameGrid(boolean isNavigation)
Constructs a game window including a playground of 10 by 10 cells (60 pixels wide)
with possibly a navigation bar and a visible red grid but no background image.
|
GameGrid(int nbHorzCells,
int nbVertCells)
Constructs a game window with one pixel cell size
including a playground with no navigation bar, no visible grid
and no background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize)
Constructs a game window including a playground with
a navigation bar and no visible grid
and no background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
boolean isNavigation)
Constructs a game window including a playground with no visible grid
and no background image, but possibly a navigation bar.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor)
Constructs a game window including a playground with a navigation bar
and a possibly a visible grid, but no background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
boolean isNavigation)
Constructs a game window including playground with possibly a navigation bar,
possibly a visible grid and no background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
java.lang.String bgImagePath)
Constructs a game window including a playground with a navigation bar,
possibly a visible grid and possibly a background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
java.lang.String bgImagePath,
boolean isNavigation)
Constructs a game window including a playground with possibly a navigation bar,
possibly a visible grid and possibly a background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
java.lang.String bgImagePath,
boolean isNavigation,
boolean undecorated)
Constructs a game window including a playground with possibly a
navigation bar, possibly a visible grid, possibly a background image
and possibly no decoration.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
java.lang.String bgImagePath,
boolean isNavigation,
int nbRotSprites)
Constructs a game window including a playground with possibly a
navigation bar, possibly a visible grid, and possibly a background image.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.awt.Color gridColor,
java.lang.String bgImagePath,
boolean isNavigation,
int nbRotSprites,
boolean undecorated)
Constructs a game window including a playground with possibly a
navigation bar, possibly a visible grid, possibly a background image and
and possibly no decoration.
|
GameGrid(int nbHorzCells,
int nbVertCells,
int cellSize,
java.lang.String bgImagePath)
Constructs a game window including a playground with a navigation bar
and a possibly a background image, but no visible grid.
|
Modifier and Type | Method and Description |
---|---|
void |
act()
Empty method called in every simulation cycle after all actor act() calls.
|
void |
actAll()
Invokes all actor's act() methods in the order of the scene
and draws the new game situation.
|
void |
activate()
Brings the game grid window to the front and request the focus.
|
void |
addActListener(GGActListener listener)
Registers the given GGActListener to get act() events.
|
void |
addActor(Actor actor,
Location location)
Same as addActor(Actor actor, Location location, double direction) with
direction = 0 (to east).
|
void |
addActor(Actor actor,
Location location,
double direction)
Adds a new actor at given starting position with given moving direction
to the scene.
|
void |
addActor(Actor actor,
Location location,
Location.CompassDirection compassDir)
Same as addActor(Actor actor, Location location, double direction)
with compass direction.
|
void |
addActorNoRefresh(Actor actor,
Location location)
Same as addActor(Actor actor, Location location), but the game grid window
is not refreshed automatically.
|
void |
addActorNoRefresh(Actor actor,
Location location,
double direction)
Same as addActor(Actor actor, Location location, double direction),
but the game grid window is not refreshed automatically.
|
void |
addExitListener(GGExitListener listener)
Registers the given GGExitListener to get an event when the title bar
close button is hit.
|
void |
addKeyListener(GGKeyListener listener)
Adds a GGKeyListener to get events when a key is pressed.
|
void |
addKeyRepeatListener(GGKeyRepeatListener listener)
Adds a GGKeyRepeatListener to get repeating events with default period (20 ms)
when a key is pressed until the key is released.
|
void |
addMouseListener(GGMouseListener listener,
int mouseEventMask)
Adds a GGMouseListener to get notifications from mouse events.
|
void |
addNavigationListener(GGNavigationListener listener)
Register a navigation listener to get notifications when the navigation
panel is used.
|
void |
addResetListener(GGResetListener listener)
Registers the given GGResetListener to get events when the
reset button is hit.
|
void |
addStatusBar(int height)
Adds a status window attached at the bottom of the game grid window
(below the navigation bar, if available).
|
void |
addWindowStateListener(GGWindowStateListener listener)
Register a GGWindowStateListener that will report change of window
location and iconification.
|
GGTileMap |
createTileMap(int nbHorzTiles,
int nbVertTiles,
int tileWidth,
int tileHeight)
Creates/Replaces a TileMap with the specified number of horizontal and vertical
tiles.
|
static void |
delay(long time)
Delays execution for the given amount of time.
|
void |
dispose()
Stops the game thread, hides the game window, disposes the frame
and calls Monitor.wakeUp().
|
void |
doPause()
Pauses the simulation cycling.
|
void |
doReset()
If still running, calls doPause() and restores actors
to their initializing state.
|
void |
doRun()
Starts the simulation cycling.
|
void |
doStep()
Runs the the simulation loop once.
|
java.util.ArrayList<Actor> |
getActors()
Returns all actors that are part of the game grid.
|
java.util.ArrayList<Actor> |
getActors(java.lang.Class clazz)
Returns all actors of the specified class that are part of the game grid.
|
java.util.ArrayList<Actor> |
getActorsAt(Location location)
Returns all actors at the given location that are part of the game grid.
|
java.util.ArrayList<Actor> |
getActorsAt(Location location,
java.lang.Class clazz)
Returns all actors of given type at given location that are part of
the game grid.
|
java.awt.Dimension |
getAreaSize()
Returns the size of the occupied area (the frame window
including navigation and status bar, if available).
|
GGBackground |
getBg()
Returns a reference to the background of the game grid.
|
java.awt.Color |
getBgColor()
Returns the color of the background.
|
java.lang.String |
getBgImagePath()
Returns to path to the background image file.
|
java.awt.Point |
getBgImagePos()
Returns the x-y-coordinates of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
int |
getBgImagePosX()
Returns the x-coordinate of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
int |
getBgImagePosY()
Returns the y-coordinate of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
int |
getCellSize()
Returns the size of a cell (in pixels).
|
static GameGrid.ClosingMode |
getClosingMode()
Returns the closing mode read from the gamegrid.properties file.
|
java.util.ArrayList<Location> |
getDiagonalLocations(Location location,
boolean up)
Returns a list of all grid locations that are on the diagonal line
through the given location.
|
int |
getDoubleClickDelay()
Returns the current double-click delay.
|
java.util.ArrayList<Location> |
getEmptyLocations()
Returns a list of all locations not occupied by actors.
|
javax.swing.JFrame |
getFrame()
Returns the JFrame reference of the surrounding window.
|
java.awt.Color |
getGridColor()
Returns the color of the grid.
|
java.awt.image.BufferedImage |
getImage()
Returns the BufferedImage of the current GameGrid window including
the background and all actors.
|
char |
getKeyChar()
Returns the character of the last key pressed and removes it from the
one-key buffer.
|
int |
getKeyCode()
Returns the key code of the last key pressed and removes it from the
one-key buffer.
|
int |
getKeyModifiers()
Returns the key modifier of the last key pressed.
|
java.lang.String |
getKeyModifiersText()
Returns the key modifier as text of the last key pressed.
|
java.util.ArrayList<Location> |
getLineLocations(Location loc1,
Location loc2,
boolean interjacent)
Returns a list of cell grid locations whose cell centers are exactly on the
the line through the centers of loc1 and loc1.
|
Location |
getMouseLocation()
Returns the cell location of the cell under the mouse pointer or null, if
the game grid is not visible or obscured by another window.
|
int |
getNbCycles()
Returns the number of simulation cycles since last reset.
|
int |
getNbHorzCells()
Returns the horizontal number of cells.
|
int |
getNbHorzPix()
Returns the horizontal number of pixels of the playground.
|
int |
getNbVertCells()
Returns the vertical number of cells.
|
int |
getNbVertPix()
Returns the vertical number of pixels of the playground.
|
int |
getNumberOfActors()
Returns total number of actors in the scene.
|
int |
getNumberOfActors(java.lang.Class clazz)
Returns number of actors of specified class.
|
int |
getNumberOfActorsAt(Location location)
Returns number of actors at specified location.
|
int |
getNumberOfActorsAt(Location location,
java.lang.Class clazz)
Returns number of actors of specified class at specified location.
|
java.util.ArrayList<Location> |
getOccupiedLocations()
Returns a list of all locations occupied by actors.
|
Actor |
getOneActor(java.lang.Class clazz)
Returns the actor of the specified class
that is part of the game grid and is on top in the paint order.
|
Actor |
getOneActorAt(Location location)
Returns the actor at the specified location
that is part of the game grid and is on top in the paint order.
|
Actor |
getOneActorAt(Location location,
java.lang.Class clazz)
Returns the actor of the specified class at the specified location
that is part of the game grid and is on top in the paint order.
|
java.util.ArrayList<Actor> |
getPaintOrderList()
Returns a list with actor references in the order they are painted.
|
java.util.ArrayList<Actor> |
getPaintOrderList(java.lang.Class clazz)
Returns a list with actor references of the given class in the order they
are painted.
|
GGPanel |
getPanel()
Returns a reference to the GGPanel with current settings.
|
GGPanel |
getPanel(double xmin,
double xmax,
double ymin,
double ymax)
Sets the coordinate system in GGPanel to given range and
returns a reference to the GGPanel of the game grid.
|
int |
getPgHeight()
Returns the height (vertical size) of the playground in pixel units.
|
int |
getPgWidth()
Returns the width (horizontal size) of the playground in pixel units.
|
java.awt.Point |
getPosition()
Returns the the location in screen coordiantes of game grid window.
|
java.util.ArrayList<java.lang.Integer> |
getPressedKeyCodes()
Returns a list of the key codes of all keys currently pressed
|
double |
getRandomDirection()
Returns a random direction 0..360 degrees.
|
Location |
getRandomEmptyLocation()
Returns an empty random location within the game grid.
|
Location |
getRandomLocation()
Returns a random location within the game grid.
|
int |
getSimulationPeriod()
Returns the current simulation period.
|
void |
getStackTrace(java.lang.String s)
Implementation of the GGExceptionHandler's event method called when
an uncaught exception is thrown.
|
GGTileMap |
getTileMap()
Returns the reference to the GGTileMap.
|
java.util.ArrayList<Actor> |
getTouchedActors(java.lang.Class clazz)
Returns a list with actor references of all actors of the given class whose
touched area (of type IMAGE, RECTANGLE or CIRCLE) intersects with the current mouse
cursor location.
|
static java.lang.String |
getVersion()
Returns current version information.
|
void |
hide()
Hides the game grid, but does not destroy it.
|
boolean |
isActorColliding(Actor a1,
Actor a2)
Checks if the two given actors are colliding.
|
boolean |
isAtBorder(Location location)
Returns true, if the given cell location is at the grid border.
|
static boolean |
isDisposed()
Returns true if closing mode DisposeOnClose is selected
and the close button was hit.
|
boolean |
isEmpty(Location location)
Returns true, if there is no actor at specified location.
|
boolean |
isInGrid(Location location)
Returns true, if the given cell location is within the grid.
|
boolean |
isKeyPressed(int keyCode)
Returns true if the key with the given key code is currently pressed.
|
boolean |
isPaused()
Returns true, if the game is paused
|
boolean |
isRunning()
Returns true, if the game is running.
|
boolean |
isShown()
Returns the state if visibilty of the game grid window.
|
boolean |
isTileColliding(Actor a,
Location location)
Checks if the given actor and the tile at the given tile location are colliding.
|
boolean |
isUndecorated()
Returns true, if the window is undecorated (no title bar and no borders).
|
boolean |
kbhit()
Returns true, if a key was press since the last call to getKeyChar() or getKeyCode().
|
void |
paint(java.awt.Graphics g)
For internal use only (overrides Canvas.paint() to get
paint notifications).
|
SoundPlayer |
playLoop(GGSound sound)
Play continously a distributed sound sample with maximum volume using the default sound device.
|
SoundPlayer |
playLoop(java.lang.Object obj,
GGSound sound)
Play continously a distributed sound sample with maximum volume using the default sound device.
|
SoundPlayer |
playLoop(java.lang.Object obj,
java.lang.String audioPathname)
Play continuously a sound sample from a JAR resource of the specified object with maximum volume using the default sound device.
|
SoundPlayer |
playLoop(java.lang.String audioPathname)
Play continuously a sound sample with maximum volume using the default sound device
using the current class loader to load the resource.
|
SoundPlayerExt |
playLoopExt(java.lang.Object obj,
java.lang.String audioPathname)
Same as playLoop(obj, audioPathname) but supports MP3.
|
SoundPlayerExt |
playLoopExt(java.lang.String audioPathname)
Same as playLoop(audioPathname) but supports MP3.
|
SoundPlayer |
playSound(GGSound sound)
Plays a distributed sound sample with maximum volume using the default sound device.
|
SoundPlayer |
playSound(java.lang.Object obj,
GGSound sound)
Play a distributed sound sample with maximum volume using the default sound device.
|
SoundPlayer |
playSound(java.lang.Object obj,
java.lang.String audioPathname)
Play a sound sample from a JAR resource of the specified object
with maximum volume using the default sound device.
|
SoundPlayer |
playSound(java.lang.String audioPathname)
Play a sound sample from given audio file with maximum volume using the default sound device
using the current class loader to load the resource.
|
SoundPlayerExt |
playSoundExt(java.lang.Object obj,
java.lang.String audioPathname)
Same as playSound(obj, audioPathname) but supports MP3.
|
SoundPlayerExt |
playSoundExt(java.lang.String audioPathname)
Same as playSound(audioPathname) but supports MP3.
|
void |
refresh()
Refreshs the current game situation (repaint background, tiles, actors).
|
boolean |
removeActor(Actor actor)
Removes the given actor from the scene, so that act() is not called any more.
|
int |
removeActors(java.lang.Class clazz)
Removes all actors from the specified class, so that act() is not called any more.
|
int |
removeActorsAt(Location location)
Removes all actors at the specified location, so that act() is not called any more.
|
int |
removeActorsAt(Location location,
java.lang.Class clazz)
Removes all actors from the specified class at the specified location,
so that act() is not called any more.
|
int |
removeAllActors()
Removes all actors from the scene, so that act() is not called any more.
|
void |
removeKeyListener(GGKeyListener listener)
Removes a previously registered GGKeyListener.
|
void |
removeKeyRepeatListener(GGKeyRepeatListener listener)
Removes a previously registered GGKeyRepeatListener.
|
boolean |
removeMouseListener(GGMouseListener listener)
Removes the given mouse listener from the list of registered
mouse listeners.
|
void |
reset()
Empty method called when the reset button is hit or doReset() is called.
|
Actor |
reverseSceneOrder(java.util.ArrayList<Actor> actors)
Reverses the order of the given actor list in the corresponding
scene list.
|
void |
setActEnabled(boolean enable)
Enables/disables the simulation cycle momentarily.
|
void |
setActOrder(java.lang.Class... classes)
Set the act order of objects in the scene.
|
void |
setActorOnBottom(Actor actor)
Puts the given actor at first place in the corresponding scene list,
in order to act last and to be drawn on the bottom of other actors
of the same class.
|
void |
setActorOnTop(Actor actor)
Puts the given actor at last place in the corresponding scene list,
in order to act first and to be drawn on top of other actors
of the same class.
|
void |
setBgColor(java.awt.Color color)
Sets the color of the background.
|
void |
setBgColor(int r,
int g,
int b)
Sets the color of the background.
|
void |
setBgImagePath(java.lang.String bgImagePath)
Sets the path to the background image file.
|
void |
setBgImagePos(java.awt.Point point)
Sets the x-y-coordinate of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
void |
setBgImagePosX(int x)
Sets the x-coordinate of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
void |
setBgImagePosY(int y)
Sets the y-coordinate of the upper left vertex of the background image
with respect to the playground pixel coordinates.
|
void |
setCellSize(int cellSize)
Sets the size of a cell.
|
static void |
setClosingMode(GameGrid.ClosingMode closingMode)
Sets the closing mode that determines what happens when
the title bar close button is hit.
|
void |
setDoubleClickDelay(int delay)
Sets the time delay the system uses to distinct click and double-click
mouse events.
|
void |
setGridColor(java.awt.Color color)
Sets the color of the grid and reconstructs the background.
|
int |
setKeyRepeatPeriod(int keyRepeatPeriod)
Sets the time between two successive key repeat events.
|
void |
setMouseEnabled(boolean enabled)
Enable/disable all mouse event callbacks.
|
void |
setNbHorzCells(int nbHorzCells)
Sets the horizontal number of cells.
|
void |
setNbVertCells(int nbVertCells)
Sets the vertical number of cells.
|
void |
setPaintOrder(java.lang.Class... classes)
Sets the paint order of objects in the game grid.
|
void |
setPosition(int ulx,
int uly)
Move the location of the game grid window to the given screen position.
|
void |
setSceneOrder(java.util.ArrayList<Actor> actors)
Sets the act and paint order of the actors in the given list by
rearraging their scene list to the order in the given list.
|
void |
setSimulationPeriod(int millisec)
Sets the period of the simulation loop.
|
void |
setStatusText(java.lang.String text)
Replaces the text in the status bar by the given text using the default
font and text color of JOptionPane.
|
void |
setStatusText(java.lang.String text,
java.awt.Font font,
java.awt.Color color)
Replaces the text in the status bar by the given text using the given
font and text color.
|
void |
setTitle(java.lang.String text)
Set the title in the window's title bar.
|
Actor |
shiftSceneOrder(java.util.ArrayList<Actor> actors,
boolean forward)
Shifts (rolls) the actors of the given actor list in the corresponding
scene list forward or backward.
|
void |
show()
Shows the game grid after initialisation or when hided.
|
void |
showStatusBar(boolean show)
Shows or hides the status bar.
|
void |
stopGameThread()
Stops the game thread to avoid any CPU consumption.
|
Location |
toLocation(int x,
int y)
Returns the location (cell indices) of the cell where the point
with given coordinates resides.
|
Location |
toLocation(java.awt.Point pt)
Returns the location (cell indices) of the cell where the given point
resides.
|
Location |
toLocationInGrid(int x,
int y)
Returns the location (cell indices) of the cell where the point
with given coordinates resides.
|
Location |
toLocationInGrid(java.awt.Point pt)
Returns the location (cell indices) of the cell where the given point
resides.
|
java.awt.Point |
toPoint(Location location)
Returns the x-y-coordinates of the center of the cell with given
location (cell indices).
|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
public static final GameGrid.ClosingMode TerminateOnClose
public static final GameGrid.ClosingMode AskOnClose
public static final GameGrid.ClosingMode DisposeOnClose
public static final GameGrid.ClosingMode NothingOnClose
public static final java.awt.Color TRANSPARENT
public static final java.awt.Color BLACK
public static final java.awt.Color BLUE
public static final java.awt.Color CYAN
public static final java.awt.Color DARKGRAY
public static final java.awt.Color GRAY
public static final java.awt.Color GREEN
public static final java.awt.Color LIGHTGRAY
public static final java.awt.Color MAGENTA
public static final java.awt.Color PINK
public static final java.awt.Color RED
public static final java.awt.Color WHITE
public static final java.awt.Color YELLOW
public java.awt.Color gridColor
public int nbHorzCells
public int nbVertCells
public int cellSize
public java.lang.String bgImagePath
public int bgImagePosX
public int bgImagePosY
public java.awt.Color bgColor
public int simulationPeriod
public static int nbRotSprites
public static final java.lang.Object monitor
public GameGrid()
public GameGrid(boolean isNavigation)
isNavigation
- if true, a navigation bar is shownpublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixelUnits) of the cellpublic GameGrid(int nbHorzCells, int nbVertCells)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellspublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, boolean isNavigation)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellisNavigation
- if true, a navigation bar is shownpublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.lang.String bgImagePath)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellbgImagePath
- the path or URL to a background image (if null, no background image)public GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)public GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, java.lang.String bgImagePath)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)bgImagePath
- the path or URL to a background image (if null, no background image)public GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, boolean isNavigation)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)isNavigation
- if true, a navigation bar is shownpublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, java.lang.String bgImagePath, boolean isNavigation)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)bgImagePath
- the path to a background image (if null, no background image)isNavigation
- if true, a navigation bar is shownpublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, java.lang.String bgImagePath, boolean isNavigation, boolean undecorated)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)bgImagePath
- the path to a background image (if null, no background image)isNavigation
- if true, a navigation bar is shownundecorated
- if true, the window has no title bar and no borderspublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, java.lang.String bgImagePath, boolean isNavigation, int nbRotSprites)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)bgImagePath
- the path to a background image (if null, no background image)isNavigation
- if true, a navigation bar is shownnbRotSprites
- the number of preloaded rotated sprite images for
all actors (default: 60). Be aware that if you change this parameter, your actors
must be created AFTER the GameGrid constructor terminates, because the
actor's creation process uses this parameterpublic GameGrid(int nbHorzCells, int nbVertCells, int cellSize, java.awt.Color gridColor, java.lang.String bgImagePath, boolean isNavigation, int nbRotSprites, boolean undecorated)
nbHorzCells
- the number of horizontal cellsnbVertCells
- the number of vertical cellscellSize
- the side length (in pixel units) of the cellgridColor
- the color of the grid (if null, no grid is shown)bgImagePath
- the path to a background image (if null, no background image)isNavigation
- if true, a navigation bar is shownnbRotSprites
- the number of preloaded rotated sprite images for
all actors (default: 60). Be aware that if you change this parameter, your actors
must be created AFTER the GameGrid constructor terminates, because the
actor's creation process uses this parameterundecorated
- if true, the window has no title bar and no bordersActor
public java.lang.String getBgImagePath()
public void setBgImagePath(java.lang.String bgImagePath)
bgImagePath
- the path to the image file; if null, no background
image is assumedpublic int getBgImagePosX()
public void setBgImagePosX(int x)
x
- the ULX of the background imagepublic int getBgImagePosY()
public void setBgImagePosY(int y)
y
- the ULY of the background imagepublic java.awt.Point getBgImagePos()
public void setBgImagePos(java.awt.Point point)
point
- the ULX/ULY of the background imagepublic java.awt.Color getBgColor()
public void setBgColor(java.awt.Color color)
color
- the background colorpublic void setBgColor(int r, int g, int b)
r
- the red value of the color RGBg
- the green value of the color RGBb
- the blue value of the color RGBpublic int getNbHorzCells()
public void setNbHorzCells(int nbHorzCells)
nbHorzCells
- the number of cells in horizontal directionpublic int getNbVertCells()
public void setNbVertCells(int nbVertCells)
nbVertCells
- the number of cells in vertical directionpublic java.awt.Color getGridColor()
public void setGridColor(java.awt.Color color)
color
- the grid color; null, if no grid is desiredpublic int getNbHorzPix()
public int getNbVertPix()
public int getPgWidth()
public int getPgHeight()
public int getCellSize()
public void setCellSize(int cellSize)
cellSize
- the length of the cell side in pixel units.public GGBackground getBg()
public GGPanel getPanel()
public GGPanel getPanel(double xmin, double xmax, double ymin, double ymax)
public void addActorNoRefresh(Actor actor, Location location)
actor
- the actor to be added at the end of the scene listlocation
- the location of the actor (cell indices, value copy)public void addActorNoRefresh(Actor actor, Location location, double direction)
actor
- the actor to be added at the end of the scene listlocation
- the location of the actor (cell indices, value copy)direction
- the direction (clockwise in degrees, 0 to east)public void addActor(Actor actor, Location location, double direction)
actor
- the actor to be added at the end of the scene listlocation
- the location of the actor (cell indices, value copy)direction
- the direction (clockwise in degrees, 0 to east)public void addActor(Actor actor, Location location)
actor
- the actor to be added at the end of the scene listlocation
- the location of the actor (cell indices, value copy)public void addActor(Actor actor, Location location, Location.CompassDirection compassDir)
actor
- the actor to be added at the end of the scene listlocation
- the location of the actor (cell indices)compassDir
- the compass directionpublic java.awt.image.BufferedImage getImage()
public void refresh()
public void actAll()
public void setActOrder(java.lang.Class... classes)
classes
- the classes in desired act orderpublic void setPaintOrder(java.lang.Class... classes)
classes
- the classes in desired paint orderpublic static void delay(long time)
time
- the delay time (in ms)public void doRun()
public void doPause()
public void doStep()
public void doReset()
public javax.swing.JFrame getFrame()
public int getSimulationPeriod()
public void setSimulationPeriod(int millisec)
millisec
- the period of the simulation loop (in milliseconds)public boolean kbhit()
public char getKeyChar()
public int getKeyCode()
public int getKeyModifiers()
public java.lang.String getKeyModifiersText()
public boolean isKeyPressed(int keyCode)
keyCode
- the code of the key you are interested in (a constant
defined in java.awt.event.KeyCode).public void addKeyListener(GGKeyListener listener)
listener
- the GGKeyListener to registerpublic void removeKeyListener(GGKeyListener listener)
listener
- the GGKeyListener to removepublic boolean isInGrid(Location location)
public boolean isAtBorder(Location location)
public java.util.ArrayList<Location> getOccupiedLocations()
public java.util.ArrayList<Location> getEmptyLocations()
public java.util.ArrayList<Actor> getActors()
public java.util.ArrayList<Actor> getActorsAt(Location location, java.lang.Class clazz)
location
- the location of the cellclazz
- class type of the actors to be returned (e.g. Fish.class),
if clazz is null, all actors are returnedpublic java.util.ArrayList<Actor> getActorsAt(Location location)
public java.util.ArrayList<Actor> getActors(java.lang.Class clazz)
clazz
- the class of the actors to look for, if null all actors are returnedpublic Actor getOneActorAt(Location location, java.lang.Class clazz)
location
- the location of the cellclazz
- the class of the actors to look for, if null all actors are consideredpublic Actor getOneActor(java.lang.Class clazz)
clazz
- the class of the actors to look for, if null all actors are consideredpublic Actor getOneActorAt(Location location)
location
- the location of the cellpublic int getNumberOfActors()
public int getNumberOfActorsAt(Location location)
public int getNumberOfActorsAt(Location location, java.lang.Class clazz)
public int getNumberOfActors(java.lang.Class clazz)
public boolean isEmpty(Location location)
public boolean removeActor(Actor actor)
actor
- the actor to be removedpublic int removeAllActors()
public int removeActors(java.lang.Class clazz)
clazz
- class of the actors to be removed, if null all actors are removedpublic int removeActorsAt(Location location, java.lang.Class clazz)
location
- the location of the cellclazz
- class of the actors to be removed, if null all actors are removedpublic int removeActorsAt(Location location)
location
- the location of the cellpublic Location getRandomLocation()
public double getRandomDirection()
public Location getRandomEmptyLocation()
public boolean isRunning()
public boolean isPaused()
public boolean isActorColliding(Actor a1, Actor a2)
a1
- the first actora2
- the second actorpublic boolean isTileColliding(Actor a, Location location)
a
- the actor to check for collisionlocation
- the tile locationpublic SoundPlayer playSound(java.lang.Object obj, GGSound sound)
playSound(GGSound sound)
sound
- the named sound sample from the GGSound enumerationobj
- object whose class loader is used to load the resourcepublic SoundPlayer playSound(GGSound sound)
sound
- the named sound sample from the GGSound enumerationpublic SoundPlayer playLoop(java.lang.Object obj, GGSound sound)
playLoop(GGSound sound)
sound
- the named sound sample from the GGSound enumerationobj
- object whose class loader is used to load the resourcepublic SoundPlayer playLoop(GGSound sound)
sound
- the named sound sample from the GGSound enumerationpublic SoundPlayer playSound(java.lang.Object obj, java.lang.String audioPathname)
obj
- object whose class loader is used to load the resourceaudioPathname
- path to the sound filepublic SoundPlayer playSound(java.lang.String audioPathname)
audioPathname
- path to the sound filepublic SoundPlayer playLoop(java.lang.Object obj, java.lang.String audioPathname)
obj
- object whose class loader is used to load the resourceaudioPathname
- path to the sound filepublic SoundPlayer playLoop(java.lang.String audioPathname)
audioPathname
- path to the sound filepublic SoundPlayerExt playSoundExt(java.lang.Object obj, java.lang.String audioPathname)
public SoundPlayerExt playSoundExt(java.lang.String audioPathname)
public SoundPlayerExt playLoopExt(java.lang.Object obj, java.lang.String audioPathname)
public SoundPlayerExt playLoopExt(java.lang.String audioPathname)
public boolean removeMouseListener(GGMouseListener listener)
listener
- the listener to removepublic void addMouseListener(GGMouseListener listener, int mouseEventMask)
listener
- the GGMouseListener to registermouseEventMask
- an OR-combinaton of constants defined in class GGMousepublic void setMouseEnabled(boolean enabled)
enabled
- if true, the registered callbacks are enabled; otherwise disabledpublic java.awt.Point toPoint(Location location)
location
- the indices of the cellpublic Location toLocation(java.awt.Point pt)
pt
- a point of pixels coordinatespublic Location toLocation(int x, int y)
x
- x-coordinate (in pixels)y
- y-coordinate (in pixels)public Location toLocationInGrid(java.awt.Point pt)
pt
- a point of pixels coordinatespublic Location toLocationInGrid(int x, int y)
x
- x-coordinate (in pixels)y
- y-coordinate (in pixels)public void setActorOnTop(Actor actor)
actor
- the actor to put on topsetPaintOrder(Class... classes)
public void setActorOnBottom(Actor actor)
actor
- the actor to put on the bottomsetPaintOrder(Class... classes)
public Actor shiftSceneOrder(java.util.ArrayList<Actor> actors, boolean forward)
actors
- a list of actors to shiftforward
- if true, shifts to the right (forward); otherwise
shifts to the left (backward)public Actor reverseSceneOrder(java.util.ArrayList<Actor> actors)
actors
- a list of actors to shiftpublic void setSceneOrder(java.util.ArrayList<Actor> actors)
actors
- a list of actors to rearrangepublic java.util.ArrayList<Actor> getPaintOrderList(java.lang.Class clazz)
clazz
- the class of actors included in the list; if null, all actors are includedpublic java.util.ArrayList<Actor> getPaintOrderList()
public java.util.ArrayList<Actor> getTouchedActors(java.lang.Class clazz)
clazz
- the class of actors checked for a touch. If null, all
actors are checked.public void stopGameThread()
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
public void addActListener(GGActListener listener)
listener
- the GGActListener to registerpublic GGTileMap createTileMap(int nbHorzTiles, int nbVertTiles, int tileWidth, int tileHeight)
nbHorzTiles
- the number of horizontal tilesnbVertTiles
- the number of vertical tilestileWidth
- the width of each tile (in pixels)tileHeight
- the height of each tile (in pixels)public GGTileMap getTileMap()
public int getNbCycles()
public void act()
act
in interface GGActListener
public void reset()
public void show()
show
in class java.awt.Component
public void hide()
hide
in class java.awt.Component
public void setTitle(java.lang.String text)
text
- the text to displaypublic void addNavigationListener(GGNavigationListener listener)
listener
- the GGNavigationListener to registerpublic void addResetListener(GGResetListener listener)
listener
- the GGActListener to registerpublic void addExitListener(GGExitListener listener)
listener
- the GGActListener to registerpublic static java.lang.String getVersion()
public void getStackTrace(java.lang.String s)
s
- the stack trace informationpublic void setPosition(int ulx, int uly)
ulx
- the upper left vertex x-coordinate of the window in pixelsuly
- the upper left vertex y-coordinate of the window in pixelspublic java.awt.Point getPosition()
public boolean isUndecorated()
public void addWindowStateListener(GGWindowStateListener listener)
listener
- the GGFrameStateListener to registerpublic void activate()
public void addStatusBar(int height)
height
- the height in pixels of the status windowpublic void setStatusText(java.lang.String text)
text
- the new text to show in the status barpublic void setStatusText(java.lang.String text, java.awt.Font font, java.awt.Color color)
text
- the new text to show in the status barfont
- the text fontcolor
- the text colorpublic void showStatusBar(boolean show)
show
- if true, a hidden status bar is shown even if the game grid
window is hidden; if false, the status bar is hidden and not shown until
showStatusBar(true) is called.public java.awt.Dimension getAreaSize()
public Location getMouseLocation()
public java.util.ArrayList<Location> getDiagonalLocations(Location location, boolean up)
location
- the location where the diagonal line is fixedup
- if true, the increasing diagonal line (y = x + b) is used; otherwise
the decreasing diagonal line (y = -x + b) is usedpublic java.util.ArrayList<Location> getLineLocations(Location loc1, Location loc2, boolean interjacent)
loc1
- the location of the first cellloc2
- the location of the second cellinterjacent
- if true, only location between loc1 and loc2 are
includedpublic void setActEnabled(boolean enable)
enable
- if true, a running simulation cycle is interrupted; otherwise
a running simulation cycles is reenabledpublic void setDoubleClickDelay(int delay)
delay
- the double click delay time in milliseconds used when a
double-click event is registeredpublic int getDoubleClickDelay()
public boolean isShown()
public void addKeyRepeatListener(GGKeyRepeatListener listener)
listener
- the GGKeyRepeatListener to registerpublic void removeKeyRepeatListener(GGKeyRepeatListener listener)
listener
- the GGKeyRepeatListener to removepublic int setKeyRepeatPeriod(int keyRepeatPeriod)
keyRepeatPeriod
- the new key repeat period (in ms)public java.util.ArrayList<java.lang.Integer> getPressedKeyCodes()
public static void setClosingMode(GameGrid.ClosingMode closingMode)
closingMode
- one of the items in enum GameGrid.ClosingModepublic static GameGrid.ClosingMode getClosingMode()
public static boolean isDisposed()
public void dispose()