import javax.microedition.lcdui.*; import java.util.*; class PointCounter{ int points=0; int lives=3; int generalLevel=1; int eggLevel=1; int speedLevel=1; int speed=300; int wait=0; // waits... int[] levelBorder={0,10,27,30,50,80,120,160,220,300,400,500,600,700,800,900,1000}; int[] eggCountBorder={0,5,27,150,1000}; int[] speedBorder={0,2,15,50,100,300,600,900}; Point pointsPos=new Point(48,40); Point livesPos=new Point(48,45); Point eraseBoxCorner = new Point(40,40); Point eraseBoxSize = new Point(9,9); Point gameOverLogoPos=new Point(25,23); Point gameOverScorePos=new Point(25,28); public PointCounter(int initialPoints, int initialLives, int initialLevel, int initialSpeed, int width, int height) { points=initialPoints; lives=initialLives; generalLevel=initialLevel; speed=initialSpeed; double xAxisMultiplier=(double)width/50.0; double yAxisMultiplier=(double)height/50.0; translatePoint(pointsPos, xAxisMultiplier, yAxisMultiplier); translatePoint(livesPos, xAxisMultiplier, yAxisMultiplier); translatePoint(eraseBoxCorner, xAxisMultiplier, yAxisMultiplier); translatePoint(eraseBoxSize, xAxisMultiplier, yAxisMultiplier); translatePoint(gameOverLogoPos, xAxisMultiplier, yAxisMultiplier); translatePoint(gameOverScorePos, xAxisMultiplier, yAxisMultiplier); } public void translatePoint(Point point, double xAxisMultiplier, double yAxisMultiplier) { point.x = (int)(point.x * xAxisMultiplier); point.y = (int)(point.y * yAxisMultiplier); } public void draw(Graphics g) { // erase previous score g.setColor(255,255,255); g.fillRect(eraseBoxCorner.x,eraseBoxCorner.y, eraseBoxSize.x,eraseBoxSize.y); // drow new score g.setColor(0,0,0); g.drawString(""+points, pointsPos.x, pointsPos.y, Graphics.TOP|Graphics.RIGHT); g.drawString(""+lives, livesPos.x, livesPos.y, Graphics.TOP|Graphics.RIGHT); } public void drawGameOver(Graphics g) { g.setColor(0,0,0); g.drawString("Game Over", gameOverLogoPos.x, gameOverLogoPos.y, Graphics.TOP|Graphics.HCENTER); g.drawString("Score: "+points, gameOverScorePos.x, gameOverScorePos.y, Graphics.TOP|Graphics.HCENTER); } public boolean isLevelJump() { return points==levelBorder[generalLevel]; } public boolean isEggCountJump() { return points==eggCountBorder[eggLevel]; } public boolean isSpeedJump() { return points==speedBorder[speedLevel]; } public boolean isTimeToAddNewEgg() { if (isEggCountJump()) { wait=5; eggLevel++; } if (isSpeedJump()) { speed=speed-20; speedLevel++; } if (isLevelJump()) { generalLevel++; lives++; } if (wait>0) { wait--; if (wait==0) { return true; } } return false; } }