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

📄 selectplayer.java

📁 格斗类型的游戏
💻 JAVA
字号:

import com.nokia.mid.ui.*;
import javax.microedition.lcdui.*;

public class SelectPlayer extends FullCanvas
{
    private DragonSoul inc = null;
//    private Image border = null;
    private Image player = null;
    private Image face = null;
    //选择角色的列数
    private int pline;
    //选择角色的行数
    private int prow;
//    private static final String _fldelse[] = {
//        "Select", "Back"
//    };
    //选择的角色
    private int p1new;
    private int p2new;
    //判断玩家角色状态
    private boolean p1State;
    //判断电脑角色状态
    private boolean p2State;

    /**
     * 选择游戏角色类的构造函数
     * @param inc DragonSoul,入口类对象
     */
    public SelectPlayer(DragonSoul inc)
    {
        this.inc = inc;
        try
        {
//            if(border == null)
//                border = Image.createImage("/border.png");
            if(player == null)
                player =  Image.createImage("/players.png");
            if (face == null)
                 face = Image.createImage("/faces.png");
        }
        catch(Exception exception) { }
    }

    /**
     * 角色参数设定
     * @param i int,玩家选的角色
     * @param j int,电脑的角色
     * @param flag boolean,true:玩家控制 false:没有控制
     * @param flag1 boolean,电脑控制为false
     */
    public void setPlayer(int i, int j, boolean flag, boolean flag1)
    {
        p1State = flag;
        p2State = flag1;
        pline = 0;
        prow = 0;
        p1new = i;
        p2new = j;
    }

    /**
     * 显示游戏画面
     */
    protected void showNotify()
    {
        if(!p1State)
            inc.loadLights();
        return;
    }

//    private int getForceTime(int pauseGame)
//    {
//        return getWidth() / 2 - (1 - pauseGame % 2) * 22;
//    }

//    private int saveIndex(int pauseGame)
//    {
//        return (44 / 2) * (pauseGame / 2) + 27;
//    }

    /**
     * 判断是否选定游戏角色
     * @param i int,选择的游戏角色
     * @return
     */
    private boolean choosePlayer(int i)
    {
        return p2new == -1 || p2new != -1 && p1new != i;
    }

    /**
     * 绘制选择游戏角色画面
     * @param g Graphics
     */
    protected void paint(Graphics g)
    {
        if(!p1State)
            if(p2new == -1)
                p1new = prow * 2 + pline;
            else
                p2new = prow * 2 + pline;
        for(int i = 0; i <= getWidth() / inc.menuBk.getWidth(); i++)
            g.drawImage(inc.menuBk, i * inc.menuBk.getWidth(), 0, 0x10 | 0x4);

        String s = "";
        if(p1State)
            s = "加载中...";
        g.setFont(Font.getFont(64, 1, 0));
        g.setColor(0);
        g.drawString(s, getWidth() / 2 + 1, 5, 0x10 | 0x1);
        g.setColor(0xffff00);
        g.drawString(s, getWidth() / 2, 4, 0x10 | 0x1);
        DirectGraphics directgraphics = DirectUtils.getDirectGraphics(g);
        if(!p1State)
        {
            for(int j = 0; j < 8; j++)
            {
                int x = getWidth() / 2 - (1 - j % 2) * 22;
                int y = (44 / 2) * (j / 2) + 50;
                g.setClip(x, y, 22, 22);
                if (j != prow * 2 + pline) {
                    g.setColor(0xCC0000);
                } else {
                    g.setColor(0x802AF1);
                }
                g.drawRect(x, y, 22, 22);
                g.drawRect(x + 1, y + 1, 20, 20);
                g.setClip(x + 2, y + 2, face.getWidth(), face.getHeight() / 8);
                if(j % 2 == 0)
                    g.drawImage(face, x + 2, (y + 2) - (face.getHeight() / 8) * j, 0x10 | 0x4);
                else
                    directgraphics.drawImage(face, x + 2, (y + 2) - (face.getHeight() / 8) * j, 0x10 | 0x4, 8192);
                if(!choosePlayer(j))
                {
                    int ai[] = new int[4];
                    ai[0] = x + 2;
                    ai[1] = (x + 22) - 2;
                    ai[2] = (x + 22) - 2;
                    ai[3] = x + 2;
                    int ai1[] = new int[4];
                    ai1[0] = y + 2;
                    ai1[1] = y + 2;
                    ai1[2] = (y + 22) - 2;
                    ai1[3] = (y + 22) - 2;
                    directgraphics.fillPolygon(ai, 0, ai1, 0, 4, 0xaa005090);
                }
            }

        }
        g.setClip(0, 0, getWidth(), getHeight());
        g.setColor(0x223399);
        if(p2State)
        {
            int k = (getWidth() - player.getWidth()) / 2;
            g.fillArc(k - 1, 100, player.getWidth() + 2, 6, 0, 360);
            g.setClip(k, 104 - player.getHeight() / 8, player.getWidth(), player.getHeight() / 8);
            g.drawImage(player, k, 80 - (player.getHeight() / 8) * (p1new + 1), 0x10 | 0x4);
        } else {
            int l = (getWidth() / 2 - 22 - player.getWidth()) / 2;
            g.fillArc(l - 1, 100, player.getWidth() + 2, 6, 0, 360);
            g.setClip(l, 104 - player.getHeight() / 8, player.getWidth(), player.getHeight() / 8);
            g.drawImage(player, l, 104 - (player.getHeight() / 8) * (p1new + 1), 0x10 | 0x4);
            g.setClip(0, 0, getWidth(), getHeight());
            g.setFont(Font.getFont(64, 1, 8));
            int k1 = (getWidth() / 2 - 22) / 2;
            g.setColor(136);
            g.drawString(DragonSoul.name[p1new], k1 + 1, 110, 0x10 | 0x1);
            g.setColor(0xffff00);
            g.drawString(DragonSoul.name[p1new], k1, 109, 0x10 | 0x1);
            g.setClip(0, 0, getWidth(), getHeight());
            if(p2new > -1)
            {
                g.setColor(0x223399);
                int i1 = ((getWidth() + getWidth() / 2 + 22) - player.getWidth()) / 2;
                g.fillArc(i1 - 1, 100, player.getWidth() + 2, 6, 0, 360);
                g.setClip(i1, 104 - player.getHeight() / 8, player.getWidth(), player.getHeight() / 8);
                directgraphics.drawImage(player, i1, 104 - (player.getHeight() / 8) * (p2new + 1), 0x10 | 0x4, 8192);
                g.setClip(0, 0, getWidth(), getHeight());
                int l1 = (getWidth() + getWidth() / 2 + 22) / 2;
                g.setColor(136);
                g.drawString(DragonSoul.name[p2new], l1 + 1, 110, 0x10 | 0x1);
                g.setColor(0xffff00);
                g.drawString(DragonSoul.name[p2new], l1, 109, 0x10 | 0x1);
            }
        }
//             eNum.setClip(0, 0, getWidth(), getHeight());
        if(!p1State)
        {
////                eNum.setFont(Font.getFont(64, 1, 8));
////                if(_fldelse[0].length() > 0)
////                {
////                    eNum.drawImage(inc.prow, 0, getHeight(), 0x20 | 0x4);
////                    eNum.setColor(136);
////                    eNum.drawString(_fldelse[0], 21, getHeight() - 1, 0x20 | 0x1);
////                    eNum.setColor(0xffff00);
////                    eNum.drawString(_fldelse[0], 20, getHeight() - 2, 0x20 | 0x1);
////                }
////                if(_fldelse[1].length() > 0)
////                {
////                    eNum.drawImage(inc.pline, getWidth(), getHeight(), 0x20 | 0x8);
////                    eNum.setColor(136);
////                    eNum.drawString(_fldelse[1], getWidth() - 19, getHeight() - 1, 0x20 | 0x1);
////                    eNum.setColor(0xffff00);
////                    eNum.drawString(_fldelse[1], getWidth() - 20, getHeight() - 2, 0x20 | 0x1);
////                }
        } else if(!p2State)
        {
            g.setClip(0, 0, getWidth(), getHeight());
            g.setFont(Font.getFont(64, 1, 16));
            g.setColor(0);
            g.drawString("对", getWidth() / 2 + 1, (getHeight() / 2 - 10) + 1, 0x1 | 0x10);
            g.setColor(0xffff00);
            g.drawString("对", getWidth() / 2, getHeight() / 2 - 10, 0x1 | 0x10);
        }
    }

        /**
         * 按键响应函数
         * @param i 按键响应代码
         */
    protected void keyPressed(int i)
    {
        if(p1State)
            return;

        if(i == 50 || i == -1)
        {
            int j = prow <= 0 ? 3 : prow - 1;
            if(choosePlayer(j * 2 + pline))
            {
                prow = j;
            } else
            {
                j = j <= 0 ? 3 : j - 1;
                if(choosePlayer(j * 2 + pline))
                    prow = j;
            }
            repaint();
            return;
        }
        if(i == 56 || i == -2)
        {
            int k = prow >= 3 ? 0 : prow + 1;
            if(choosePlayer(k * 2 + pline))
            {
                prow = k;
            } else
            {
                k = k >= 3 ? 0 : k + 1;
                if(choosePlayer(k * 2 + pline))
                    prow = k;
            }
            repaint();
            return;
        }
        if(i == 52 || i == -3)
        {
            int l = pline != 0 ? 0 : 1;
            if(choosePlayer(prow * 2 + l))
                pline = l;
            repaint();
            return;
        }
        if(i == 54 || i == -4)
        {
            int i1 = pline != 0 ? 0 : 1;
            if(choosePlayer(prow * 2 + i1))
                pline = i1;
            repaint();
            return;
        }
        if(i == 53 || i == -6 || i == getKeyCode(8))
        {
            if(p2new == -1 && (inc.backToGameMode() == 0 || inc.backToGameMode() == 1))
            {
                p2new = 0;
                pline = 1 - pline;
            } else
            {
                p1State = true;
                if(inc.backToGameMode() == 2 || inc.backToGameMode() == 3)
                {
                    p2new = 0;
                    if(p1new == 0)
                        p2new = 1;
                }
                repaint();
                serviceRepaints();
                inc.EnterGame(p1new, p2new);
            }
            repaint();
        }
        if(i == -7)
        {
            inc.initModeMenu();
        }
    }

//    public void getForceTime()
//    {
//        player = null;
//        face = null;
//        //System.gc();
//    }
}

⌨️ 快捷键说明

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