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

📄 gamecanvas.java

📁 仙境传说手机游戏源码 仅适用于NOKIA 游戏画布选择了KONIA自带的类。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-7 11:53:26
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 

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

public class GameCanvas extends FullCanvas
    implements Runnable
{

    void initSound()
    {
        try
        {
            soundData[0] = new byte[19];
            soundData[1] = new byte[31];
            soundData[2] = new byte[194];
            String as[] = {
                "/attack.ott", "/levelup.ott", "/field.ott"
            };
            for(int i = 0; i < 3; i++)
            {
                InputStream inputstream = Runtime.getRuntime().getClass().getResourceAsStream(as[i]);
                inputstream.read(soundData[i]);
                inputstream.close();
            }

            sound[0] = new Sound(soundData[0], 1);
            sound[1] = new Sound(soundData[1], 1);
            sound[2] = new Sound(soundData[2], 1);
        }
        catch(Exception exception) { }
    }

    void play(int i)
    {
        if(!isSound)
            return;
        try
        {
            sound[i].play(1);
        }
        catch(Exception exception) { }
    }

    void stop()
    {
        for(int i = 0; i < 3; i++)
            sound[i].stop();

    }

    GameCanvas()
    {
        sound = new Sound[3];
        soundData = new byte[3][];
        start_x = 0;
        start_y = 0;
        current_state = 0;
        state_index = 0;
        imgs = new Image[30];
        isFirst = true;
        logo_clips = 0;
        backup_time = 0L;
        next_time = 0L;
        isBlank = false;
        menu_index = 0;
        subtype = 0;
        box_height = 0;
        game_tip_progress = 0;
        endingY = 128;
        ending_Mode = 0;
        endingRGB = 0;
        vill_isSub = 0;
        vill_cursor = 0;
        quit = "0-CLOSE";
        isSound = true;
        isVibration = true;
        kaplaCursor = 0;
        storeCursor = 0;
        oriCursor = 0;
        questNo = 0;
        questIng = 0;
        triggerText = null;
        quest_buf = (char[][])null;
        nextOffset = 0;
        face = 0;
        boxStep = 0;
        quest_Str = null;
        triggerNo = 0;
        dragonTailNo = 0;
        MAPX = 0;
        MAPY = 0;
        maps = null;
        isInfoMode = false;
        nowMode = 0;
        messageTime = 0L;
        nowMenus = 0;
        statusCursor = 0;
        statusTop = 0;
        skillCursor = 0;
        skillTop = 0;
        skill_help = "Set * ";
        equipTop = 0;
        equipCursor = 0;
        itemCursor = 0;
        itemTop = 0;
        systemCursor = 0;
        save_done = "Game saved";
        turn = 0;
        dir = 0;
        action = 0;
        player_X = 0;
        player_Y = 0;
        plAniTurn = 0;
        sp_str = "Not enough SP!";
        _nowMonImage = null;
        monsterNo = new int[3];
        monsterAction = new int[3];
        monsterX = new int[3];
        monsterY = new int[3];
        monsterDir = new int[3];
        monsterTurn = new int[3];
        monsterHp = new int[3];
        monsterAngry = new boolean[3];
        monsterThinkTurn = new int[3];
        monImg = new Image[3];
        ran = new Random();
        effectNo = new int[4];
        effectValue = new int[4];
        effectTurn = new int[4];
        effectX = new int[4];
        effectY = new int[4];
        effCurrent = 0;
        SKILL_POINT = 0;
        STATUS_POINT = 0;
        STR = 0;
        VIT = 0;
        INT = 0;
        AGI = 0;
        DEX = 0;
        LUK = 0;
        HP = 0;
        SP = 0;
        WEIGHT = 0;
        LEVEL = 0;
        ZENY = 0;
        EXP = 0;
        SKILLS = new byte[4];
        slots = new byte[2];
        nowArm = new byte[2];
        item_have = new byte[item_names.length];
        engStr = new char[100];
        number_Strs = new byte[20];
        initSound();
        loading(0);
        loadOption();
        System.gc();
    }

    protected void paint(Graphics g)
    {
        if(isFirst)
        {
            start_x = getWidth() / 2;
            start_y = getHeight() / 2;
        }
        switch(current_state)
        {
        case 0: // '\0'
            drawLogo(g);
            break;

        case 1: // '\001'
            drawTitle(g);
            break;

        case 2: // '\002'村庄
            drawVillage(g);
            break;

        case 3: // '\003'
            drawField(g);
            break;

        case 4: // '\004'
            drawEnding(g);
            break;
        }
    }

    protected void keyPressed(int i)
    {
        switch(current_state)
        {
        case 0: // '\0'
            keyLogo(i);
            break;

        case 1: // '\001'
            keyTitle(i);
            break;

        case 2: // '\002'
            keyVillage(i);
            break;

        case 3: // '\003'
            keyField(i);
            break;
        }
    }
    protected void keyReleased(int i)
    {
    	 switch(current_state)
    	 {
    	 case 3:
    		 no_keyField(i);
    	 }
    }
    
//资源载入
    public void loading(int i)
    {
        try
        {
            for(int j = 0; j < imgs.length; j++)
                imgs[j] = null;

            System.gc();
            if(imgs[4] == null)
            {
                imgs[4] = Image.createImage("/words.png");
                imgs[5] = Image.createImage("/words_s.png");
                imgs[6] = Image.createImage("/number.png");
                imgs[7] = Image.createImage("/etc.png");
                imgs[10] = Image.createImage("/cursors.png");
            }
            if(i == 0)
            {
                if(imgs[0] == null)
                {
                    imgs[0] = Image.createImage("/widerthan.png");
                    imgs[1] = Image.createImage("/ci.png");
                    imgs[2] = imgs[1];
                    imgs[3] = Image.createImage("/title.png");
                    imgs[8] = Image.createImage("/face.png");
                    imgs[9] = imgs[1];
                }
            } else
            if(i == 1)
            {
                imgs[0] = imgs[1] = imgs[2] = imgs[3] = imgs[8] = imgs[9] = null;
                System.gc();
                imgs[11] = Image.createImage("/tile.png");
                imgs[12] = Image.createImage("/object.png");
                imgs[13] = Image.createImage("/equip.png");
                imgs[14] = Image.createImage("/player_action_move_19_29.png");
                imgs[15] = Image.createImage("/player_action_etc_27_31.png");
                imgs[16] = Image.createImage("/player_atk_eff_20_25.png");
                imgs[17] = Image.createImage("/effect_sk_shout_42_27.png");
                imgs[18] = Image.createImage("/cart_24_24.png");
                System.gc();
            }
            System.gc();
            InputStream inputstream = Runtime.getRuntime().getClass().getResourceAsStream("/alberta.map");
            maps = new byte[4608];
            for(int k = 0; k < 4608; k++)
            {
                maps[k] = (byte)inputstream.read();
                inputstream.read();
            }

            inputstream.close();
            System.gc();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    void loadMonster(int i)
    {
        try
        {
            if(imgs[19 + i] == null)
                imgs[19 + i] = Image.createImage(fileNames[i]);
        }
        catch(Exception exception) { }
        System.gc();
    }

    public void drawLogo(Graphics g)
    {
        g.setClip(start_x - logo_clips, 0, logo_clips << 1, getHeight());
        if(logo_clips < start_x)
            logo_clips += 10;
        else
            logo_clips = start_x;
        switch(state_index)
        {
        case 0: // '\0'
            g.setColor(255, 255, 255);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.drawImage(imgs[0], start_x - imgs[0].getWidth() / 2, start_y - imgs[0].getHeight() / 2, 0);
            break;

        case 1: // '\001'
            g.setColor(0, 0, 0);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.drawImage(imgs[1], start_x - imgs[1].getWidth() / 2, start_y - imgs[1].getHeight() / 2, 0);
            break;
        }
    }

    public void keyLogo(int i)
    {
        switch(state_index)
        {
        case 0: // '\0'
            state_index = 1;
            logo_clips = 0;
            break;

        case 1: // '\001'
            state_index = 0;
            current_state = 1;
            logo_clips = 0;
            break;
        }
    }

    public void drawTitle(Graphics g)
    {
        g.setColor(0, 0, 0);
        g.fillRect(0, 0, getWidth(), getHeight());
        //game logo
        g.drawImage(imgs[3], start_x - imgs[3].getWidth() / 2, start_y - imgs[3].getHeight() / 2 - 30, 0);
        switch(state_index)
        {
        case 0: // '\0'
            next_time = System.currentTimeMillis();
            if(next_time - backup_time > 500L)
            {
                isBlank = !isBlank;
                backup_time = next_time;
            }
            if(isBlank)
                drawEnglish(pressAnyKey, start_x - (pressAnyKey.length() * 6) / 2, start_y + 30, g);
            break;

        case 1: // '\001'
            drawMenu(g);
            break;
        }
    }

    public void keyTitle(int i)
    {
        switch(state_index)
        {
        case 0: // '\0'
            state_index = 1;
            nowMenu = menus[0];
            initOption();
            break;

        case 1: // '\001'
            keyMenu(i);
            break;
        }
    }

    public void drawMenu(Graphics g)
    {
        if(menu_index == 1)//载入游戏
        {
            drawUserLoad(g);
            return;
        }
        if(menu_index == 3)//游戏帮助
        {
            drawHelp(g);
            return;
        }
        if(menu_index != 5)//正常菜单
        {
            g.setColor(255, 255, 255);
            g.fillRect(start_x - 50, start_y - (nowMenu.length * 15 >> 1) - 5, 100, nowMenu.length * 15 + 10);
            g.setColor(0, 0, 255);
            g.fillRect((start_x - 50) + 2, (start_y - (nowMenu.length * 15 >> 1) - 5) + 2, 96, (nowMenu.length * 15 + 10) - 4);
        } else//帮助界面
        {
            g.setColor(0, 0, 255);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
        int i = (start_y - (nowMenu.length * 15 >> 1) - 5) + 5;
        for(int j = 0; j < nowMenu.length; j++)
            drawEnglish(nowMenu[j], start_x - (nowMenu[j].length() * 6) / 2, i + j * 15, g);

    }
//载入游戏进度
    public void drawUserLoad(Graphics g)
    {
        g.setColor(0, 0, 0);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(255, 255, 255);
        g.fillRect(start_x - 50, start_y - (szUserLoad.length * 15 >> 1) - 5, 100, szUserLoad.length * 15 + 10);
        g.setColor(0, 0, 255);
        g.fillRect((start_x - 50) + 2, (start_y - (szUserLoad.length * 15 >> 1) - 5) + 2, 96, (szUserLoad.length * 15 + 10) - 4);
        for(int i = 0; i < szUserLoad.length; i++)
            drawEnglish(szUserLoad[i], start_x - (szUserLoad[i].length() * 6) / 2, (start_y - (szUserLoad.length * 15 >> 1)) + i * 15, g);

    }
//HELP
    public void drawHelp(Graphics g)
    {
        g.setColor(255, 255, 255);
        g.fillRect(start_x - 60, start_y - 54 - 1, 120, 113);
        g.setColor(0, 0, 255);
        g.fillRect((start_x - 60) + 2, start_y - 54, 116, 111);
        drawEnglish(menus[23][0], start_x - (menus[23][0].length() * 6) / 2, (start_y + 54) - 7, g);
        int i = (start_y - (nowMenu.length * 15 >> 1) - 5) + 5;
        for(int j = 0; j < nowMenu.length; j++)
            drawEnglish(nowMenu[j], start_x - (nowMenu[j].length() * 6) / 2, i + j * 15, g);

    }
//init options 菜单
    public void initOption()
    {
        if(isSound)
            menus[1][0] = "1.SOUND-ON";
        else
            menus[1][0] = "1.SOUND-OFF";
        if(isVibration)
            menus[1][1] = "2.SPEED-FAST";
        else
            menus[1][1] = "2.SPEED-SLOW";
        System.gc();
    }

    public void keyMenu(int i)
    {
        switch(menu_index)
        {
        case 4: // '\004'
        default:
            break;

        case 0: // '\0'
            switch(i)
            {

⌨️ 快捷键说明

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