// ## JAVANOID STATUS CLASS ####################################
// This class maintains and displays
the state of the game (score, lives
// & level). It the specialist
for string displays. It may be extended for
// displays such as game loading
or instructions.
// strings for display
final static String appletString1 = "JAVANOID
V1.45";
final static String appletString2 = "by
Remi Faitout";
final static String scoreString
= "SCORE : ";
final static String levelString
= "LEVEL : ";
final static String livesString
= "LIVES : ";
final static String hiScoreString = "HIGH
SCORE :";
// default game settings
final static int nbLives = 2;
final static int maxLives = 5;
final static int lifeSize = 12;
final static int hitScore = 10;
final static int bonusScore = 100;
final static int levelScore = 500;
// status values
protected int hiScore = 1000;
protected int score = 0;
protected int lives = 0;
protected int level = 0;
// String positions
protected int scoreX, scoreXX, livesX,
livesXX, levelX, namesX;
protected int statusY, textY, namesY;
protected int width, height;
protected int livesWidth, scoreWidth, levelWidth;
// display the level name
or not
protected boolean nameDisplay;
jnbuffer
buffer;
jnimageserver
imageSrv;
// »ý¼ºÀÚ
public jnstatus(jnbuffer c, jnimageserver
i, int alt1, int alt2 ) {
buffer = c;
imageSrv = i;
width = buffer.getWidth();
height = buffer.getStringHeight();
livesX = 1 * width / 18;
levelX = 8 * width / 18;
scoreX = 13 * width / 18;
namesX = width / 2;
livesXX = livesX + buffer.getStringWidth(livesString);
scoreXX = scoreX + buffer.getStringWidth(scoreString);
statusY = buffer.getHeight() - alt1;
namesY = buffer.getHeight() - alt2;
nameDisplay = false;
}
// À§·Î
// Actions on the status
: add or remove
public void addLife() {
if (lives<maxLives)
buffer.drawPermanentImage(imageSrv.ballImage(0),
livesXX + lives * lifeSize, statusY);
lives++;
}
// À§·Î
public void removeLife() {
lives--; set();}
public void addLevel() {
level++; score+=levelScore; set();}
public void addScore() {
score+=hitScore; setScore();}
public void addBonus() {
score+=bonusScore; set(); }
// hiding or showing the
level name
public void showName(String s) {
nameDisplay = true;
buffer.drawPermanentString(s, namesX -
buffer.getStringWidth(s) / 2, namesY + height);
}
// À§·Î
public void hideName() {
if (nameDisplay) buffer.clearPermanentImage(0,
namesY, width, height);
}
// À§·Î
public void showHiScore() {
String s1 = appletString1;
String s2 = appletString2;
String s3 = hiScoreString + hiScore;
int h = (int)(height/2);
buffer.drawPermanentString(s1, namesX
- buffer.getStringWidth(s1) / 2, namesY - 2*h);
buffer.drawPermanentString(s2, namesX
- buffer.getStringWidth(s2) / 2, namesY + h);
buffer.drawPermanentString(s3, namesX
- buffer.getStringWidth(s3) / 2, namesY + 5*h);
}
// À§·Î
// reset & set (partial
or not) : Draw the status on the buffer
public void reset() {
if (score > hiScore) hiScore = score;
lives = nbLives; level = 1; score = 0;
set();
}
// À§·Î
void set() {
buffer.clearPermanentImage(0, statusY,
width, height);
buffer.drawPermanentString(livesString,
livesX, statusY + height);
for (int i=0;i<lives;i++) {
if (i<maxLives)
buffer.drawPermanentImage(imageSrv.ballImage(0),
livesXX + i * lifeSize, statusY);
}
buffer.drawPermanentString(levelString
+ level, levelX, statusY + height);
buffer.drawPermanentString(scoreString
+ score, scoreX, statusY + height);
}
// À§·Î
void setScore() {
buffer.clearPermanentImage(scoreXX, statusY,
width - scoreXX, height);
buffer.drawPermanentString(String.valueOf(score),
scoreXX, statusY + height);
}
// À§·Î
public int getLives() {
return lives; }
}
// À§·Î