在黑莓手机中设计老虎机
-
02-10-2019 - |
题
我是一名黑莓 Java 开发人员。我正在尝试开发一个简单的老虎机逻辑。我对黑莓的动画图形等很陌生。那么,谁能告诉我如何设计一个简单的老虎机,按下按钮时,3 个块中的图像必须开始旋转,停止后将根据图片显示奖品。那么你能帮我提供一些如何做到这一点的示例或教程吗...
编辑:我正在将其开发为不涉及任何金钱交易的有趣应用程序。因此,任何黑莓开发人员请指导我如何完成任务并通过单击按钮旋转三个图像......
解决方案
这是一个简单的例子,但你必须自己处理装饰、平滑滚动等。
假设您有 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);
}
}
替代文本 http://img534.imageshack.us/img534/2172/slots.jpg
对于 UI 功能,请阅读
和
其他提示
游戏机上的机械卷轴的模拟受到保护 美国专利7452276. 。专利网页链接到其他40项美国和国际专利,您必须在开始开发软件之前必须进行调查。
在收到所有不同美国和国际专利持有人开发软件的许可之后,您将开发一个长的.gif条带,并带有不同的图像,这些图像很快就以三个或更多的位置向下移动。您的软件将不得不扭曲.GIF条带的可见部分的顶部和底部边缘,以使机械插槽轮的外观。
不隶属于 StackOverflow