java.awt.event.ActionListener, java.util.EventListenerpublic class Board
extends javax.swing.JPanel
implements java.awt.event.ActionListener
The version of the code by Jan Bodnar may be found at http://zetcode.com/tutorials/javagamestutorial/pacman/
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategyjava.awt.Container.AccessibleAWTContainer| Modifier and Type | Field | Description |
|---|---|---|
static int |
BLOCKSIZE |
|
static int |
GHOSTHOUSE_WIDTH |
|
static int |
NUMBLOCKS |
|
static int |
score |
|
static int |
SCORE_ENEMY |
|
static int |
SCORE_FRUIT |
|
static int |
SCORE_PELLET |
|
static int |
SCORE_POWER_PILL |
|
static int |
SCORE_WIN |
|
static int |
SCRSIZE |
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT| Constructor | Description |
|---|---|
Board() |
Constructor for Board object
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
actionPerformed(java.awt.event.ActionEvent e) |
Repaint the graphics each frame
|
void |
addNotify() |
Called by the system
|
void |
callLeaderboardMain(java.lang.String args) |
Calls the leaderboards main method with the command line arguments
|
boolean |
checkAlive() |
Returns true if any pacman is alive, returns false if they
are all dead
|
void |
detectCollision(java.util.ArrayList<Ghost> ghosts) |
Detects when ghosts and pacman collide
Ghosts are sent back to the 'ghost house' (center of map)
when pacman dies
|
void |
drawHighScores(java.awt.Graphics g) |
Displays a list of high scores on the bottom of the screen
|
void |
drawScore(java.awt.Graphics g) |
Display game information such as:
the number of pellets left,
the current score,
the number of lives left for pacman and possibly Ms.
|
void |
gameInit() |
Initialize game variables
|
void |
gameOver() |
End the game if remaining lives reaches 0.
|
void |
levelContinue() |
Initialize Pacman and ghost position/direction
|
void |
paint(java.awt.Graphics g) |
Paint graphics onto screen
|
void |
playGame(java.awt.Graphics2D g2d) |
Main game logic loop
Anything related to the updating of game objects and state occurs in this
method.
|
void |
showHelpScreen(java.awt.Graphics g) |
Shows help screen detailing game mode instructions,
movement commands, and other game controls
|
void |
showIntroScreen(java.awt.Graphics g) |
Draw a message box with the text "Press s to start." in the center of the screen
|
void |
showPauseScreen(java.awt.Graphics g) |
Draw a message box telling the player the game is paused
Also tells player to press 'p' to continue the game
|
void |
startDevMode() |
if the game is running in dev-mode then create a dev-tool GUI
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaddAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updatepublic static final int BLOCKSIZE
public static final int NUMBLOCKS
public static final int SCRSIZE
public static final int SCORE_PELLET
public static final int SCORE_FRUIT
public static final int SCORE_POWER_PILL
public static final int SCORE_ENEMY
public static final int SCORE_WIN
public static final int GHOSTHOUSE_WIDTH
public static int score
public void addNotify()
addNotify in class javax.swing.JComponentpublic void playGame(java.awt.Graphics2D g2d)
g2d - a Graphics 2D objectpublic void showIntroScreen(java.awt.Graphics g)
g - a Graphics objectpublic void showPauseScreen(java.awt.Graphics g)
g - a Graphics objectpublic void showHelpScreen(java.awt.Graphics g)
g - a Graphics objectpublic void drawScore(java.awt.Graphics g)
g - a Graphics objectpublic void drawHighScores(java.awt.Graphics g)
g - a Graphics objectpublic void gameOver()
public void detectCollision(java.util.ArrayList<Ghost> ghosts)
ghosts - An array of Ghostpublic boolean checkAlive()
public void gameInit()
public void levelContinue()
public void paint(java.awt.Graphics g)
paint in class javax.swing.JComponentg - a Graphics objectpublic void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed in interface java.awt.event.ActionListenere - an ActionEventpublic void callLeaderboardMain(java.lang.String args)
args - - represents the command line argumentspublic void startDevMode()