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

📄 game.java

📁 j2me游戏都市骑士的代码,是一款横版格斗的游戏.可以学习参考.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if(enemy1.ehit && !enemy1.ebackAttack)
                {
                    enemy1.enemyHitted(g);
                    enemy1.eattackedAnimation(g);
                }
            }
        }
        if(me.health > 0 && !search)
        {
            if(me.backAttack)
                me.drawFall(g);
            else
            if(me.hit && !me.backAttack)
            {
                me.drawHitted(g);
                me.attackedAnimation(g);
            }
            me.DoAction(g);
        }
    }

    public void drawBg1(Graphics g)
    {
        int i = 0;
        if(!enemyMan.isEmpty())
            if(enemyMan.size() == 1)
            {
                Enemy enemy = (Enemy)enemyMan.firstElement();
                if((enemy.x + me.x) / 2 < WIDTH / 2)
                    x1 = 0;
                else
                if(bgWIDTH - (enemy.x + me.x) / 2 < WIDTH / 2)
                    x1 = -(bgWIDTH - WIDTH);
                else
                    x1 = -((enemy.x + me.x) / 2 - WIDTH / 2);
            } else
            if(enemyMan.size() > 1)
            {
                Enumeration enumeration = enemyMan.elements();
                int j;
                Enemy enemy1;
                for(j = 0; enumeration.hasMoreElements(); j += enemy1.x)
                    enemy1 = (Enemy)enumeration.nextElement();

                if((j / enemyMan.size() + me.x) / 2 < WIDTH / 2)
                    x1 = 0;
                else
                if(bgWIDTH - (j / enemyMan.size() + me.x) / 2 < WIDTH / 2)
                    x1 = -(bgWIDTH - WIDTH);
                else
                    x1 = -((j / enemyMan.size() + me.x) / 2 - WIDTH / 2);
            }
        g.setColor(0, 0, 0);
        g.fillRect(0, 0, 176, 180);
        g.setColor(60, 60, 60);
        g.fillRect(0, 173, 176, 8);
        g.setColor(81, 81, 81);
        g.fillRect(0, 181, 176, 40);
        g.setClip(0, 0, WIDTH, HEIGHT);
        g.setColor(255, 255, 255);
        g.fillArc(x1 + 140, i + 15, 40, 40, 0, 360);
        g.drawImage(building, x1 + 9, i + 70, 0x10 | 4);
        g.drawImage(building, x1 + 140, i + 70, 0x10 | 4);
        g.drawImage(building, x1 + 181, i + 70, 0x10 | 4);
        g.drawImage(building, x1 + 320, i + 70, 0x10 | 4);
        g.drawImage(wall, x1 + 420, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 376 + 1, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 332 + 2, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 288 + 3, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 244 + 4, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 200 + 5, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 156 + 6, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 112 + 7, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 68 + 8, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, x1 + 24 + 9, (i + 168) - 48, 0x10 | 4);
        g.drawImage(wall, (x1 - 20) + 10, (i + 168) - 48, 0x10 | 4);
        g.setClip(0, 0, WIDTH, HEIGHT);
    }

    public void drawPanel(Graphics g)
    {
        if(me != null)
        {
            short word0 = me.health;
            g.setColor(255, 255, 0);
            g.setFont(Font.getFont(0, 0, 8));
            g.drawString("" + score, 10, 12, 4 | 0x10);
            if(word0 > 120)
                word0 = 120;
            g.setColor(255, 255, 0);
            g.fillRect(10, 6, 60, 4);
            g.setColor(255, 0, 0);
            g.fillRect(10, 6, word0 / 2, 4);
        }
        Enumeration enumeration = enemyMan.elements();
        if(lvl == 1)
        {
            g.setColor(255, 255, 0);
            g.fillRect(103, 6, 60, 4);
        } else
        if(lvl == 2)
        {
            g.setColor(255, 255, 0);
            g.fillRect(103, 6, 60, 4);
            g.setColor(255, 255, 0);
            g.fillRect(103, 12, 60, 4);
        } else
        if(lvl == 3)
        {
            g.setColor(255, 255, 0);
            g.fillRect(103, 6, 60, 4);
            g.setColor(255, 255, 0);
            g.fillRect(103, 12, 60, 4);
            g.setColor(255, 255, 0);
            g.fillRect(103, 18, 60, 4);
        }
        while(enumeration.hasMoreElements()) 
        {
            Enemy enemy = (Enemy)enumeration.nextElement();
            if(enemyMan.indexOf(enemy) == 0)
            {
                g.setColor(75, 176, 47);
                g.fillRect(103, 6, enemy.health, 4);
            } else
            if(enemyMan.indexOf(enemy) == 1)
            {
                g.setColor(75, 176, 47);
                g.fillRect(103, 12, enemy.health, 4);
            } else
            if(enemyMan.indexOf(enemy) == 2)
            {
                g.setColor(75, 176, 47);
                g.fillRect(103, 18, enemy.health, 4);
            }
        }
    }

    public void resetLevel()
    {
        lastlevel = level;
        lastscore = score;
        lasthealth = me.health;
        levelWeapon = weapon2;
        try
        {
            GameOver = false;
            if(level > 20)
                GameOver = true;
            if(me == null)
                me = new Fighter((short)108, (short)176, this);
            me.y = me.maxY;
            me.action = 13;
            me.isWeapon = false;
            me.weapon = 35;
            me.hit = false;
            me.backAttack = false;
            me.jt = 0;
            me.axeJumpCtr = 0;
            me.chainJumpCtr = 0;
            me.Armor[0] = 127;
            bonus = 0;
            me.weaponPicked = false;
            ptr.removeAllElements();
            enemyMan.removeAllElements();
            addPoints();
            addEnemy();
        }
        catch(Exception exception)
        {
            System.out.println("herer" + exception);
        }
    }

    public void restartGame()
    {
        try
        {
            GamePaused = false;
            GameOver = false;
            level = 1;
        }
        catch(Exception exception)
        {
            System.out.println("herer" + exception);
        }
        if(lvl == 127)
            lvl = 1;
        if(me == null)
            me = new Fighter((short)108, (short)176, this);
        cheatL = 0;
        me.fr = 0;
        me.health = 120;
        me.x = 108;
        me.y = me.maxY;
        me.action = 13;
        me.isWeapon = false;
        me.hit = false;
        me.backAttack = false;
        me.weaponPicked = false;
        me.jt = 0;
        me.axeJumpCtr = 0;
        me.chainJumpCtr = 0;
        strypg = 0;
        msglp = -30;
        lag = 0L;
        lightening = false;
        m = 10;
        p = 0;
        q = 0;
        search = false;
        score = 0;
        me.Armor[0] = 127;
        weapon2 = 127;
        bonus = 0;
        lastlevel = 1;
        lastscore = 0;
        lasthealth = 120;
        ptr.removeAllElements();
        enemyMan.removeAllElements();
        RoadArms.removeAllElements();
        addPoints();
        addEnemy();
    }

    public void restartGame(String s)
    {
        GamePaused = false;
        if(me == null)
            me = new Fighter((short)108, (short)176, this);
        try
        {
            lvl = Byte.parseByte(s.substring(0, s.indexOf(':')));
            level = Short.parseShort(s.substring(s.indexOf(':') + 1, s.indexOf('@')));
            score = Integer.parseInt(s.substring(s.indexOf('@') + 1, s.indexOf('*')));
            me.health = Short.parseShort(s.substring(s.indexOf('*') + 1, s.indexOf('#')));
            levelWeapon = Byte.parseByte(s.substring(s.indexOf('#') + 1));
        }
        catch(Exception exception)
        {
            System.out.println("Here is an exception in reading Game settings" + exception);
        }
        me.health = 120;
        me.x = 108;
        me.y = me.maxY;
        me.action = 13;
        me.isWeapon = false;
        me.hit = false;
        me.backAttack = false;
        cheatL = 0;
        me.weaponPicked = false;
        me.jt = 0;
        me.axeJumpCtr = 0;
        me.chainJumpCtr = 0;
        bonus = 0;
        lastlevel = level;
        if(level > 4)
        {
            RoadArms.removeAllElements();
            weapon2 = levelWeapon;
            RoadArms.addElement(new Arms(weapon2, (short)270, (short)192));
        }
        ptr.removeAllElements();
        enemyMan.removeAllElements();
        addPoints();
        addEnemy();
    }

    public void makeSound()
    {
        Class class1 = getClass();
        try
        {
            p1 = Manager.createPlayer(class1.getResourceAsStream("/Punch.wav"), "audio/wav");
            p1.realize();
            p1.prefetch();
        }
        catch(MediaException mediaexception)
        {
            System.out.println(" throwing media exception = " + mediaexception);
            mediaexception.printStackTrace();
        }
        catch(IOException ioexception)
        {
            System.out.println("1 testing sound " + ioexception);
        }
        catch(Exception exception)
        {
            System.out.println(" throwing exception = " + exception);
        }
    }

    public void gameEffects(String s)
    {
        if(isSoundOn)
            try
            {
                if(s.equals("punch") || s.equals("hit"))
                    p1.start();
            }
            catch(MediaException mediaexception)
            {
                System.out.println("game--effect--Media--exception = " + mediaexception);
                mediaexception.printStackTrace();
            }
            catch(Exception exception)
            {
                System.out.println("game effect exception = " + exception);
                exception.printStackTrace();
            }
    }

    public void searchAnimation(Graphics g)
    {
        search = true;
        switch(q)
        {
        case 0: // '\0'
            g.setClip((me.x - 30) + x1, 146, 60, 60);
            g.clipRect((me.x - 30) + x1, 146, 60, 60);
            g.drawRegion(playerIm, 0, 0, 60, 60, 2, (me.x - 30) + x1, 146, 0x10 | 4);
            q++;
            break;

        case 1: // '\001'
            g.setClip((me.x - 30) + x1, 146, 60, 60);
            g.clipRect((me.x - 30) + x1, 146, 60, 60);
            g.drawRegion(playerIm, 60, 0, 60, 60, 2, (me.x - 30) + x1, 146, 0x10 | 4);
            q = 0;
            break;
        }
        g.setClip(0, 0, WIDTH, HEIGHT);
        me.x += 3;
    }

    int WIDTH;
    int HEIGHT;
    int selRectPos;
    GameCanvas Gc;
    boolean GameStart;
    boolean GameOver;
    boolean GamePaused;
    int score;
    byte lvl;
    short level;
    boolean isSoundOn;
    boolean isVibratorOn;
    int lastscore;
    short lasthealth;
    short lastlevel;
    Image playerIm;
    Image dieIm;
    Image axeIm;
    Image chainIm;
    Image no;
    Image building;
    Image wall;
    Image vanish;
    Image fighterHit;
    Image armsIm;
    Random rnd;
    GameSettings gameSettings;
    String temp;
    short gameOverCtr;
    short resetCtr;
    short enemyRemoveCtr;
    Fighter me;
    Enemy you;
    Vector RoadArms;
    Vector enemyMan;
    Vector ptr;
    MidPlayer mp;
    Player p1;
    Player p2;
    public static int bgWIDTH = 450;
    short waitCtr;
    byte State;
    short cheatL;
    byte weapon2;
    short scorpioCtr;
    short y2;
    boolean vanishFlag;
    long prevtime;
    boolean hitting;
    int index;
    int bonus;
    int x1;
    byte levelWeapon;
    byte strypg;
    short msglp;
    long lag;
    boolean lightening;
    int m;
    int p;
    int q;
    boolean search;

}

⌨️ 快捷键说明

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