home *** CD-ROM | disk | FTP | other *** search
- package LockemUp;
-
- import com.siemens.mp.game.ExtendedImage;
- import com.siemens.mp.game.GraphicObjectManager;
- import com.siemens.mp.game.Sprite;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.List;
- import javax.microedition.rms.RecordStore;
-
- public class LevelScreen extends BaseScreen {
- private static final int GAME_SCREEN_WIDTH = 96;
- private static final int GAME_SCREEN_HEIGHT = 80;
- private static final int BLINK_TIMER = 4;
- private static final int[] LEVELMAPCOUNT = new int[]{5, 10, 5, 5, 5, 10};
- private static final String MENU_DATA = "res\\menu.bin";
- private static final String NUM_TILES = "res\\num.bin";
- private static final String[] LEVELNAME = new String[]{"Learning", "Beginning", "Switch", "Death", "Jumper", "Master"};
- private static final String GAMERECORD = "REC";
- private byte[] records;
- private boolean modified;
- private int maxLevel;
- private int maxMap;
- private int level = 0;
- private int map = 0;
- private long timer;
- private CommandListener listener;
- private int state;
- private boolean running;
- private boolean readyToPaint;
- private Image gameScreenImage;
- private ExtendedImage gameScreen;
- private GraphicObjectManager gfxManager;
- private Sprite levelSpr;
- private Sprite mapSpr;
- private boolean blink;
- private boolean visible;
- private int blinkTimer;
- private boolean repaintFlag;
- private byte[] pixels;
- private int menuShow;
- private Image menu;
- private ExtendedImage menuEx;
-
- public LevelScreen() {
- try {
- this.gameScreenImage = Image.createImage(96, 80);
- this.gameScreen = new ExtendedImage(this.gameScreenImage);
- this.gfxManager = new GraphicObjectManager();
- this.pixels = ((BaseScreen)this).ReadByteArray("res\\num.bin", 42, 0);
- byte[] var2 = new byte[42];
-
- for(int var1 = 0; var1 < 42; ++var1) {
- var2[var1] = -2;
- }
-
- this.levelSpr = new Sprite(this.pixels, 0, 8, 7, var2, 0, 6);
- Object var6 = null;
- this.pixels = ((BaseScreen)this).ReadByteArray("res\\num.bin", 77, 0);
- byte[] var7 = new byte[77];
-
- for(int var5 = 0; var5 < 77; ++var5) {
- var7[var5] = -2;
- }
-
- this.mapSpr = new Sprite(this.pixels, 0, 8, 7, var7, 0, 11);
- Object var8 = null;
- this.gfxManager.addObject(this.levelSpr);
- this.gfxManager.addObject(this.mapSpr);
- this.pixels = ((BaseScreen)this).ReadByteArray("res\\menu.bin", 960, 0);
- this.menu = Image.createImage(24, 8);
- this.menuEx = new ExtendedImage(this.menu);
- this.menuEx.setPixels(((BaseScreen)this).ReadByteArray("res\\menu_sprite.bin", 24, 0), 0, 0, 24, 8);
- } catch (Exception var4) {
- System.out.println("Exception: " + var4);
- }
-
- this.modified = false;
- this.records = new byte[80];
- this.timer = 0L;
- this.blink = false;
- this.visible = true;
- this.state = 0;
- this.readyToPaint = true;
- this.repaintFlag = true;
- }
-
- public void Dispose() {
- this.menuEx = null;
- this.gameScreen = null;
- this.gfxManager = null;
- }
-
- public void loadRecords() {
- for(int var1 = 0; var1 < 80; ++var1) {
- this.records[var1] = 0;
- }
-
- try {
- RecordStore var3 = RecordStore.openRecordStore("REC", true);
- byte[] var4 = new byte[2];
- if (var3.getNumRecords() > 0) {
- var3.getRecord(1, this.records, 0);
- var3.getRecord(2, var4, 0);
- this.maxLevel = var4[0];
- this.level = this.maxLevel - 1;
- this.maxMap = var4[1];
- this.map = this.maxMap - 1;
- } else {
- var4[0] = 1;
- var4[1] = 1;
- var3.addRecord(this.records, 0, 80);
- var3.addRecord(var4, 0, 2);
- this.maxLevel = 1;
- this.level = 0;
- this.maxMap = 1;
- this.map = 0;
- }
-
- var3.closeRecordStore();
- } catch (Exception var5) {
- System.out.println("Exception: " + var5);
- }
-
- }
-
- public void saveRecords() {
- try {
- if (this.modified) {
- RecordStore var2 = RecordStore.openRecordStore("REC", true);
- byte[] var3 = new byte[]{(byte)this.maxLevel, (byte)this.maxMap};
- if (var2.getNumRecords() > 0) {
- var2.setRecord(1, this.records, 0, 80);
- var2.setRecord(2, var3, 0, 2);
- } else {
- var2.addRecord(this.records, 0, 80);
- var2.addRecord(var3, 0, 2);
- }
-
- var2.closeRecordStore();
- this.modified = false;
- }
- } catch (Exception var4) {
- System.out.println("Exception: " + var4);
- }
-
- }
-
- public void resetStateValue() {
- this.state = 0;
- this.repaintFlag = true;
- this.gameScreen.clear((byte)0);
- }
-
- public void setStateValue(int var1) {
- this.state = var1;
- this.repaintFlag = false;
- this.gameScreen.clear((byte)0);
- Font var2 = Font.getFont(0, 1, 8);
- this.gameScreenImage.getGraphics().setFont(var2);
- int var3 = var2.stringWidth("Please wait...");
- int var4 = var2.getHeight();
- int var5 = (96 - var3) / 2;
- int var6 = (80 - var4) / 2;
- this.gameScreenImage.getGraphics().drawString("Please wait...", var5, var6, 20);
- var5 -= 2;
- var6 -= 2;
- this.gameScreenImage.getGraphics().drawRect(var5, var6, var3 + 3, var4 + 3);
- var5 -= 2;
- var6 -= 2;
- this.gameScreenImage.getGraphics().drawRect(var5, var6, var3 + 7, var4 + 7);
- this.gameScreen.blitToScreen(0, 0);
- }
-
- public void startTimer() {
- this.timer = System.currentTimeMillis();
- }
-
- public void stopTimer() {
- this.timer = (System.currentTimeMillis() - this.timer) / 1000L;
- if (this.timer > 5999L) {
- this.timer = 5999L;
- }
-
- if ((long)this.getBestTimeOfCurrentLevel() > this.timer) {
- this.records[2 * this.getMapNum()] = (byte)((int)(this.timer / 60L));
- this.records[2 * this.getMapNum() + 1] = (byte)((int)(this.timer % 60L));
- this.modified = true;
- if (this.level == this.maxLevel - 1 && this.map == this.maxMap - 1) {
- if (this.maxMap < LEVELMAPCOUNT[this.level]) {
- ++this.maxMap;
- } else if (this.maxLevel < 6) {
- ++this.maxLevel;
- this.maxMap = 1;
- }
- }
- }
-
- }
-
- public void startBlink() {
- this.blink = true;
- this.blinkTimer = 4;
- this.visible = true;
- }
-
- public void stopBlink() {
- this.blink = false;
- this.visible = true;
- }
-
- public String getTimeOfThisTurn() {
- int var2 = (int)(this.timer / 60L);
- String var1;
- if (var2 < 10) {
- var1 = "0" + String.valueOf(var2);
- } else {
- var1 = String.valueOf(var2);
- }
-
- var2 = (int)(this.timer % 60L);
- if (var2 < 10) {
- var1 = var1 + ":0" + var2;
- } else {
- var1 = var1 + ":" + var2;
- }
-
- return var1;
- }
-
- public int getReturnValue() {
- return this.state < 40 ? this.getMapNum() : this.state;
- }
-
- public int nextMap() {
- if (this.map < LEVELMAPCOUNT[this.level] - 1) {
- ++this.map;
- } else {
- this.map = 0;
- this.level = (this.level + 1) % 6;
- }
-
- return this.getMapNum();
- }
-
- public int getMapNum() {
- return this.computeMapNum(this.level, this.map);
- }
-
- public String getStringOfBestTime() {
- if (this.level < this.maxLevel && (this.level != this.maxLevel - 1 || this.map < this.maxMap)) {
- if (this.level != this.maxLevel - 1 || this.map != this.maxMap - 1 || this.maxLevel == 6 && this.maxMap == 10) {
- if (this.level == 5 && this.map == 9 && this.records[78] == 0 && this.records[79] == 0) {
- return "NO REC";
- } else {
- int var3 = this.getMapNum();
- byte var2 = this.records[2 * var3];
- String var1;
- if (var2 < 10) {
- var1 = "0" + String.valueOf(var2);
- } else {
- var1 = String.valueOf(var2);
- }
-
- var2 = this.records[2 * var3 + 1];
- if (var2 < 10) {
- var1 = var1 + ":0" + var2;
- } else {
- var1 = var1 + ":" + var2;
- }
-
- return var1;
- }
- } else {
- return "NO REC";
- }
- } else {
- return "LOCKED";
- }
- }
-
- public void run() {
- int var1 = 11;
- this.running = true;
-
- while(this.running) {
- try {
- Thread.sleep(20L);
- if (this.blink) {
- --this.blinkTimer;
- if (this.blinkTimer <= 0) {
- this.visible = !this.visible;
- this.blinkTimer = 4;
- this.repaintFlag = true;
- }
- }
-
- if (this.repaintFlag) {
- Font var2 = Font.getFont(0, 0, 8);
- this.gameScreen.setPixels(this.pixels, 0, 0, 96, 80);
- this.gameScreenImage.getGraphics().setColor(16777215);
- if (LEVELMAPCOUNT[this.level] == 5) {
- this.gameScreenImage.getGraphics().fillRect(35, 49, 50, 9);
- }
-
- this.gameScreenImage.getGraphics().setFont(var2);
- this.gameScreenImage.getGraphics().drawString(LEVELNAME[this.level], 36, 20, 20);
- if (this.visible) {
- this.gameScreenImage.getGraphics().drawString(this.getStringOfBestTime(), 48, 66, 20);
- }
-
- this.gameScreenImage.getGraphics().setColor(0);
- if (this.level >= this.maxLevel) {
- var1 = 0;
- } else if (this.level == this.maxLevel - 1) {
- var1 = this.maxMap;
- } else {
- var1 = 11;
- }
-
- while(var1 < LEVELMAPCOUNT[this.level]) {
- this.gameScreenImage.getGraphics().fillRect(38 + var1 % 5 * 10, 39 + var1 / 5 * 12, 5, 5);
- ++var1;
- }
-
- this.drawMapNum();
- this.drawLevelNum();
- this.gfxManager.paint(this.gameScreen, 0, 0);
- this.repaintFlag = false;
- }
-
- ((Canvas)this).repaint();
- } catch (Exception var3) {
- }
-
- if (this.state != 0) {
- this.running = false;
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- boolean var2 = true;
- if (this.gameScreen != null && this.readyToPaint) {
- try {
- this.gameScreen.blitToScreen(0, 0);
- } catch (Exception var4) {
- System.out.println("Exception: " + var4);
- }
- }
-
- if (this.state == 0) {
- if ((this.menuShow++ & 8) != 0) {
- this.menuEx.blitToScreen(80, 67);
- } else {
- var1.setColor(255, 255, 255);
- var1.fillRect(96, 67, 5, 8);
- }
- }
-
- }
-
- public void setCommandListener(CommandListener var1) {
- super.setCommandListener(var1);
- this.listener = var1;
- }
-
- protected void keyPressed(int var1) {
- if (var1 == -12) {
- this.listener.commandAction(List.SELECT_COMMAND, this);
- } else if (!this.repaintFlag) {
- this.repaintFlag = true;
- int var2 = ((Canvas)this).getGameAction(var1);
- switch (var2) {
- case 1:
- if (this.level > 0) {
- --this.level;
- }
-
- if (this.map >= LEVELMAPCOUNT[this.level]) {
- this.map = LEVELMAPCOUNT[this.level] - 1;
- }
-
- this.stopBlink();
- break;
- case 2:
- if (this.map > 0) {
- --this.map;
- }
-
- this.stopBlink();
- case 3:
- case 4:
- default:
- break;
- case 5:
- if (this.map < LEVELMAPCOUNT[this.level] - 1) {
- ++this.map;
- }
-
- this.stopBlink();
- break;
- case 6:
- if (this.level < 5) {
- ++this.level;
- }
-
- if (this.map >= LEVELMAPCOUNT[this.level]) {
- this.map = LEVELMAPCOUNT[this.level] - 1;
- }
-
- this.stopBlink();
- }
-
- }
- }
-
- private void drawLevelNum() {
- this.levelSpr.setPosition(9, 19 + this.level * 10);
- this.levelSpr.setFrame(this.level);
- }
-
- private void drawMapNum() {
- this.mapSpr.setPosition(37 + this.map % 5 * 10, 38 + this.map / 5 * 12);
- if (this.level >= this.maxLevel) {
- this.mapSpr.setFrame(10);
- } else if (this.level == this.maxLevel - 1 && this.map >= this.maxMap) {
- this.mapSpr.setFrame(10);
- } else {
- this.mapSpr.setFrame(this.map);
- }
-
- }
-
- private int getBestTimeOfCurrentLevel() {
- int var1 = this.getMapNum();
- var1 = this.records[2 * var1] * 60 + this.records[2 * var1 + 1];
- if (var1 == 0) {
- var1 = 6000;
- }
-
- return var1;
- }
-
- private int computeMapNum(int var1, int var2) {
- int var4 = 0;
-
- for(int var3 = 0; var3 < var1; ++var3) {
- var4 += LEVELMAPCOUNT[var3];
- }
-
- var4 += var2;
- return var4;
- }
- }
-