2010-07-07 73 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