I am making this card game app, when the user clicks the card this image will turn into a random other card. Here is an example:
public class MainActivity extends Activity {
int[] cards={R.drawable.aceofspades,R.drawable.aceofhearts,R.drawable.aceofclubs};
static Random r = new Random();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void imageClick(View view) {
int n=r.nextInt(cards.length);
{
ImageView image = (ImageView) findViewById(R.id.imageDice1);
image.setImageResource(cards[n]);
}
}
}
I would like to alter the code so that it won't be possible that the same card will show twice, not untill all the cards passed. So in this case when the card is "aceofspades" the next card and the card after that should not be "aceofspades". The first image that users will see is "R.drawable.cardback". I would like a code that changes the image back to "cardback" when all cards have been shown. Any help is appreciated.