Class Bojng
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----Bojng
- class Bojng
- extends Canvas
- implements Runnable, BojngInterface
The main game engine - controls everything.
Source
- See Also:
- BojngInterface, Stats, Timer, Update, Ball, Paddle, Field
-
balls
-
-
blockheight
- Size of block (Pixels)
-
blockwidth
- Size of block (Pixels)
-
bombTargets
-
-
bulcol
-
-
bulheight
- Bullets
-
bullets
-
-
bulspeed
- Pixel/tick
-
bulwidth
- Bullets
-
canvgr
-
-
clickWaitTime
-
-
defaultMessage
-
-
field
-
-
imgheight
- Pixel size of image/canvas
-
imgwidth
- Pixel size of image/canvas
-
msgs
- Msg
-
msgShowCntr
-
-
msgShowTime
-
-
nextRandomBase
-
-
nextRandomCntr
-
-
nextRandomVar
-
-
offGr
-
-
offImg
-
-
P_BASE
- Punkte
-
P_BOMB
- Punkte
-
P_BULLETS
- Punkte
-
P_GROW
- Punkte
-
P_NEWBALL
- Punkte
-
P_TRIPLE
- Punkte
-
paddle
- Image[] imgs;
-
rand
-
-
S_ALLITEMSREMOVED
- initialize
-
S_BALLINVALID
- initialize
-
S_GAMEOVER
- initialize
-
S_INIT
- initialize
-
S_NEWLEVEL
- initialize
-
S_PLAYING
- initialize
-
S_STOPNOW
- initialize
-
S_WAITFORCLICK
- initialize
-
standardPos
-
-
state
-
-
stateCntr
-
-
stats
- URL urlBase;
-
thread
-
-
timer
- Delay in ms
-
update
-
-
Bojng(URL, Stats, Label)
- Sets up everything, starts main game thread.
-
_blockheight()
-
-
_blockwidth()
-
-
_fieldHeight()
-
-
_fieldWidth()
-
-
_imgheight()
-
-
_imgwidth()
-
-
_paddle()
-
-
_update()
-
-
addBombTarget(Point)
- Adds a location to the bomb target vector.
-
bomb(int, int)
- Starts a new BombThread to explode a bomb.
-
clearBlock(int, int)
- Draws a rectangle from the background image to the off-screen
image to fill the rectangle of a block.
-
drawBackground(int, int, int, int)
- Draws a rectangle from the background image to the off-screen
image and adds it to the update area.
-
drawImage(Image, int, int)
- Draws an image on the off-screen buffer and adds it to the
update region.
-
explodeAllBlocks()
- Clears the whole field of all blocks.
-
getItem(int, int)
-
-
hit(Object, Object)
- Does the special actions needed when a block is hit by a ball or a
bullet and adds game points.
-
initOffGr()
- Initializes the off-screen and background images.
-
kill()
- Stops all threads and enters the S_STOPNOW state.
-
killBall(Ball)
- Kills a ball, removes it from the ball vector, updates statistics
and displays a message about it.
-
mouseDown(Event, int, int)
- Handles mouse clicks events to start the game or shoot bullets.
-
mouseMove(Event, int, int)
- Handles mouse movement events to place the paddle.
-
moveBullet(Point)
- Moves one bullet further and checks for hits with blocks and balls.
-
ms()
- Returns the number of ms waited between two ticks.
-
msg(String)
- Displays a string on the message line for some seconds.
-
paint(Graphics)
- Repaints the window using the off-screen image.
-
posRand(int)
- Calculates a random positive integer.
-
removeBullets()
- Removes all bullets, for example if a game is ended.
-
removeItem(int, int)
- Removes one item from the map, setting the state to S_ALLITEMSREMOVED
if necessary.
-
run()
- Main loop - handles everything, controled by
state.
-
shoot()
- Shoots a bullet from the current paddle position.
-
teleport(Ball)
- Teleports a ball to a random location and displays a message about
this.
-
update()
- Calls update.update
-
update(Graphics)
- Repaints the window using the off-screen image.
timer
Timer timer
- Delay in ms
update
Update update
thread
Thread thread
balls
Vector balls
paddle
Paddle paddle
- Image[] imgs;
stats
Stats stats
- URL urlBase;
bullets
Vector bullets
field
Field field
bombTargets
Vector bombTargets
S_INIT
final int S_INIT
- initialize
S_NEWLEVEL
final int S_NEWLEVEL
- initialize
S_BALLINVALID
final int S_BALLINVALID
- initialize
S_WAITFORCLICK
final int S_WAITFORCLICK
- initialize
S_PLAYING
final int S_PLAYING
- initialize
S_ALLITEMSREMOVED
final int S_ALLITEMSREMOVED
- initialize
S_GAMEOVER
final int S_GAMEOVER
- initialize
S_STOPNOW
final int S_STOPNOW
- initialize
state
int state
stateCntr
int stateCntr
nextRandomCntr
int nextRandomCntr
clickWaitTime
final int clickWaitTime
nextRandomBase
final int nextRandomBase
nextRandomVar
final int nextRandomVar
rand
Random rand
P_BASE
final int P_BASE
- Punkte
P_TRIPLE
final int P_TRIPLE
- Punkte
P_BULLETS
final int P_BULLETS
- Punkte
P_GROW
final int P_GROW
- Punkte
P_NEWBALL
final int P_NEWBALL
- Punkte
P_BOMB
final int P_BOMB
- Punkte
blockwidth
int blockwidth
- Size of block (Pixels)
blockheight
int blockheight
- Size of block (Pixels)
imgwidth
int imgwidth
- Pixel size of image/canvas
imgheight
int imgheight
- Pixel size of image/canvas
offGr
Graphics offGr
canvgr
Graphics canvgr
offImg
Image offImg
bulwidth
final int bulwidth
- Bullets
bulheight
final int bulheight
- Bullets
bulspeed
final int bulspeed
- Pixel/tick
bulcol
final Color bulcol
standardPos
Point standardPos
msgs
Label msgs
- Msg
msgShowCntr
int msgShowCntr
msgShowTime
final int msgShowTime
defaultMessage
String defaultMessage
Bojng
Bojng(URL urlBase,
Stats stats,
Label msgs)
- Sets up everything, starts main game thread.
- Parameters:
- urlBase - the document base of the game
- stats - statistics display on the top of the screen
- msgs - message display at the bottom
kill
void kill()
- Stops all threads and enters the S_STOPNOW state.
run
public void run()
- Main loop - handles everything, controled by
state.
paint
public void paint(Graphics g)
- Repaints the window using the off-screen image.
- Parameters:
- g - the Graphics context
- Overrides:
- paint in class Canvas
update
public void update(Graphics g)
- Repaints the window using the off-screen image.
- Parameters:
- g - the Graphics context
- Overrides:
- update in class Component
mouseMove
public boolean mouseMove(Event evt,
int x,
int y)
- Handles mouse movement events to place the paddle.
- Parameters:
- evt - the mouse event, unused
- x - the x coordinate, unused
- y - the y coordinate
- Returns:
-
true, if handled
- Overrides:
- mouseMove in class Component
mouseDown
public boolean mouseDown(Event evt,
int x,
int y)
- Handles mouse clicks events to start the game or shoot bullets.
- Parameters:
- evt - the mouse event, unused
- x - the x coordinate, unused
- y - the y coordinate, unused
- Returns:
-
true, if handled
- Overrides:
- mouseDown in class Component
initOffGr
synchronized boolean initOffGr()
- Initializes the off-screen and background images.
drawBackground
public void drawBackground(int x,
int y,
int w,
int h)
- Draws a rectangle from the background image to the off-screen
image and adds it to the update area. All coordinates are in pixel
space.
- Parameters:
- x - the x coordinate
- y - the y coordinate
- w - the width coordinate
- h - the height coordinate
clearBlock
public void clearBlock(int x,
int y)
- Draws a rectangle from the background image to the off-screen
image to fill the rectangle of a block. The coordinates are in
block space.
- Parameters:
- x - the x coordinate
- y - the y coordinate
removeItem
public void removeItem(int bx,
int by)
- Removes one item from the map, setting the state to S_ALLITEMSREMOVED
if necessary. The coordinate are in block space.
- Parameters:
- x - the x coordinate
- y - the y coordinate
hit
public synchronized void hit(Object i,
Object ball)
- Does the special actions needed when a block is hit by a ball or a
bullet and adds game points.
- Parameters:
- i - the item which is hit
- ball - the ball that hit the block (or null)
- See Also:
- Item, Ball
explodeAllBlocks
void explodeAllBlocks()
- Clears the whole field of all blocks.
msg
public void msg(String s)
- Displays a string on the message line for some seconds.
- Parameters:
- s - the string to be displayed
shoot
synchronized void shoot()
- Shoots a bullet from the current paddle position. At most one
bullet can be active at a time.
moveBullet
boolean moveBullet(Point p)
- Moves one bullet further and checks for hits with blocks and balls.
- Parameters:
- p - the bullet
- Returns:
-
false, if the bullet should be removed
removeBullets
void removeBullets()
- Removes all bullets, for example if a game is ended.
killBall
void killBall(Ball ball)
- Kills a ball, removes it from the ball vector, updates statistics
and displays a message about it.
- Parameters:
- ball - the ball to be removed
posRand
public int posRand(int max)
- Calculates a random positive integer.
- Parameters:
- max - the maximum value
- Returns:
- -1<;rc<max
bomb
public void bomb(int x,
int y)
- Starts a new BombThread to explode a bomb. The coordinates are int
block space.
- Parameters:
- x - the x coordinate
- y - the y coordinate
addBombTarget
void addBombTarget(Point p)
- Adds a location to the bomb target vector.
- Parameters:
- p - the point to be added, in block space
drawImage
public void drawImage(Image i,
int x,
int y)
- Draws an image on the off-screen buffer and adds it to the
update region.
- Parameters:
- i - the image to be drawn
- x - the x coordinate
- y - the y coordinate
update
public void update()
- Calls update.update
- See Also:
- update
teleport
void teleport(Ball ball)
- Teleports a ball to a random location and displays a message about
this.
- Parameters:
- ball - the ball to be teleported
ms
public int ms()
- Returns the number of ms waited between two ticks.
- Returns:
- s timer.ms
getItem
public Rectangle getItem(int x,
int y)
_update
public Update _update()
_paddle
public Rectangle _paddle()
_fieldWidth
public int _fieldWidth()
_fieldHeight
public int _fieldHeight()
_blockwidth
public int _blockwidth()
_blockheight
public int _blockheight()
_imgwidth
public int _imgwidth()
_imgheight
public int _imgheight()