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

📄 resource.java

📁 初学者的佳音 初学者的佳音 初学者的佳音 初学者的佳音 初学者的佳音
💻 JAVA
字号:
package game;

import javax.microedition.lcdui.*;
import lib.*;
import com.nokia.mid.sound.*;

public class Resource{

  private static Resource resource=new Resource();

  public static Resource getResource(){
    return resource;
  }

  private Resource(){
    if(isMIPD2_0){
      openMedia=new Media("/music/open.mid",Media.TYPE_MIDI,false);
      backMedia=new Media("/music/back.mid",Media.TYPE_MIDI,true);
      winMedia=new Media("/music/win.mid",Media.TYPE_MIDI,false);
      loseMedia=new Media("/music/lose.mid",Media.TYPE_MIDI,false);
    }
    else{
      openSound=new Sound(openData,Sound.FORMAT_TONE);
      winSound=new Sound(winData,Sound.FORMAT_TONE);
      loseSound=new Sound(loseData,Sound.FORMAT_TONE);
      openData=null;
      winData=null;
      loseData=null;
    }
  }

  public boolean isMIPD2_0=false;

  //图片
  public Image imgLogo2;
  public Image imgLogo5;

  public Image imgMenuBack;
  public Image imgMenuText;
  public Image imgMenuBoard;

  public Image imgLevel1Tiles;
  public Image imgLevel2Tiles;
  public Image imgLevel3Tiles;
  public Image imgLevel1Back;
  public Image imgLevel2Back;
  public Image imgLevel3Back;
  public Image imgActor;
  public Image imgMonkey;
  public Image imgProp;
  public Image imgText;
  public Image imgCayman;
  public Image imgGameMenu;
  public Image imgTiger;
  public Image imgBlood;

  //音乐
  public Media openMedia;
  public Media backMedia;
  public Media winMedia;
  public Media loseMedia;

  public Sound openSound;
  public Sound winSound;
  public Sound loseSound;

  public boolean sound=true;

  //单音调
  private byte[] winData={
      (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
      (byte)0x04, (byte)0x00, (byte)0x21, (byte)0x1e,
      (byte)0x83, (byte)0x10, (byte)0x21, (byte)0x02,
      (byte)0x70, (byte)0x31, (byte)0x03, (byte)0x88,
      (byte)0x20, (byte)0xc3, (byte)0x50, (byte)0x21,
      (byte)0x03, (byte)0x90, (byte)0x21, (byte)0x04,
      (byte)0x91, (byte)0x81, (byte)0x08, (byte)0x13,
      (byte)0x20, (byte)0x00
  };
  private byte[] loseData={
      (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
      (byte)0x04, (byte)0x00, (byte)0x1b, (byte)0x1c,
      (byte)0x83, (byte)0x8c, (byte)0x39, (byte)0x02,
      (byte)0x10, (byte)0x38, (byte)0xc3, (byte)0x90,
      (byte)0x21, (byte)0x03, (byte)0x8c, (byte)0x32,
      (byte)0xc4, (byte)0x95, (byte)0x61, (byte)0x58,
      (byte)0x00, (byte)0x00
  };
  private byte[] openData={
      (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
      (byte)0x04, (byte)0x00, (byte)0x2d, (byte)0x22,
      (byte)0xa2, (byte)0x91, (byte)0x21, (byte)0x02,
      (byte)0x14, (byte)0x23, (byte)0x12, (byte)0x10,
      (byte)0x21, (byte)0x42, (byte)0x91, (byte)0x25,
      (byte)0x12, (byte)0x10, (byte)0x21, (byte)0x42,
      (byte)0x31, (byte)0x21, (byte)0x02, (byte)0x14,
      (byte)0x49, (byte)0xb8, (byte)0x99, (byte)0x89,
      (byte)0x04, (byte)0x10, (byte)0xa2, (byte)0x0c,
      (byte)0xc4, (byte)0x00
  };
  public String helpString=
      "游戏简介:\n"+
      "帝企鹅厌倦了动物园里枯燥的生活,决定去外面的世界闯一闯。但是它能躲开一路上顽皮的猴子、危险的鳄鱼和凶猛的老虎吗?于是帝企鹅开始了奇妙的逃亡日记。\n"+
      "\n"+
      "游戏规则:\n"+
      "玩家控制企鹅跳跃躲避通过所有障碍及敌人即过关。游戏共包含三关。\n"+
      "\n"+
      "操作说明:\n"+
      "方向键左右    移动\n"+
      "数字键2/上键  上跳\n"+
      "数字键1,3    斜跳\n"+
      "左软键       暂停\n"+
      "右软键       退出\n";
  public String aboutString=
      "版权所属:\n"+
      "李海洋\n"+
      "MSN:\n"+
      "oceanlee8055@hotmail.com";

  //数据
  public int[] data=new int[13];

  //载入logo
  public void loadLogo(){
    try{
      imgLogo2=Image.createImage("/image/logo2.png");
      imgLogo5=Image.createImage("/image/logo5.png");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //释放logo
  public void releaseLogo(){
    imgLogo2=null;
    imgLogo5=null;
    System.gc();
  }
  //载入菜单
  public void loadMenu(){
    try{
      imgMenuBack=Image.createImage("/image/menuback.png");
      imgMenuText=Image.createImage("/image/menutext.png");
      imgMenuBoard=Image.createImage("/image/menuboard.png");
      imgText=Image.createImage("/image/text.png");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //释放菜单
  public void releaseMenu(){
    imgMenuBack=null;
    imgMenuText=null;
    imgMenuBoard=null;
    imgText=null;
    System.gc();
  }
  //载入关卡1
  public void loadLevel1Game(){
    try{
      imgActor=Image.createImage("/image/actor.png");
      imgProp=Image.createImage("/image/prop.png");
      imgText=Image.createImage("/image/text.png");
      imgLevel1Tiles=Image.createImage("/image/level1tiles.png");
      imgLevel1Back=Image.createImage("/image/level1back.png");
      imgMonkey=Image.createImage("/image/monkey.png");
      imgGameMenu=Image.createImage("/image/gamemenu.png");
      imgBlood=Image.createImage("/image/blood.png");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //释放关卡1
  public void releaseLevel1Game(){
    imgActor=null;
    imgProp=null;
    imgText=null;
    imgLevel1Tiles=null;
    imgLevel1Back=null;
    imgMonkey=null;
    imgGameMenu=null;
    imgBlood=null;
    System.gc();
  }
  //载入关卡2
  public void loadLevel2Game(){
    try{
      imgActor=Image.createImage("/image/actor.png");
      imgProp=Image.createImage("/image/prop.png");
      imgText=Image.createImage("/image/text.png");
      imgLevel2Tiles=Image.createImage("/image/level2tiles.png");
      imgLevel2Back=Image.createImage("/image/level2back.png");
      imgCayman=Image.createImage("/image/cayman.png");
      imgGameMenu=Image.createImage("/image/gamemenu.png");
      imgBlood=Image.createImage("/image/blood.png");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //释放关卡2
  public void releaseLevel2Game(){
    imgActor=null;
    imgProp=null;
    imgText=null;
    imgLevel2Tiles=null;
    imgLevel2Back=null;
    imgCayman=null;
    imgGameMenu=null;
    imgBlood=null;
    System.gc();
  }
  //载入关卡3
  public void loadLevel3Game(){
    try{
      imgActor=Image.createImage("/image/actor.png");
      imgProp=Image.createImage("/image/prop.png");
      imgText=Image.createImage("/image/text.png");
      imgLevel3Tiles=Image.createImage("/image/level3tiles.png");
      imgLevel3Back=Image.createImage("/image/level3back.png");
      imgMonkey=Image.createImage("/image/monkey.png");
      imgGameMenu=Image.createImage("/image/gamemenu.png");
      imgTiger=Image.createImage("/image/tiger.png");
      imgCayman=Image.createImage("/image/cayman.png");
      imgBlood=Image.createImage("/image/blood.png");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //释放关卡3
  public void releaseLevel3Game(){
    imgActor=null;
    imgProp=null;
    imgText=null;
    imgLevel2Tiles=null;
    imgLevel2Back=null;
    imgMonkey=null;
    imgGameMenu=null;
    imgMonkey=null;
    imgTiger=null;
    imgCayman=null;
    imgBlood=null;
    System.gc();
  }
  //设置关卡数据
  public void setGateData(int level,int score){
    data[11]=level;
    data[12]=score;
  }
  //设置排行榜数据
  public void addHiscoreData(int score){
    data[10]=score;
    Toolkit.sort(data,11,true);
  }
  //写数据
  public void saveData(){
    try{
      Toolkit.writeData(data);
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  //读数据
  public void readData(){
    try{
      Toolkit.readData(data);
    }catch(Exception e){
      e.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

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