Advertisement
iNoobAvicena

Asynctask java slot game

Oct 18th, 2021
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. ImageView _slotgambar;
  2.     Random _acak = new Random();
  3.     boolean _roll = true;
  4.     int[] _slotimg = {R.drawable.slot1, R.drawable.slot2, R.drawable.slot3,
  5.             R.drawable.slot4, R.drawable.slot5, R.drawable.slotbar};
  6.  
  7.     int _next;
  8.  
  9. //    public Asynctask() {
  10. //        this._roll = true;
  11. //    }
  12.  
  13.     public Asynctask(Asynctask tv) {
  14.         _acak = tv;
  15.     }
  16.  
  17. //    interface tester {
  18. //        void newImage(int img);
  19. //    }
  20.  
  21. //    public void nextimg() {
  22. //        _next++;
  23. //
  24. //        if (_next == _slotimg.length) {
  25. //            _next = 0;
  26. //        }
  27.  
  28. //        int j = _acak.nextInt(3);
  29. //        publishProgress(j);
  30.  
  31. //        _acak.nextInt(3);
  32. //    }
  33.  
  34.     @Override
  35.     protected Boolean doInBackground(ImageView... slotimg) {
  36.         _slotgambar = slotimg[0];
  37. //        int i = 0;
  38.         while (_roll) {
  39. //            int j = _acak.nextInt(3);
  40. //            publishProgress(j);
  41.  
  42. //                _next++;
  43. //
  44. //                if (_next == _slotimg.length) {
  45. //                    _next = 1;
  46. //                }
  47.                 _next = _acak.nextInt(6);
  48.                 publishProgress(_next);
  49. //            nextimg();
  50.             try {
  51.                 Thread.sleep(_acak.nextInt(3000));
  52.             } catch (InterruptedException e) {
  53.                 e.printStackTrace();
  54.             }
  55.         }
  56.  
  57.         return !_roll;
  58.  
  59.     }
  60.  
  61.     @Override
  62.     protected void onProgressUpdate(Integer... values) {
  63.         super.onProgressUpdate(values);
  64. //        int k = _acak.nextInt(3);
  65. //        tester.newImage(_slotimg[_next]);
  66. //        _slotgambar.setImageResource(_slotimg[values[0]]);
  67.         _slotgambar.setImageResource(_slotimg[_next]);
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement