|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectspaceinvaders.Game
public class Game
The Game object is the core of the application. It is a "Runnable" - the thread that runs it keeps the game going while another thread looks after the graphics. It is a MouseListener and MouseMotionListener - the mouse is used by the player to control the gun; the Game object picks up the mouse events. It is responsible for drawing the Gun and other details in the display apart from the invaders. It provides a number of utility functions for the invaders.
| Constructor Summary | |
|---|---|
Game(int num)
Constructor - loads sound files, performs other minor initializations. |
|
| Method Summary | |
|---|---|
GamePanel |
getGamePanel()
Used by invaders to get reference to display panel (e.g. |
void |
groundBurst(int damage)
Record damage done to gun when invader hits ground |
int |
gunLocation()
Returns gun's location (x-coordinate in game coordinates) |
void |
mouseClicked(java.awt.event.MouseEvent e)
Record attempt to fire gun in this cycle of game |
void |
mouseDragged(java.awt.event.MouseEvent e)
No-operation (Part of MouseMotionListener) |
void |
mouseEntered(java.awt.event.MouseEvent e)
No-operation (Part of MouseListener) |
void |
mouseExited(java.awt.event.MouseEvent e)
No-operation (Part of MouseListener) |
void |
mouseMoved(java.awt.event.MouseEvent e)
Mouse moved, use x-coordinate to update gun position |
void |
mousePressed(java.awt.event.MouseEvent e)
No-operation (Part of MouseListener) |
void |
mouseReleased(java.awt.event.MouseEvent e)
No-operation (Part of MouseListener) |
void |
paint(java.awt.Graphics g)
Paints gun etc, then tells each invader to paint itself |
void |
run()
Define game behaviour: while gunners are alive check for movement/firing of gun allow invaders to attack |
int |
score()
Returns current score for player. |
void |
setControlLink(ControlPanel cp)
Set link to control panel. |
void |
setGamePanelLink(GamePanel gp)
Set link to GamePanel. |
void |
start()
Starts a new thread to run the game |
int |
status()
Returns integer status score for player (score starts at 100 and is decreased every time an invader makes a successful attack) |
int |
X2X(int gameX)
Converts game X-coordinate to screen X-coordinate (needed when an invader is trying to draw itself) |
int |
Y2Y(int gameY)
Converts game Y-coordinate to screen Y-coordinate (needed when an invader is trying to draw itself) |
void |
zapGun()
Record damage done by invader to gun through mechanisms like missle fire |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Game(int num)
num - Defines number of invaders to use in game.| Method Detail |
|---|
public int X2X(int gameX)
gameX - Game x- coordinate
public int Y2Y(int gameY)
gameY - Game Y coordinate
public void setControlLink(ControlPanel cp)
cp - Reference to ControlPanel part of GUIpublic void setGamePanelLink(GamePanel gp)
gp - GamePanel component in GUI.public int score()
public int status()
public int gunLocation()
public GamePanel getGamePanel()
public void paint(java.awt.Graphics g)
g - Graphic object used for paintingpublic void start()
public void zapGun()
public void groundBurst(int damage)
damage - Damage done by this invaderpublic void run()
run in interface java.lang.Runnablepublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked in interface java.awt.event.MouseListenere - Mouse event marking clickpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered in interface java.awt.event.MouseListenere - Mouse eventpublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenere - Mouse eventpublic void mousePressed(java.awt.event.MouseEvent e)
mousePressed in interface java.awt.event.MouseListenere - Mouse eventpublic void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased in interface java.awt.event.MouseListenere - Mouse eventpublic void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged in interface java.awt.event.MouseMotionListenere - Mouse eventpublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved in interface java.awt.event.MouseMotionListenere - Mouse event (with x,y coords in display coordinates)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||