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

📄 resourcemanager.java

📁 韩国人手机上的J2ME手机游戏哈里波特源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//Download by http://www.codefans.net
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
import media.MediaPlayer;
import media.Vibration;

public class ResourceManager
{

    public ResourceManager(GameCanvas gamecanvas)
    {
        tnum = -1;
        level = 0;
        effectFlag = true;
        soundFlag = true;
        speedFlag = true;
        audio = null;
        gc = gamecanvas;
        img_char = new Image[3];
        try
        {
            i_p = Image.createImage("/i/p.png");
            i_p2 = Image.createImage("/i/p2.png");
            img_icon = Image.createImage("/i/micon.png");
            img_game = Image.createImage("/i/g.png");
        }
        catch(Exception exception) { }
        init();
    }

    public boolean imgCheck(Image image)
    {
        return image != null;
    }

    public void unloadImage()
    {
        img_char[0] = img_char[1] = img_char[2] = img_mon = img_obj = img_magic = img_eff = img_tmp = null;
        ttiledata = tbgdata = tmondata = tobjdata = sobjdata = null;
        scriddata = null;
        System.gc();
    }

    public void imageLoad(byte byte0)
    {
        unloadImage();
        try
        {
            if(byte0 == 3)
            {
                img_obj = Image.createImage("/i/obj.png");
                img_mon = Image.createImage("/i/mon.png");
                img_char[0] = Image.createImage("/i/hL.png");
                img_char[1] = Image.createImage("/i/hR.png");
                img_char[2] = Image.createImage("/i/hI.png");
                img_magic = Image.createImage("/i/mg.png");
                img_eff = Image.createImage("/i/e.png");
            }
        }
        catch(Exception exception) { }
        Runtime.getRuntime().gc();
    }

    public Image getTmp(int i)
    {
        if(tnum != i)
        {
            tnum = i;
            img_tmp = null;
            try
            {
                switch(tnum)
                {
                case 0: // '\0'
                    img_tmp = Image.createImage("/i/gtxt0.png");
                    break;

                case 1: // '\001'
                    img_tmp = Image.createImage("/i/gtxt1.png");
                    break;

                case 2: // '\002'
                    img_tmp = Image.createImage("/i/e0.png");
                    break;

                case 3: // '\003'
                    img_tmp = Image.createImage("/i/e1.png");
                    break;

                case 4: // '\004'
                    img_tmp = Image.createImage("/i/e2.png");
                    break;
                }
            }
            catch(Exception exception) { }
        }
        return img_tmp;
    }

    public Image getBg(int i, int j, int k)
    {
        if(bglvl == leveltile[i] && j == btype && bgorder == k)
            return imgbg;
        btype = j;
        bglvl = leveltile[i];
        bgorder = k;
        String s = j != 0 ? "t" : "b";
        String s1 = null;
        switch(bglvl)
        {
        case 0: // '\0'
            s1 = "d";
            break;

        case 1: // '\001'
            s1 = "h";
            break;

        case 2: // '\002'
            s1 = "f";
            break;

        case 3: // '\003'
            s1 = "c";
            break;

        case 4: // '\004'
            s1 = "o";
            break;
        }
        imgbg = null;
        try
        {
            imgbg = Image.createImage("/i/" + s + s1 + k + ".png");
        }
        catch(Exception exception) { }
        return imgbg;
    }

    public byte[] getImageCoord(int i, int j, int k)
    {
        coord[0] = (byte)(i * j);
        coord[1] = 0;
        coord[2] = (byte)j;
        coord[3] = (byte)k;
        return coord;
    }

    public byte[][] getLevelData(int i)
    {
        if(i == 14)
            return hiddenlevel;
        String s = "data/" + i + ".ln";
        byte abyte0[] = null;
        try
        {
            InputStream inputstream = getClass().getResourceAsStream(s);
            abyte0 = new byte[inputstream.available()];
            inputstream.read(abyte0);
            inputstream.close();
        }
        catch(IOException ioexception)
        {
            return null;
        }
        byte abyte1[][] = new byte[abyte0.length / 6][6];
        for(int j = 0; j < abyte1.length; j++)
        {
            abyte1[j][0] = abyte0[j * 6];
            abyte1[j][1] = abyte0[j * 6 + 1];
            abyte1[j][2] = abyte0[j * 6 + 2];
            abyte1[j][3] = abyte0[j * 6 + 3];
            abyte1[j][4] = abyte0[j * 6 + 4];
            abyte1[j][5] = abyte0[j * 6 + 5];
        }

        abyte0 = null;
        System.gc();
        return abyte1;
    }

    public byte[][] getMapData(int i, byte byte0)
    {
        byte abyte0[][] = null;
        int j = -1;
        for(int k = 0; k < scriddata.length; k++)
        {
            if(i != scriddata[k])
                continue;
            j = k;
            break;
        }

        switch(byte0)
        {
        default:
            break;

        case 0: // '\0'
            abyte0 = tbgdata[j];
            break;

        case 1: // '\001'
            abyte0 = ttiledata[j];
            break;

        case 3: // '\003'
            abyte0 = tmondata[j];
            break;

        case 2: // '\002'
            if(gc.gscreen.hidden)
                abyte0 = sobjdata[j];
            else
                abyte0 = tobjdata[j];
            break;
        }
        return abyte0;
    }

    public boolean loadLevel(int i, byte byte0)
    {
        String s = "data/" + i;
        ttiledata = new byte[46][8][8];
        ResourceManager _tmp = this;
        if(GameCanvas.bg == 1)
            tbgdata = new byte[46][8][8];
        tmondata = new byte[46][4][4];
        if(byte0 == 0)
            tobjdata = new byte[46][4][4];
        scriddata = new byte[46];
        for(int j = 0; j < scriddata.length; j++)
            scriddata[j] = -1;

        sobjdata = new byte[6][4][4];
        System.gc();
        byte abyte0[] = new byte[64];
        byte abyte1[] = new byte[12];
        int k = 0;
        ResourceManager _tmp1 = this;
        if(GameCanvas.bg == 1)
            try
            {
                InputStream inputstream = getClass().getResourceAsStream(s + ".b");
                k = inputstream.read();
                for(int l = 0; l < k; l++)
                {
                    scriddata[l] = (byte)inputstream.read();
                    inputstream.read(abyte0);
                    convertdata(tbgdata[l], abyte0, 8, 8);
                }

                inputstream.close();
            }
            catch(IOException ioexception) { }
        try
        {
            InputStream inputstream1 = getClass().getResourceAsStream(s + ".t");
            k = inputstream1.read();
            for(int i1 = 0; i1 < k; i1++)
            {
                scriddata[i1] = (byte)inputstream1.read();
                inputstream1.read(abyte0);
                convertdata(ttiledata[i1], abyte0, 8, 8);
            }

            inputstream1.close();
        }
        catch(IOException ioexception1) { }
        if(byte0 != 2)
            try
            {
                InputStream inputstream2 = getClass().getResourceAsStream(s + ".o");
                for(int j1 = 0; j1 < k; j1++)
                {
                    inputstream2.read(abyte1);
                    if(byte0 == 1)
                        convertobj(sobjdata[j1], abyte1, 6);
                    else
                        convertobj(tobjdata[j1], abyte1, 6);
                }

                inputstream2.close();
            }
            catch(IOException ioexception2) { }
        try
        {
            InputStream inputstream3 = getClass().getResourceAsStream(s + ".m");
            for(int k1 = 0; k1 < k; k1++)
            {
                inputstream3.read(abyte1);
                convertobj(tmondata[k1], abyte1, 3);
            }

            inputstream3.close();
        }
        catch(IOException ioexception3) { }
        abyte0 = null;
        abyte1 = null;
        System.gc();
        return true;
    }

    public void convertdata(byte abyte0[][], byte abyte1[], int i, int j)
    {
        int k = 0;
        for(int l = 0; l < abyte0.length; l++)
        {
            for(int i1 = 0; i1 < abyte0[l].length; i1++)
            {
                abyte0[l][i1] = abyte1[k];
                k++;
            }

        }

    }

    public void convertobj(byte abyte0[][], byte abyte1[], int i)
    {
        int j = 0;
        int k = 0;
        for(int l = 0; l < abyte1.length; l += 3)
        {
            if(abyte1[l] != -1)
            {
                if(k < abyte0.length)
                {
                    abyte0[k][0] = abyte1[l];
                    abyte0[k][1] = 1;
                    abyte0[k][2] = abyte1[l + 1];
                    abyte0[k][3] = abyte1[l + 2];
                }
                k++;
            }
            j++;
        }

    }

    public void init()
    {
        audio = new MediaPlayer();
        try
        {
            vol = gc.midlet.getSoundOption() + "";
            intVol = Integer.parseInt(vol);
            audio.setVolumeLevel(vol);
        }
        catch(Exception exception) { }
    }

    public void setOption(int i, int j)
    {
        soundFlag = i != 0;
        effectFlag = j != 0;
    }

    public void soundOnOff()
    {
        soundFlag = intVol != 0;
        vol = intVol + "";
        if(!soundFlag)
            stop();
        else
            play(5, false);
    }

    public void effectOnOff()
    {
        effectFlag = !effectFlag;
        gc.midlet.setOption(intVol, effectFlag ? 1 : 0, gc.speedlevel, GameCanvas.bg);
        if(effectFlag)
            setVib(1000);
    }

    public boolean isEffectOn()
    {
        return effectFlag;
    }

    public void play(int i, boolean flag)
    {
        if(audio != null)
            audio.stop();
        if(!soundFlag)
            return;
        Runtime.getRuntime().gc();
        repeatFlag = flag;
        tsound = i;
        audio.setPlayBackLoop(flag);
        audio.setVolumeLevel(vol);
        try
        {

⌨️ 快捷键说明

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