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

📄 mygamecanvas.java.bak

📁 游戏学院《天下武王》教学实例
💻 BAK
📖 第 1 页 / 共 4 页
字号:
                            this.setGameStatus(STATUS_WALKING);
                            this.ranEnemy = null;
                            myPlayer.attackStatus = -1;
                        }
                        break;
                    }
                } else {
                    popSkill = false;
                    if (myPlayer.skillVec.size() > 0) {
                        fireSkill(curMenuIndex2);
                    }

                }

            } else {
                this.handleMenuKeyBrowse2(keyStates,
                                          myPlayer.skillVec.size() - 1);
            }
            break;
            //主角属性界面
        case STATUS_PLAYER_INFO:
            Vector v = this.weaponVec;
            switch (curMenuIndex) {
            case 1:
                v = myPlayer.weaponVec;
                break;
            case 2:
                v = myPlayer.medicVec;
                break;
            case 3:
                v = myPlayer.jacketVec;
                break;
            case 4:
                v = myPlayer.skillVec;
                break;

            }
            if ((keyStates & LEFT_PRESSED) != 0) {
                curMenuIndex = curMenuIndex - 1 >= 0 ? curMenuIndex - 1 : 4;
            } else if ((keyStates & RIGHT_PRESSED) != 0) {
                curMenuIndex = curMenuIndex + 1 > 4 ? 0 : curMenuIndex + 1;
            } else if ((keyStates & FIRE_PRESSED) != 0) {
                if (curMenuIndex == 0) {
                    this.setGameStatus(STATUS_WALKING);
                } else {
                    if (curMenuIndex2 < v.size() && curMenuIndex != 4) {
                        RPGObject ro = (RPGObject) v.elementAt(curMenuIndex2);
                        myPlayer.useObject(ro);
                    } else {
                        this.setGameStatus(STATUS_WALKING);
                    }
                }
            } else {
                handleMenuKeyBrowse2(keyStates, v.size());
            }
            break;
        }
    }

    private void fireSkill(int index) {
        Skill sk = (Skill) myPlayer.skillVec.elementAt(index);
        if (sk.requiredLevel <= myPlayer.rank && sk.hpCost <= myPlayer.hp
            && sk.mpCost <= myPlayer.mp) {
            myPlayer.fireSkill = sk;
            myPlayer.setAttackStatusSprite(1979);
        }

    }

    public void handleGameOver() {
        ranSkill = null;
        this.ranEnemy = null;
        myPlayer.attackStatus = -1;
        myPlayer.hp = 10;
        saveGame();
        engine.stop();
        lastGameOverTime = System.currentTimeMillis();
        this.setGameStatus(STATUS_GAME_OVER);
    }

    /**
     * 菜单上下遍历的通用方法
     * @param keyStates 按键状态
     * @param maxMenuIndex 最大的菜单索引
     */
    private void handleMenuKeyBrowse(int keyStates, int maxMenuIndex) {

        if ((keyStates & DOWN_PRESSED) != 0) {
            curMenuIndex = curMenuIndex + 1 > maxMenuIndex ? 0
                           : curMenuIndex + 1;
        }

        if ((keyStates & UP_PRESSED) != 0) {
            curMenuIndex = curMenuIndex - 1 < 0 ? maxMenuIndex
                           : curMenuIndex - 1;
        }
    }

    private void handleMenuKeyBrowse2(int keyStates, int maxMenuIndex) {

        if ((keyStates & DOWN_PRESSED) != 0) {
            curMenuIndex2 = curMenuIndex2 + 1 > maxMenuIndex ? 0
                            : curMenuIndex2 + 1;
        }

        if ((keyStates & UP_PRESSED) != 0) {
            curMenuIndex2 = curMenuIndex2 - 1 < 0 ? maxMenuIndex
                            : curMenuIndex2 - 1;
        }
    }

    public void startGame() {
        isRunning = true;
        Thread t = new Thread(this);
        gameThread = t;

        t.start();

    }

    public void handleRanEnemy() {
        if (this.ranEnemy != null) {
            this.constructsFightMap();
            this.setGameStatus(STATUS_FIGHTING);
            //System.out.println("handleRanEnemy over");
            //engine.ranEnemy = null;
        }
    }

    public void handleFightOver() {
        if (ranEnemy.ID == 3) {
            this.killTigerCount++;
        }
        gameStatus = STATUS_FIGHT_OVER;
        lastFightOverTime = System.currentTimeMillis();
    }

    /*
     * (non-Javadoc)
     *
     * @see org.gamecollege.j2me.rpg.RPGGameCanvas#render(javax.microedition.lcdui.Graphics)
     */
    protected void render() {
        Graphics g = this.getGraphics();
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, width, height);
        g.setColor(0, 0, 0);
        
        System.out.println("gs " +getGameStatus());
        
        switch (getGameStatus()) {

        case STATUS_WALKING:

            lm.paint(g, 0, 0);
            drawMessage();
            break;
        case STATUS_LOADING_LEVEL:
            drawLoadingLevel(g);
            break;
        case STATUS_POPMENU_CONFIRM:
            lm.paint(g, 0, 0);
            drawConfirmMenu(g);
            break;
        case STATUS_BUYING:
            drawBuying(g);
            break;
        case STATUS_SALING:
            drawSaling(g);
            break;
        case STATUS_FIGHTING:
            drawFightScene(g);

            break;
        case STATUS_MAIN_MENU:
            drawMainMenu(g);
            break;
        case STATUS_HELP:
            drawHelp(g);
            break;
        case STATUS_ABOUT:
            drawAbout(g);
            break;

        case STATUS_PLAYER_INFO:
            drawPlayerInfo(g);
            break;
        case STATUS_MISSION_INFO:
            drawMissonList(g);
            break;
        case STATUS_GAME_OVER:
            drawGameOver(g);
            break;
        case STATUS_FIGHT_OVER:
            drawFightOver(g);
            break;
        case STATUS_MISSION_OVER:
            drawMissonOver(g);
            break;
        }
        
        System.out.println("render finished " );
    }

    public void drawFlash() {
        Graphics g = this.getGraphics();
        if (ResourceLoader.flashImage != null) {
            g.drawImage(ResourceLoader.flashImage, width / 2, height / 2,
                        Graphics.HCENTER | Graphics.VCENTER);
        }
        this.flushGraphics();
    }

    /**
     * 绘制主角拥有的东西列表
     *
     * @param bType
     *            :1:武器 2:护具,3:药品 4:技能
     */
    private void drawBelongs(int bType, Graphics g) {
        int y1 = 10;

        y1 += 36;
        Vector ps = this.weaponVec;
        switch (curMenuIndex) {
        case 1:
            ps = myPlayer.weaponVec;
            break;
        case 2:
            ps = myPlayer.medicVec;
            break;
        case 3:
            ps = myPlayer.jacketVec;
            break;
        case 4:
            ps = myPlayer.skillVec;
            break;

        }
        for (int i = 0; i < ps.size(); i++) {
            RPGObject object = (RPGObject) ps.elementAt(i);

            paintMenu(g, object.name, 66, y1, i == curMenuIndex2);
            y1 += 18;
        }

        RPGObject ro = null;
        if (curMenuIndex2 < ps.size()) {
            ro = (RPGObject) ps.elementAt(curMenuIndex2);
        }

        if (ro != null) {
            String allDesc = ro.description;
            g.drawString(allDesc, width / 2, 208 - 15, Graphics.HCENTER
                         | Graphics.BOTTOM);
        }

        paintMenu(g, ResourceLoader.StringResource[3], 66, 193,
                  ps.size() == curMenuIndex2);

    }

    private void drawSaling(Graphics g) {
        g.drawImage(ResourceLoader.menu[0], width / 2, 0, Graphics.TOP
                    | Graphics.HCENTER);
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                               Font.SIZE_SMALL));
        switch (this.saleType) {
        //武器护具
        case 1:

            int y1 = 10;
            g.drawImage(ResourceLoader.menu[8], width / 2, y1, Graphics.TOP
                        | Graphics.HCENTER);
            String type = ResourceLoader.StringResource[27];
            if (!isArm) {
                type = ResourceLoader.StringResource[28];
            }

            g.drawString(type, width / 2, y1 + 1, Graphics.TOP
                         | Graphics.HCENTER);

            y1 += 18;
            g.drawString(ResourceLoader.StringResource[29] + ":"
                         + myPlayer.money, width / 2, y1, Graphics.TOP
                         | Graphics.HCENTER);
            Vector ps = myPlayer.weaponVec;
            if (!isArm) {
                ps = myPlayer.jacketVec;
            }

            y1 += 18;

            //武器护具列表

            for (int i = 0; i < ps.size(); i++) {
                Property property = (Property) ps.elementAt(i);

                paintMenu(g, property.name, width / 2, y1, i == curMenuIndex);
                y1 += 18;
            }

            //退出按钮
            paintMenu(g, ResourceLoader.StringResource[3], width / 2, y1,
                      curMenuIndex == ps.size());

            Property curP = null;
            if (curMenuIndex < ps.size()) {
                curP = (Property) ps.elementAt(curMenuIndex);
            }

            if (curP != null) {
                String allDesc = ResourceLoader.StringResource[6] + ":"
                                 + curP.description + "        "
                                 + ResourceLoader.StringResource[7] + ":" +
                                 curP.price;
                g.drawString(allDesc, width / 2, 208, Graphics.HCENTER
                             | Graphics.BOTTOM);
            }

            break;
        case 2:

            //药品
            int y = 10;
            g.drawString(ResourceLoader.StringResource[29] + ":"
                         + myPlayer.money, width / 2, y, Graphics.TOP
                         | Graphics.HCENTER);
            ps = myPlayer.medicVec;
            y += 18;
            for (int i = 0; i < ps.size(); i++) {
                Property property = (Property) ps.elementAt(i);

                paintMenu(g, property.name, width / 2, y, i == curMenuIndex);

                y += 18;
            }
            paintMenu(g, ResourceLoader.StringResource[3], width / 2, y,
                      curMenuIndex == ps.size());
            curP = null;
            if (ps.size() > curMenuIndex) {
                curP = (Property) ps.elementAt(curMenuIndex);
            }

            if (curP != null) {
                String allDesc = ResourceLoader.StringResource[6] + ":"
                                 + curP.description + "        "
                                 + ResourceLoader.StringResource[7] + ":" +
                                 curP.price;
                g.drawString(allDesc, width / 2, 208, Graphics.HCENTER
                             | Graphics.BOTTOM);
            }
            break;

        }
    }

    /**
     *
     */
    private void drawMissonList(Graphics g) {

        g.drawImage(ResourceLoader.menu[0], width / 2, 0, Graphics.TOP
                    | Graphics.HCENTER);
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                               Font.SIZE_LARGE));
        g.drawString(ResourceLoader.StringResource[42], width / 2, 0,
                     Graphics.TOP | Graphics.HCENTER);
        g.drawString(curLevel.missionDesc, width / 2, 40, Graphics.TOP
                     | Graphics.HCENTER);

    }

    private void drawMissonOver(Graphics g) {

        g.drawImage(ResourceLoader.menu[0], width / 2, 0, Graphics.TOP
                    | Graphics.HCENTER);
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                               Font.SIZE_LARGE));

        g.drawString(ResourceLoader.StringResource[40], width / 2,
                     height / 2 - 20, Graphics.TOP | Graphics.HCENTER);
        //g.drawString(""+this.killTigerCount,40,40,0);

    }

    private void drawFightOver(Graphics g) {
        fightLayerManager = new LayerManager();
        fightLayerManager.append(this.fightBackGround);
        fightLayerManager.paint(g, 0, 0);
        g.setColor(255, 255, 255);
        g.drawImage(ResourceLoader.menu[3], width / 2, height / 2,
                    Graphics.HCENTER | Graphics.VCENTER);
        g.drawString(ResourceLoader.StringResource[30]
                     + (myPlayer.exp - this.beforeFightExp), width / 2,
                     height / 2 - 40, Graphics.HCENTER | Graphics.TOP);
        g.drawString(ResourceLoader.StringResource[31]
                     + (myPlayer.money - this.beforeFightMoney), width / 2,
                     height / 2 - 20, Graphics.HCENTER | Graphics.TOP);
        //升级了
        if (myPlayer.exp >= myPlayer.nextExp) {
            g.drawString(ResourceLoader.StringResource[39], width / 2,
                         height / 2, Graphics.HCENTER | Graphics.TOP);

        }
        //学会技能
        if (ranSkill != null) {
            g
                    .drawString(ResourceLoader.StringResource[41]
                                + ranSkill.name, width / 2, height / 2 + 20,
                                Graphics.HCENTER | Graphics.TOP);
        }

    }

    /**
     *
     */
    private void drawPlayerInfo(Graphics g) {
        // TODO 自动生成方法存根
        g.drawImage(ResourceLoader.menu[0], 0, 0, 0);
        g.setColor(255, 255, 255);

        g
                .drawImage(ResourceLoader.menu[8], 30, 0, Graphics.TOP
                           | Graphics.LEFT);

        g.setClip(118, 0, 58, 52);
        g.drawImage(ResourceLoader.menu[4], 118, 0, 0);
        g.setClip(0, 0, width, height);

        String type = type = ResourceLoader.StringResource[38]; //一般

        switch (curMenuIndex) {
        //通常信息
        case 0:

⌨️ 快捷键说明

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