|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet
|
+--SpaceInvaders.SpaceInvaders
An applet simulating the popular Space Invaders video game. An initial screen asks player to specify a spaceship style and difficulty level to use in the game. A "Start game" button brings up the game screen. The difficulty level is achieved by adjusting the speed of the aliens. After each game, the same spaceship and difficulty choice menus appear along with a "Next game" button to allow continuous play without restarting the applet. Rules: Player may have up to three lasers on screen at a time. Three rows of eight aliens advance left to right, down, then right to left across the screen until player has shot them all or one of them hits the spaceship. Lasers are shot by pressing the spacebar, the spaceship can be moved right or left by arrow keys.
| Inner classes inherited from class java.applet.Applet |
java.applet.Applet.AccessibleApplet |
| Inner classes inherited from class java.awt.Panel |
java.awt.Panel.AccessibleAWTPanel |
| Inner classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock |
| Field Summary | |
private int |
alienCount
aliens remaining |
private java.awt.Image[] |
alienImage
alien image style array |
private boolean |
appInit
applet initialization flag |
private int |
BEGINNER
beginner game speed |
private boolean |
clearScreen
screen clearing flag |
private int |
COLS
number of columns in alien force |
private java.awt.Choice |
diffChoices
game difficulty choice menu |
private int |
EXPERT
expert game speed |
private java.applet.AudioClip |
gameAudio
game background music |
private boolean |
gameOver
game over flag |
private Score |
gameScore
current game score |
private int |
height
applet height |
private java.applet.AudioClip |
hitAudio
laser hitting alien sound |
private int |
INTERMEDIATE
intermediate game speed |
private int |
LASERS
maximum number of lasers allowed to fly |
private java.applet.AudioClip |
laserShoot
laser shooting swoosh |
private java.awt.Image |
modShipImage
modern spaceship image |
private Alien[][] |
myAliens
alien array |
private Ship |
myShip
the spaceship |
private boolean |
playGame
proceed with game flag |
private int |
ROWS
number of rows in alien force |
private Point |
SCORE_POSITION
position of score on screen |
private java.awt.Image |
selShipImage
spaceship image selection |
private boolean |
setGame
first game setup flag |
private java.awt.Choice |
shipChoices
spaceship choice menu |
private java.applet.AudioClip |
shipHitAudio
alien hitting ship sound |
private java.awt.Image |
shipImage
current spaceship image |
private Star[] |
stars
array of colored stars |
private java.awt.Button |
startButton
start game button |
private java.awt.Image |
stdShipImage
standard spaceship image |
private java.lang.Thread |
timer
thread that controls game speed |
private int |
width
applet width |
private boolean |
youLose
lose game flag |
private java.applet.AudioClip |
youWinAudio
victory gong |
private Laser[] |
zappers
laser array |
| Fields inherited from class java.applet.Applet |
accessibleContext, serialVersionUID, stub |
| Fields inherited from class java.awt.Panel |
base, nameCounter |
| Fields inherited from class java.awt.Container |
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads |
| Fields inherited from class java.awt.Component |
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, windowClosingException, windowListenerK, x, y |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
SpaceInvaders()
|
|
| Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent ae)
Handles game start button functions including starting game audio clip. |
boolean |
alienHitsShip(Alien alien,
Ship ship)
Determines if an alien collided with the spaceship. |
java.lang.String |
getAppletInfo()
Returns information about this applet. |
java.lang.String[][] |
getParameterInfo()
Returns information about the parameters that are settable in the HTML file. |
void |
init()
Initialize the game: Set black background with stars randomly distributed, load game sounds and spaceship and alien images, initialize game object locations as they will appear on screen. |
void |
itemStateChanged(java.awt.event.ItemEvent ie)
Handles menu selections for game difficulty and spaceship style. |
void |
keyPressed(java.awt.event.KeyEvent ke)
Handles a space bar press as an attempt to shoot a laser and shoots a laser only if fewer than the maximum number allowed are on screen; play shooting sound if shot was made. |
void |
keyReleased(java.awt.event.KeyEvent ke)
not used |
void |
keyTyped(java.awt.event.KeyEvent ke)
not used |
boolean |
laserHitsAlien(Laser zap,
Alien alien)
Determines if a laser has hit an alien. |
void |
paint(java.awt.Graphics g)
Paint all game objects and manage the moving of aliens and lasers. |
void |
run()
Controls game speed by sleeping, then repainting when needed. |
void |
start()
Restarts game music after minimization/maximization sequence if the music had been playing, then start game motion thread. |
void |
stop()
Stops Space Invaders game including all audio clips. |
void |
update(java.awt.Graphics g)
Overrides update to eliminate clearing of the graphics context before each screen paint in order to avoid annoying flicker and clears the screen when a flag is set. |
| Methods inherited from class java.applet.Applet |
destroy, getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus |
| Methods inherited from class java.awt.Panel |
|
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, readObject, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusOwner, setFont, setLayout, transferFocus, validate, validateTree, writeObject |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, resetGC, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait |
| Field Detail |
private final Point SCORE_POSITION
private final int ROWS
private final int COLS
private final int LASERS
private final int BEGINNER
private final int INTERMEDIATE
private final int EXPERT
private Ship myShip
private Score gameScore
private int width
private int height
private Laser[] zappers
private Alien[][] myAliens
private int alienCount
private java.applet.AudioClip gameAudio
private java.applet.AudioClip hitAudio
private java.applet.AudioClip shipHitAudio
private java.applet.AudioClip youWinAudio
private java.applet.AudioClip laserShoot
private java.awt.Image[] alienImage
private java.awt.Image shipImage
private java.awt.Image selShipImage
private java.awt.Image stdShipImage
private java.awt.Image modShipImage
private Star[] stars
private java.awt.Button startButton
private java.awt.Choice shipChoices
private java.awt.Choice diffChoices
private boolean appInit
private boolean setGame
private boolean clearScreen
private boolean youLose
private java.lang.Thread timer
private boolean gameOver
private boolean playGame
| Constructor Detail |
public SpaceInvaders()
| Method Detail |
public void init()
init in class java.applet.Appletpublic void start()
start in class java.applet.Appletpublic void run()
run in interface java.lang.Runnablepublic void update(java.awt.Graphics g)
update in class java.awt.Containerg - Graphics context to draw in.public void paint(java.awt.Graphics g)
paint in class java.awt.Containerg - Graphics context to draw in.
public boolean laserHitsAlien(Laser zap,
Alien alien)
zap - the Laser objectalien - the Alien object
public boolean alienHitsShip(Alien alien,
Ship ship)
alien - the Alien objectship - the Ship objectpublic void keyPressed(java.awt.event.KeyEvent ke)
keyPressed in interface java.awt.event.KeyListenerke - KeyEvent object describing the user inputpublic void keyTyped(java.awt.event.KeyEvent ke)
keyTyped in interface java.awt.event.KeyListenerpublic void keyReleased(java.awt.event.KeyEvent ke)
keyReleased in interface java.awt.event.KeyListenerpublic void actionPerformed(java.awt.event.ActionEvent ae)
actionPerformed in interface java.awt.event.ActionListenerae - ActionEvent object describing the user inputpublic void itemStateChanged(java.awt.event.ItemEvent ie)
itemStateChanged in interface java.awt.event.ItemListenerie - ItemEvent object describing the user inputpublic void stop()
stop in class java.applet.Appletpublic java.lang.String getAppletInfo()
getAppletInfo in class java.applet.Appletpublic java.lang.String[][] getParameterInfo()
getParameterInfo in class java.applet.Applet
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||