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

📄 bonus.java

📁 J2ME手机游戏源码 整个游戏有八个类组成: &#61548 主类:TankMIDlet &#61548 敌人坦克:Enemy &#61548 图片池:EnemyPool &#61548
💻 JAVA
字号:
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Bonus
{
    public static Graphics g = null;
    private Image bonus;
    private Image imgTimer;
    private Image imgPower;
    private Image imgBomber;
    private Image imgWall;
    private Image imgTanker;
    private Image imgCap;
    private Image imgBlock;
    public int bonusKind;
    public int bonusX;
    public int bonusY;
    public int formerBonusX;
    public int formerBonusY;
    public int bonusWidth;
    public int bonusHeight;
    int count = 1;
    public Bonus()
    {
        bonusKind = 0;
        bonusX =  - 1;
        bonusY =  - 1;
        formerBonusX =  - 1;
        formerBonusY =  - 1;
        try
        {
            bonus = Image.createImage("/bonus.png");
            bonusWidth = bonus.getWidth() / 3;
            bonusHeight = bonus.getHeight() / 2;
            imgBomber = Image.createImage(bonusWidth, bonusHeight);
            g = imgBomber.getGraphics();
            g.drawImage(bonus, 0, 0, g.TOP | g.LEFT);
            imgPower = Image.createImage(bonusWidth, bonusHeight);
            g = imgPower.getGraphics();
            g.drawImage(bonus,  - bonusWidth, 0, g.TOP | g.LEFT);
            imgTanker = Image.createImage(bonusWidth, bonusHeight);
            g = imgTanker.getGraphics();
            g.drawImage(bonus,  - bonusWidth * 2, 0, g.TOP | g.LEFT);
            imgTimer = Image.createImage(bonusWidth, bonusHeight);
            g = imgTimer.getGraphics();
            g.drawImage(bonus, 0,  - bonusHeight, g.TOP | g.LEFT);
            imgWall = Image.createImage(bonusWidth, bonusHeight);
            g = imgWall.getGraphics();
            g.drawImage(bonus,  - bonusWidth,  - bonusHeight, g.TOP | g.LEFT);
            imgCap = Image.createImage(bonusWidth, bonusHeight);
            g = imgCap.getGraphics();
            g.drawImage(bonus,  - bonusWidth * 2,  - bonusHeight, g.TOP | g.LEFT); //g.TOP|g.LEFT:g.topleft
            imgBlock = Image.createImage("/back.png");
        }
        catch (Exception exception)
        {
            System.out.println(exception);
        }
    }
    synchronized void paint(Graphics g)
    {
        if (count % 3 != 0)
        {
            switch (bonusKind)
            {
                case 1:
                    g.drawImage(imgTimer, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                case 2:
                    g.drawImage(imgPower, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                case 3:
                    g.drawImage(imgBomber, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                case 4:
                    g.drawImage(imgWall, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                case 5:
                    g.drawImage(imgTanker, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                case 6:
                    g.drawImage(imgCap, bonusX, bonusY, g.TOP | g.LEFT);
                    break;
                default:
                    break;
            }
        }
        else
        {
            g.drawImage(imgBlock, bonusX, bonusY, g.TOP | g.LEFT);
            count = 0;
        }
        count++;
    }
}

⌨️ 快捷键说明

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