Java Reference
In-Depth Information
class
Paddle
{
public static final
int
WIDTH = 5 0 ;
public static final
int
HEIGHT = 1 0 ;
public static final
int
START X = 200;
public static final
int
START Y = 430;
private
Color color ;
private int
x, y;
public
Paddle(Color color)
{
this
. color = color ;
x=STARTX;
y=STARTY;
}
public void
draw(Graphics2D g2)
{
g2 . setPaint ( color ) ;
Rectangle2D r =
new
Rectangle2D .Double(x, y, WIDTH, HEIGHT) ;
g2. fill (r);
}
}
class
Brick
{
public static final
int
HEIGHT = 1 0 ;
public static final
int
WIDTH = 3 0 ;
public static final
int
BRICK H GAP = 2 ;
public static final
int
BRICK V GAP = 2 ;
private int
x, y;
private
Color
color ;
public
Brick(
int
row ,
int
col , Color color)
{
this
. color = color ;
x=BRICKH GAP + row
∗
(BRICK H GAP + B r i c k . WIDTH) ;
y=BRICKV GAP + c o l
∗
(BRICK V GAP + B r i c k . HEIGHT) ;
}
{
public void
draw(Graphics2D g2)
g2 . setPaint ( color ) ;
Rectangle2D r =
new
Rectangle2D .Double(x, y, WIDTH, HEIGHT) ;
g2. fill (r);
}
}
class
Player
{
public static int
INITIAL NUM LIVES = 3 ;
public static int
IMAGE DISTANCE = 4 0 ;
public static int
IMAGE Y = 450;
private int
numLives ;
public
Player ()
{
this
. numLives = INITIAL NUM LIVES ;
}
public void
killPlayer()
{
numLives
−−
;