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

📄 bnb_game.java

📁 手机版本的泡泡堂 用j2me写的 大家可以参考下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                {
                    Tools.paintString(g, "返回主菜单", 25, 50, GRAPHICS_TL);
                }
                g.setColor(0, 0, 0);
                Tools.paintString(g, "继续游戏", 32, 85, GRAPHICS_TL);
                if (isMusic)
                {
                    Tools.paintString(g, "音乐:开", 32, 105, GRAPHICS_TL);
                }
                else
                {
                    Tools.paintString(g, "音乐:关", 32, 105, GRAPHICS_TL);
                }
                Tools.paintString(g, "退出游戏", 32, 125, GRAPHICS_TL);
                break;
            case 2:
                g.setColor(255, 0, 0);
                if (pausetime++ % 6 != 0)
                {
                    Tools.paintString(g, "继续游戏", 32, 85, GRAPHICS_TL);
                }
                g.setColor(0, 0, 0);
                Tools.paintString(g, "返回主菜单", 25, 50, GRAPHICS_TL);
                if (isMusic)
                {
                    Tools.paintString(g, "音乐:开", 32, 105, GRAPHICS_TL);
                }
                else
                {
                    Tools.paintString(g, "音乐:关", 32, 105, GRAPHICS_TL);
                }
                Tools.paintString(g, "退出游戏", 32, 125, GRAPHICS_TL);
                break;
            case 3:
                g.setColor(255, 0, 0);
                if (pausetime++ % 6 != 0)
                {
                    if (isMusic)
                    {
                        Tools.paintString(g, "音乐:开", 32, 105, GRAPHICS_TL);
                    }
                    else
                    {
                        Tools.paintString(g, "音乐:关", 32, 105, GRAPHICS_TL);
                    }
                }
                g.setColor(0, 0, 0);
                Tools.paintString(g, "返回主菜单", 25, 50, GRAPHICS_TL);
                Tools.paintString(g, "继续游戏", 32, 85, GRAPHICS_TL);
                Tools.paintString(g, "退出游戏", 32, 125, GRAPHICS_TL);
                break;
            case 4:
                g.setColor(255, 0, 0);
                if (pausetime++ % 6 != 0)
                {
                    Tools.paintString(g, "退出游戏", 32, 125, GRAPHICS_TL);
                }
                g.setColor(0, 0, 0);
                Tools.paintString(g, "返回主菜单", 25, 50, GRAPHICS_TL);
                Tools.paintString(g, "继续游戏", 32, 85, GRAPHICS_TL);
                if (isMusic)
                {
                    Tools.paintString(g, "音乐:开", 32, 105, GRAPHICS_TL);
                }
                else
                {
                    Tools.paintString(g, "音乐:关", 32, 105, GRAPHICS_TL);
                }
                break;
        }
    }

    public static final void paintOver(Graphics g)
    {
        if (isOK)
        {
            totalizescore += BnB_Player.score;
            rms.saveScore(name.toString(), totalizescore);
            Tools.loadOver();
            isOK = false;
        }
        g.drawImage(Tools.over, 0, 0, GRAPHICS_TL);
    }

    public static final void paintEnding(Graphics g)
    {
        if (isOK)
        {
            Tools.loadEnding();
            rms.saveScore(name.toString(), totalizescore);
            isOK = false;
        }
        g.drawImage(Tools.ending, 0, 0, GRAPHICS_TL);
        g.setColor(0, 255, 0);
        g.setFont(FONT1);
        Tools.paintString(g, "" + totalizescore, 91, 131, GRAPHICS_TR);
    }

    public static final void paintGame(Graphics g)
    {
        loadGame();
        clear(g);
        map.paint(g);
        box.paint(g);
        player.move();
        player.collidesWith(box, player.key);
        for (int i = 0; i < BnB_Player.MAX_POPO; i++)
        {
            if (player.pao[i].isShow)
            {
                player.pao[i].paintPopo(g, Tools.water, box);
                player.collidesWith(player.pao[i], box);
                player.collideesWith(player.pao[i], player.key);
                npc.collidesWith(player.pao[i], box);
                if (player.index != i)
                {
                    if (player.pao[player.index].isExpedite(box,
                            player.pao[i].cols, player.pao[i].rows))
                    {
                        player.pao[player.index].detectCannonry(player.pao[i]);
                    }
                }
            }
        }
        g.drawImage(Tools.cue, 0, 0, GRAPHICS_TL);
        if (player.firstPaint(npc))
        {
            npc.paintPlayer(g);
            player.paintPlayer(g);
        }
        else
        {
            player.paintPlayer(g);
            npc.paintPlayer(g);
        }
        g.setColor(255, 255, 255);
        g.setFont(FONT1);
        if (player.life >= 0)
        {
            Tools.paintString(g, "" + player.life, 35, 8, GRAPHICS_TL);
        }
        else
        {
            Tools.paintString(g, "" + 0, 35, 8, GRAPHICS_TL);
        }
        if (isLost() && !player.isDie)
        {
            if (!isOK)
            {
                try
                {
                    Thread.sleep(2000);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                stage = UI_OVER;
                isOK = true;
                return;
            }
        }
        if (isWin() && !npc.isDie)
        {
            if (!isOK)
            {
                try
                {
                    Thread.sleep(2000);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                releaseGame();
                stage = UI_PASS;
                isOK = true;
                totalizescore += BnB_Player.score;
                time = System.currentTimeMillis() - time;
                return;
            }
        }
    }

    public static final void loadGame()
    {
        switch (pass)
        {
            case 1:
                if (isOK)
                {
                    isOK = false;
                    Tools.loadGame();
                    player = new BnB_Player(Tools.playerstart, 16, 20, true);
                    npc = new BnB_Player(Tools.npcstart, 16, 20, false);
                    box = new TiledLayer(8, 10, Tools.tile, 16, 16);
                    createTiledLayer(box, 8, 10, Tools.box1);
                    map = new TiledLayer(8, 10, Tools.map, 16, 16);
                    createTiledLayer(map, 8, 10, Tools.map1);
                    time = 0;
                    time = System.currentTimeMillis();
                }
                break;
            case 2:
                if (isOK)
                {
                    isOK = false;
                    Tools.loadGame();
                    player = new BnB_Player(Tools.playerstart, 16, 20, true);
                    npc = new BnB_Player(Tools.npcstart, 16, 20, false);
                    box = new TiledLayer(8, 10, Tools.tile, 16, 16);
                    createTiledLayer(box, 8, 10, Tools.box2);
                    map = new TiledLayer(8, 10, Tools.map, 16, 16);
                    createTiledLayer(map, 8, 10, Tools.map2);
                    time = 0;
                    time = System.currentTimeMillis();
                }
                break;
            case 3:
                if (isOK)
                {
                    isOK = false;
                    Tools.loadGame();
                    player = new BnB_Player(Tools.playerstart, 16, 20, true);
                    npc = new BnB_Player(Tools.npcstart, 16, 20, false);
                    box = new TiledLayer(8, 10, Tools.tile, 16, 16);
                    createTiledLayer(box, 8, 10, Tools.box3);
                    map = new TiledLayer(8, 10, Tools.map, 16, 16);
                    createTiledLayer(map, 8, 10, Tools.map3);
                    time = 0;
                    time = System.currentTimeMillis();
                }
                break;
            case 4:
                if (isOK)
                {
                    isOK = false;
                    Tools.loadGame();
                    player = new BnB_Player(Tools.playerstart, 16, 20, true);
                    npc = new BnB_Player(Tools.npcstart, 16, 20, false);
                    box = new TiledLayer(8, 10, Tools.tile, 16, 16);
                    createTiledLayer(box, 8, 10, Tools.box4);
                    map = new TiledLayer(8, 10, Tools.map, 16, 16);
                    createTiledLayer(map, 8, 10, Tools.map4);
                    time = 0;
                    time = System.currentTimeMillis();
                }
                break;
        }
    }

    public static final void releaseGame()
    {
        if (!isOK)
        {
            isOK = true;
            player = null;
            npc = null;
            box = null;
            map = null;
            Tools.releaseGame();
        }
    }

    public static final boolean isWin()
    {
        if (npc.life < 0)
        {
            npc.isKeyPress = false;
            player.isKeyPress = false;
            return true;
        }
        return false;
    }

    public static final boolean isLost()
    {
        if (player.life < 0)
        {
            npc.isKeyPress = false;
            player.isKeyPress = false;
            return true;
        }
        return false;
    }

    public static final void createTiledLayer(TiledLayer tl, int cols,
            int rows, int array[][])
    {
        for (int i = 0; i < cols; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                tl.setCell(i, j, array[j][i]);
            }
        }
    }

    // 恢复处理
    protected void showNotify()
    {
        if (stage == UI_GAME)
        {
            isPause = false;
            stage = UI_GAME;
            pausepage = 2;
            pausetime = 0;
        }
    }

    // 来电处理
    protected void hideNotify()
    {
        if (stage == UI_GAME)
        {
            isPause = true;
            stage = UI_PUASE;
            pausepage = 2;
            pausetime = 0;
        }
    }

    /**
     * 时间转换成String对象。
     */
    public static final String timeToString(long t)
    {
        String temp;
        if (t / 60000 < 10 && t / 1000 % 60 < 10)
        {
            temp = "0" + t / 60000 + ":0" + t / 1000 % 60;
        }
        else if (t / 60000 < 10)
        {
            temp = "0" + t / 60000 + ":" + t / 1000 % 60;
        }
        else if (t / 1000 % 60 < 10)
        {
            temp = t / 60000 + ":0" + t / 1000 % 60;
        }
        else
        {
            temp = t / 60000 + ":" + t / 1000 % 60;
        }
        return temp;
    }
}

⌨️ 快捷键说明

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