⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splashscreen.java

📁 java实现的简单连连看游戏
💻 JAVA
字号:
package com.ismyway.n840_kyodai;

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.rms.*;

/**
 * <p>Title: S60_Kyodai</p>
 * <p>Description: for S60 platform</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: www.ismyway.com</p>
 * @author ZhangJian
 * @version 1.0
 */

public class SplashScreen
    extends GameCanvas
    implements Runnable {
  Thread thread;
  Kyodai kyodai;
  int loadCounter = 1; //已装载的资源文件
  Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                        Font.SIZE_MEDIUM);

  //为动画LOGO准备的
  private byte[] logo; //logo文件
  private int plteOffset = 0;
  private int plteLen = 0;

  private String loading = "Loading...";
  boolean load = false;

  public SplashScreen(Kyodai kyodai) {
    super(false);
    this.kyodai = kyodai;

    logo = getImageBuffer("/res/logo.png");
  }

  public void paint(Graphics g) {
    int fx = 0, fy = 0;
    fx = (CV.srcWidth - f.stringWidth(loading)) >> 1;
    fy = (CV.srcHeight >> 1) - f.getHeight();
    g.setFont(f);
    g.setColor(0);
    g.fillRect(0, 0, CV.srcWidth, CV.srcHeight);
    g.setColor(0xffffff);
    g.drawString(loading, fx, fy, Graphics.LEFT | Graphics.TOP);
    g.drawRect(51, 142, 140, 15);
    g.fillRect(53, 144, loadCounter * 3, 12);

    g.drawImage(Image.createImage(logo, 0, logo.length), 10, 50,
                Graphics.LEFT | Graphics.TOP);
  }

  public void start() {
    thread = new Thread(this);
    thread.start();
  }

  public void run() {
    while (!load) {

      //检测是否支持MMAPI
      try {
        Class.forName("javax.microedition.media.Manager");
        kyodai.supportMMAPI = true;
      }
      catch (ClassNotFoundException ex) {
        kyodai.supportMMAPI = false;
      }
      loadCounter++;
      try {
        thread.sleep(10l);
      }
      catch (InterruptedException ex) {
      }

      //加载图片
      for (int i = 0; i < Kyodai.sprites.length; i++) {
        byte[] b = getImageBuffer("/res/" + i + ".png");
        //Kyodai.ImagesBuffer[i] = getImageBuffer("/res/" + i + ".png");
        Image img = Image.createImage(b, 0, b.length);
        Kyodai.sprites[i] = new Sprite(img);
        loadCounter++;
        repaint();
        try {
          thread.sleep(10l);
        }
        catch (InterruptedException ex) {
          System.out.println("InterruptedException");
        }
      }
      //读取游戏参数
      try {
        RecordStore recordstore = RecordStore.openRecordStore(CV.
            recordStoreName, true);
        int emptyScore = 11 - recordstore.getNumRecords();
        for (int i = 1; i <= emptyScore; i++) {
          byte abyte0[] = kyodai.encodeRecord("Empty", "100");
          recordstore.addRecord(abyte0, 0, abyte0.length);
        }
        for (int i = 1; i <= 11; i++) {
          byte abyte0[] = recordstore.getRecord(i);
          kyodai.decodeRecord(abyte0, kyodai.record[i - 1]);
          loadCounter++;
          repaint();
          try {
            thread.sleep(10l);
          }
          catch (InterruptedException ex) {
            System.out.println("InterruptedException\n" + ex.getMessage());
          }
        }
        recordstore.closeRecordStore();
      }
      catch (RecordStoreException ex) {
      }
      try {
        kyodai.musicMode = Integer.parseInt(kyodai.record[0].getName());
      }
      catch (NumberFormatException ex1) {
        kyodai.musicMode = 8;
      }
      kyodai.gameMode = kyodai.record[0].getScore() & 1;

      load = true;
      //System.out.println(loadCounter);
    }

    stop();
  }

  public void stop() {
    if (thread != null) {
      thread = null;
    }
    /*KyodaiUI kui = new KyodaiUI(kyodai);
         Display.getDisplay(kyodai).setCurrent(kui);
         kui.start();*/
    Display.getDisplay(kyodai).setCurrent(new GameMenu(kyodai));
    //Display.getDisplay(kyodai).setCurrent(new GameMenu(kyodai));
  }

  /**
   * 读取图像
   * @param filename
   * @return
   */
  private byte[] getImageBuffer(String filename) {
    try {
      InputStream is = this.getClass().getResourceAsStream(filename);
      byte[] b = new byte[is.available()];
      is.read(b);
      is.close();
      System.gc();
      return b;
    }
    catch (Exception ex) {
      System.out.println("Error!\n" + ex.toString());
      return null;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -