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

📄 gamecanvas.java

📁 K750手机游戏泡泡龙源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// http://www.codefans.net

import com.nokia.mid.sound.Sound;
import com.nokia.mid.ui.FullCanvas;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

class GameCanvas extends FullCanvas
    implements Runnable, CommandListener
{

    public static final int OFSET = -8;
    public static final int ONSIGN = -1;
    public static final int ONTITLE = 0;
    public static final int ONGAME = 1;
    public static final int ONOPTION = 2;
    public static final int STGOFX = 16;
    public static final int STGOFY = 16;
    public static final int S_PYONPA = 0;
    public static final int S_ERASE = 1;
    public static final int S_SHOT = 2;
    public static final int S_GOVER = 3;
    public static int trX;
    public static int trY;
    private boolean resumeFlag;
    private int iS;
    private int pS;
    private int tgS;
    private int bgS;
    private int mV;
    private int sC;
    private int dR;
    private int lV;
    private int dV;
    private int eC;
    private int bR;
    private int kY;
    private int bobP;
    private int bAnim;
    private int mH;
    private int mS;
    private int eB;
    private int dB;
    private boolean sE;
    private boolean kF;
    private boolean gF;
    private boolean dF;
    private boolean upA;
    private boolean upB;
    private Bobble pA;
    private Font sFont;
    private static final int ARW1[][] = {
        {
            42, 157
        }, {
            42, 156
        }, {
            42, 155
        }, {
            43, 154
        }, {
            44, 154
        }, {
            44, 152
        }, {
            45, 152
        }, {
            45, 151
        }, {
            46, 150
        }, {
            47, 150
        }, {
            47, 149
        }, {
            48, 148
        }, {
            49, 148
        }, {
            50, 147
        }, {
            51, 146
        }, {
            52, 146
        }, {
            53, 145
        }, {
            54, 145
        }, {
            55, 145
        }, {
            56, 146
        }, {
            57, 146
        }, {
            58, 145
        }, {
            59, 146
        }, {
            60, 146
        }, {
            61, 146
        }, {
            62, 147
        }, {
            62, 147
        }, {
            63, 148
        }, {
            64, 148
        }, {
            65, 149
        }, {
            66, 150
        }, {
            67, 150
        }, {
            67, 151
        }, {
            67, 152
        }, {
            68, 153
        }, {
            69, 154
        }, {
            69, 155
        }, {
            70, 155
        }, {
            70, 157
        }, {
            71, 158
        }, {
            71, 159
        }, {
            70, 160
        }, {
            70, 161
        }
    };
    private static final int ARW2[][] = {
        {
            42, 161
        }, {
            42, 160
        }, {
            41, 159
        }, {
            41, 158
        }, {
            42, 157
        }, {
            42, 155
        }, {
            43, 155
        }, {
            43, 154
        }, {
            44, 153
        }, {
            45, 152
        }, {
            45, 151
        }, {
            45, 150
        }, {
            46, 150
        }, {
            47, 149
        }, {
            48, 148
        }, {
            49, 148
        }, {
            50, 147
        }, {
            50, 147
        }, {
            51, 146
        }, {
            52, 146
        }, {
            53, 146
        }, {
            54, 145
        }, {
            55, 146
        }, {
            56, 146
        }, {
            57, 145
        }, {
            58, 145
        }, {
            59, 145
        }, {
            60, 146
        }, {
            61, 146
        }, {
            62, 147
        }, {
            63, 148
        }, {
            64, 148
        }, {
            65, 149
        }, {
            65, 150
        }, {
            66, 150
        }, {
            67, 151
        }, {
            67, 152
        }, {
            68, 152
        }, {
            68, 154
        }, {
            69, 154
        }, {
            70, 155
        }, {
            70, 156
        }, {
            70, 157
        }
    };
    private PzBb4Nokia owM;
    private Image pI;
    private Image sI;
    private Image nI;
    private Image bI;
    private Image oI;
    private Image eI;
    private Image rI;
    private Image tI;
    public Image ofSc1;
    public Image ofSc2;
    public Graphics ofSg2;
    public Image ofSc3;
    public Image bomI[];
    public Image awaI[];
    public Image plyI[];
    public Image numI[];
    private int aWidth;
    private Sound sD[];
    private int theGain;
    private RecordStore rStore;
    private int indeX;
    private Form hForm;
    private StringItem strItem[];
    private Command cBack;
    private String pMstr[] = {
        "\n", "Decide with the right and left joystick, the direction of the bubble shot.\n\n", "Push the joystick and the bubble shot will come out.\n\n", "Bubbles will disappear, when more than 3 bubbles in a same color are in a row.\n\n", "Game will be over when bubbles exceed the line in the screen.\n"
    };
    private boolean pauseFlag;

    public GameCanvas(PzBb4Nokia pzbb4nokia)
    {
        resumeFlag = false;
        theGain = 32;
        rStore = null;
        owM = pzbb4nokia;
    }

    private void setSound(String s, int i)
    {
        try
        {
            DataInputStream datainputstream = new DataInputStream(Class.forName("PzBb4Nokia").getResourceAsStream("/" + s));
            int j = datainputstream.readInt();
            int k = datainputstream.read();
            int l = datainputstream.read();
            int i1 = datainputstream.read();
            int j1 = datainputstream.read();
            int k1 = (j1 << 24) + (i1 << 16) + (l << 8) + (k << 0) + 8;
            datainputstream.close();
            datainputstream = new DataInputStream(Class.forName("PzBb4Nokia").getResourceAsStream("/" + s));
            byte abyte0[] = new byte[k1];
            datainputstream.read(abyte0, 0, k1);
            datainputstream.close();
            sD[i] = new Sound(abyte0, 5);
        }
        catch(Exception exception) { }
    }

    private boolean loadImages()
    {
        try
        {
            awaI = new Image[8];
            for(int i = 0; i < awaI.length; i++)
                awaI[i] = Image.createImage("/awa" + (i + 1) + ".png");

            numI = new Image[10];
            for(int j = 0; j < numI.length; j++)
                numI[j] = Image.createImage("/num" + j + ".png");

            bomI = new Image[6];
            for(int k = 0; k < bomI.length; k++)
                bomI[k] = Image.createImage("/bom" + (k + 1) + ".png");

            plyI = new Image[5];
            plyI[0] = Image.createImage("/bub1.png");
            plyI[1] = Image.createImage("/bub2.png");
            plyI[2] = Image.createImage("/bub3.png");
            plyI[3] = Image.createImage("/bub4.png");
            plyI[4] = Image.createImage("/bub5.png");
            return true;
        }
        catch(Exception exception)
        {
            return false;
        }
    }

    public boolean setBGImage()
    {
        try
        {
            ofSc1 = Image.createImage("/bgH.png");
            ofSc3 = Image.createImage("/sg.png");
            ofSc2 = Image.createImage(ofSc3.getWidth(), ofSc3.getHeight());
            ofSg2 = ofSc2.getGraphics();
            return true;
        }
        catch(Exception exception)
        {
            return false;
        }
    }

    public void initSign()
    {
        tgS = -1;
        try
        {
            if(nI == null)
                nI = Image.createImage("/nT.png");
        }
        catch(Exception exception) { }
        Thread thread = new Thread(this);
        thread.start();
    }

    public void pbInit()
    {
        try
        {
            rStore = RecordStore.openRecordStore("pbRS", true);
        }
        catch(Exception exception) { }
        loadData();
        loadImages();
        setBGImage();
        sD = new Sound[3];
        setSound("pyonpa.wav", 0);
        setSound("erase.wav", 1);
        setSound("shot.wav", 2);
        strItem = new StringItem[pMstr.length];
        for(int i = 0; i < pMstr.length; i++)
            strItem[i] = new StringItem("", pMstr[i]);

        cBack = new Command("back", 2, 1);
        hForm = new Form("Help");
        for(int j = 0; j < pMstr.length; j++)
            hForm.append(strItem[j]);

        hForm.addCommand(cBack);
        hForm.setCommandListener(this);
    }

    public void initTitle()
    {
        tgS = 0;
        bgS = 0;
        try
        {
            if(pI == null)
                pI = Image.createImage("/pbTitle.png");
            if(sI == null)
                sI = Image.createImage("/taito.png");
            if(bI == null)
                bI = Image.createImage("/backW.png");
            if(oI == null)

⌨️ 快捷键说明

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