2010-07-07 119 views
2

我是黑莓java开发人员。我正试图开发一个简单的老虎机逻辑。我是黑莓手机中的动画图形等新手。那么,谁能告诉我如何设计一个简单的老虎机,在按下按钮时,3个方块中的图像必须开始旋转,停止后,奖励将根据图片显示。所以,你可以plz帮我一些样品或教程如何做到这一点...设计黑莓老虎机

编辑:我正在开发它只是作为有趣的应用程序,不涉及任何金钱交易。所以,任何黑莓开发者plz指导我如何实现任务,并点击一个按钮旋转三个图像...

回答

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); 
    } 
} 

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

对于UI功能,请参阅

Blackberry User Interface Design - Customizable UI?

Blackberry - fields layout animation

+0

谢谢麦克斯...我可以知道什么程序,以实现图像的平稳过渡。 – 2010-07-13 08:12:49

+0

您可以将代码添加到paint()方法中。在g.drawBitmap()中使用y坐标,只需添加一些dy值并从timerTask run()更改即可。但可以肯定的是,它最终会变成0。对不起,你将不得不自己写下:) – 2010-07-14 05:26:13

+0

非常感谢...我一定会实现你的想法... – 2010-07-14 05:28:15

0

在游戏机上模拟机械卷轴受United States Patent 7452276保护。专利网页链接到40个其他美国和国际专利,在开始开发软件之前,您必须先进行调查。

在您获得所有美国和国际专利持有人的许可以开发您的软件后,您将开发一个长长的带有不同图像的.gif带,您可以快速向下移动三个或更多位置。您的软件必须扭曲.gif条的可见部分的顶部和底部边缘,才能看到机械槽轮的外观。

+0

你认为印度遵循美国法律? – 2010-07-07 14:04:20

+0

如果他们想在美国市场销售,他们应该。还有国际专利。 – 2010-07-07 14:14:30

+0

我不是在设计一款涉及金钱的典型老虎机。我需要开发它的机制(示例代码或教程)。我需要弄清楚如何让图像旋转,以及如何在旋转停止后真正获得3幅图像的值。任何黑莓开发者都可以帮助我? – 2010-07-08 04:18:40