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

Variable Index

 o balls
 o blockheight
Size of block (Pixels)
 o blockwidth
Size of block (Pixels)
 o bombTargets
 o bulcol
 o bulheight
Bullets
 o bullets
 o bulspeed
Pixel/tick
 o bulwidth
Bullets
 o canvgr
 o clickWaitTime
 o defaultMessage
 o field
 o imgheight
Pixel size of image/canvas
 o imgwidth
Pixel size of image/canvas
 o msgs
Msg
 o msgShowCntr
 o msgShowTime
 o nextRandomBase
 o nextRandomCntr
 o nextRandomVar
 o offGr
 o offImg
 o P_BASE
Punkte
 o P_BOMB
Punkte
 o P_BULLETS
Punkte
 o P_GROW
Punkte
 o P_NEWBALL
Punkte
 o P_TRIPLE
Punkte
 o paddle
Image[] imgs;
 o rand
 o S_ALLITEMSREMOVED
initialize
 o S_BALLINVALID
initialize
 o S_GAMEOVER
initialize
 o S_INIT
initialize
 o S_NEWLEVEL
initialize
 o S_PLAYING
initialize
 o S_STOPNOW
initialize
 o S_WAITFORCLICK
initialize
 o standardPos
 o state
 o stateCntr
 o stats
URL urlBase;
 o thread
 o timer
Delay in ms
 o update

Constructor Index

 o Bojng(URL, Stats, Label)
Sets up everything, starts main game thread.

Method Index

 o _blockheight()
 o _blockwidth()
 o _fieldHeight()
 o _fieldWidth()
 o _imgheight()
 o _imgwidth()
 o _paddle()
 o _update()
 o addBombTarget(Point)
Adds a location to the bomb target vector.
 o bomb(int, int)
Starts a new BombThread to explode a bomb.
 o clearBlock(int, int)
Draws a rectangle from the background image to the off-screen image to fill the rectangle of a block.
 o drawBackground(int, int, int, int)
Draws a rectangle from the background image to the off-screen image and adds it to the update area.
 o drawImage(Image, int, int)
Draws an image on the off-screen buffer and adds it to the update region.
 o explodeAllBlocks()
Clears the whole field of all blocks.
 o getItem(int, int)
 o hit(Object, Object)
Does the special actions needed when a block is hit by a ball or a bullet and adds game points.
 o initOffGr()
Initializes the off-screen and background images.
 o kill()
Stops all threads and enters the S_STOPNOW state.
 o killBall(Ball)
Kills a ball, removes it from the ball vector, updates statistics and displays a message about it.
 o mouseDown(Event, int, int)
Handles mouse clicks events to start the game or shoot bullets.
 o mouseMove(Event, int, int)
Handles mouse movement events to place the paddle.
 o moveBullet(Point)
Moves one bullet further and checks for hits with blocks and balls.
 o ms()
Returns the number of ms waited between two ticks.
 o msg(String)
Displays a string on the message line for some seconds.
 o paint(Graphics)
Repaints the window using the off-screen image.
 o posRand(int)
Calculates a random positive integer.
 o removeBullets()
Removes all bullets, for example if a game is ended.
 o removeItem(int, int)
Removes one item from the map, setting the state to S_ALLITEMSREMOVED if necessary.
 o run()
Main loop - handles everything, controled by state.
 o shoot()
Shoots a bullet from the current paddle position.
 o teleport(Ball)
Teleports a ball to a random location and displays a message about this.
 o update()
Calls update.update
 o update(Graphics)
Repaints the window using the off-screen image.

Variables

 o timer
 Timer timer
Delay in ms

 o update
 Update update
 o thread
 Thread thread
 o balls
 Vector balls
 o paddle
 Paddle paddle
Image[] imgs;

 o stats
 Stats stats
URL urlBase;

 o bullets
 Vector bullets
 o field
 Field field
 o bombTargets
 Vector bombTargets
 o S_INIT
 final int S_INIT
initialize

 o S_NEWLEVEL
 final int S_NEWLEVEL
initialize

 o S_BALLINVALID
 final int S_BALLINVALID
initialize

 o S_WAITFORCLICK
 final int S_WAITFORCLICK
initialize

 o S_PLAYING
 final int S_PLAYING
initialize

 o S_ALLITEMSREMOVED
 final int S_ALLITEMSREMOVED
initialize

 o S_GAMEOVER
 final int S_GAMEOVER
initialize

 o S_STOPNOW
 final int S_STOPNOW
initialize

 o state
 int state
 o stateCntr
 int stateCntr
 o nextRandomCntr
 int nextRandomCntr
 o clickWaitTime
 final int clickWaitTime
 o nextRandomBase
 final int nextRandomBase
 o nextRandomVar
 final int nextRandomVar
 o rand
 Random rand
 o P_BASE
 final int P_BASE
Punkte

 o P_TRIPLE
 final int P_TRIPLE
Punkte

 o P_BULLETS
 final int P_BULLETS
Punkte

 o P_GROW
 final int P_GROW
Punkte

 o P_NEWBALL
 final int P_NEWBALL
Punkte

 o P_BOMB
 final int P_BOMB
Punkte

 o blockwidth
 int blockwidth
Size of block (Pixels)

 o blockheight
 int blockheight
Size of block (Pixels)

 o imgwidth
 int imgwidth
Pixel size of image/canvas

 o imgheight
 int imgheight
Pixel size of image/canvas

 o offGr
 Graphics offGr
 o canvgr
 Graphics canvgr
 o offImg
 Image offImg
 o bulwidth
 final int bulwidth
Bullets

 o bulheight
 final int bulheight
Bullets

 o bulspeed
 final int bulspeed
Pixel/tick

 o bulcol
 final Color bulcol
 o standardPos
 Point standardPos
 o msgs
 Label msgs
Msg

 o msgShowCntr
 int msgShowCntr
 o msgShowTime
 final int msgShowTime
 o defaultMessage
 String defaultMessage

Constructors

 o 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

Methods

 o kill
 void kill()
Stops all threads and enters the S_STOPNOW state.

 o run
 public void run()
Main loop - handles everything, controled by state.

 o paint
 public void paint(Graphics g)
Repaints the window using the off-screen image.

Parameters:
g - the Graphics context
Overrides:
paint in class Canvas
 o update
 public void update(Graphics g)
Repaints the window using the off-screen image.

Parameters:
g - the Graphics context
Overrides:
update in class Component
 o 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
 o 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
 o initOffGr
 synchronized boolean initOffGr()
Initializes the off-screen and background images.

 o 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
 o 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
 o 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
 o 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
 o explodeAllBlocks
 void explodeAllBlocks()
Clears the whole field of all blocks.

 o msg
 public void msg(String s)
Displays a string on the message line for some seconds.

Parameters:
s - the string to be displayed
 o shoot
 synchronized void shoot()
Shoots a bullet from the current paddle position. At most one bullet can be active at a time.

 o 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
 o removeBullets
 void removeBullets()
Removes all bullets, for example if a game is ended.

 o 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
 o posRand
 public int posRand(int max)
Calculates a random positive integer.

Parameters:
max - the maximum value
Returns:
-1<;rc<max
 o 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
 o addBombTarget
 void addBombTarget(Point p)
Adds a location to the bomb target vector.

Parameters:
p - the point to be added, in block space
 o 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
 o update
 public void update()
Calls update.update

See Also:
update
 o 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
 o ms
 public int ms()
Returns the number of ms waited between two ticks.

Returns:
s timer.ms
 o getItem
 public Rectangle getItem(int x,
                          int y)
 o _update
 public Update _update()
 o _paddle
 public Rectangle _paddle()
 o _fieldWidth
 public int _fieldWidth()
 o _fieldHeight
 public int _fieldHeight()
 o _blockwidth
 public int _blockwidth()
 o _blockheight
 public int _blockheight()
 o _imgwidth
 public int _imgwidth()
 o _imgheight
 public int _imgheight()