blackberry - 在黑莓手机中设计老虎机

标签 blackberry blackberry-eclipse-plugin

我是一名 Blackberry Java 开发人员。我正在尝试开发一个简单的老虎机逻辑。我对黑莓的动画图形等很陌生。那么,谁能告诉我如何设计一个简单的老虎机,按下按钮时,3 个 block 中的图像必须开始旋转,停止后将根据图片显示奖品。那么你能帮我提供一些如何做到这一点的示例或教程吗...

编辑:我正在将其开发为不涉及任何金钱交易的有趣应用程序。因此,任何黑莓开发人员请指导我如何完成任务并通过单击按钮旋转三个图像......

最佳答案

这是一个简单的例子,但你必须自己处理装饰、平滑滚动等。

假设您有 6 张 70x70 的图像。 简单的 BitmapField 扩展用于绘制当前槽图像,上面的一半图像和下面的一半图像:

class SlotField extends BitmapField {
    Bitmap bmp1 = Bitmap.getBitmapResource("img1.png");
    Bitmap bmp2 = Bitmap.getBitmapResource("img2.png");
    Bitmap bmp3 = Bitmap.getBitmapResource("img3.png");
    Bitmap bmp4 = Bitmap.getBitmapResource("img4.png");
    Bitmap bmp5 = Bitmap.getBitmapResource("img5.png");
    Bitmap bmp6 = Bitmap.getBitmapResource("img6.png");

    Bitmap[] bmps = new Bitmap[] { bmp1, bmp2, bmp3, bmp4, bmp5, bmp6 };

    int mPos = 0;

    public SlotField(int position) {
        mPos = position;
    }

    public int getBitmapHeight() {
        return bmp1.getHeight() * 2;
    }

    public int getBitmapWidth() {
        return bmp1.getWidth();
    }

    protected void layout(int width, int height) {
        setExtent(getBitmapWidth(), getBitmapHeight());
    }

    int getNextPos() {
        if (mPos == bmps.length - 1) {
            return 0;
        } else
            return mPos + 1;
    }

    int getPrevPos() {
        if (mPos == 0) {
            return bmps.length - 1;
        } else
            return mPos - 1;
    }

    protected void paint(Graphics g) {
        Bitmap hImg = bmps[getPrevPos()];
        Bitmap mImg = bmps[mPos];
        Bitmap lImg = bmps[getNextPos()];
        g.drawBitmap(0, 0, 70, 35, hImg, 0, 35);
        g.drawBitmap(0, 35, 70, 70, mImg, 0, 0);
        g.drawBitmap(0, 105, 70, 35, lImg, 0, 0);
    }
}

现在将这些字段放在屏幕上并使用计时器制作动画:

class MainScr extends MainScreen {
    SlotField slot1 = new SlotField(0);
    SlotField slot2 = new SlotField(3);
    SlotField slot3 = new SlotField(5);
    boolean running = false;

    public MainScr() {
        HorizontalFieldManager hField = new HorizontalFieldManager();
        add(hField);

        hField.add(slot1);
        hField.add(slot2);
        hField.add(slot3);

        ButtonField btnRoll = new ButtonField("Roll");
        btnRoll.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                if (!running)
                    rollSlots();
            }
        });

        add(btnRoll);
    }

    void rollSlots() {
        Timer timer = new Timer();
        final Random rnd = new Random();
        TimerTask ttask1 = new TimerTask() {
            int cycle = 0;

            public void run() {
                slot1.mPos = slot1.getNextPos();
                invalidate();
                cycle++;
                if (cycle >= 100+rnd.nextInt(6))
                    cancel();
            }
        };

        TimerTask ttask2 = new TimerTask() {
            int cycle = 0;

            public void run() {
                slot2.mPos = slot2.getNextPos();
                invalidate();
                cycle++;
                if (cycle >= 100+rnd.nextInt(6))
                    cancel();
            }
        };

        TimerTask ttask3 = new TimerTask() {
            int cycle = 0;

            public void run() {
                slot3.mPos = slot3.getNextPos();
                invalidate();
                cycle++;
                if (cycle >= 100+rnd.nextInt(6))
                    cancel();
            }
        };

        timer.schedule(ttask1, 0, 50);
        timer.schedule(ttask2, 200, 50);
        timer.schedule(ttask3, 400, 50);
    }
}

alt text http://img534.imageshack.us/img534/2172/slots.jpg

有关 UI 功能,请阅读

Blackberry User Interface Design - Customizable UI?

Blackberry - fields layout animation

关于blackberry - 在黑莓手机中设计老虎机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3193802/

相关文章:

java - BlackBerry:检索当前年、月、日

java - 如何在Android和Blackberry上进行HTTP广播流?

java - 黑莓机中的 HTTP POST

BlackBerry - 在自己的项目中使用自己的 JAR 文件

java - 简单的应用程序无法在 Eclipse 中编译(带插件)?

java - 如何在黑莓 JDE 中添加新的模拟器?

java - 有 DNS 异常的黑莓模拟器

blackberry - 无法在 BlackBerry 上的 Micro SD 卡上写入

console - 过滤黑莓模拟器控制台输出消息

Blackberry - 在 Mac OSX 上的 Eclipse 上找不到 "Run on simulator"选项