No contact with Rxjava before the beginning of Android, with the native control ImageView wrote a flop game.
However, the bug is that if you click on the same card twice, you will be counted into the error.
I was not quite sure how to prevent the control from multiple clicks, then the solution was to compare the ID of the last click on the second click and not count if it was consistent.
Now with the Rxjava, you can implement this feature more succinctly.
See:
Prevent multiple codes: (Only one click on the control in two seconds)
Rxview. clicks (pictureboxs[i]) . Throttlefirst (2timeunit. SECONDS) . Subscribeon (androidschedulers. Mainthread()) . Subscribe (action1<void> () { @Override Call (Void avoid) {dosomething ();});
Background Timings:
Observable.interval(1, Timeunit.SECONDS). Compose ( This. <long>bindtolifecycle ()). Observeon (androidschedulers.Mainthread()). Subscribeon (schedulers.Newthread()). Subscribe (NewAction1<long> () {@Override Public voidPager(Long along) {TvShow. SetText ("" + Integer.toString(alltime++));};
The game logic is simple.
Randomly 6 different numbers, assigned to array num[0]-----num[5],
Then let Num[0]---num[5] order of the scrambled values assigned to NUM[6]---num[11].
So 0---11 have 6 pairs of the same, and the order is chaotic.
And then what. Control IMAGEVIEW[12] The value hidden behind them is the value in the array num.
After every 2 clicks, see if the num[x] value of the clicked control is equal.
Equal to hide the control, without waiting for the card to be unified display back and error number +1.
It's simple, right?
The control removes the particle effect on GitHub, forgetting the address, and I'm sorry, but thank the author very much.
There are many ways to vary the number of random numbers, because the array is small, can be directly two for loop, can also be implemented recursively :
static intGetNumber(int[] A, intIndex, intMinValue, intMaxValue, intTemp, Random R) { for(intI=0; I< index; I++) {if(a[I] = = temp) {intnewtemp= R.nextint (MaxValue) +minvalue; A[index] =newtemp;returnGetNumber(A, Index, MinValue, MaxValue, newtemp, R; } }returnTemp;}
GitHub Address: Https://github.com/VongVia1209/MemoryCard
"Android Learning" uses Rxjava to complete puzzle-flop games