android - Card Game App - Random card but not the same card twice -
i making card game app, when user clicks card image turn random other card. here 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 alter code won't possible same card show twice, not untill cards passed. in case when card "aceofspades" next card , card after should not "aceofspades". first image users see "r.drawable.cardback". code changes image "cardback" when cards have been shown. appreciated.
you need put cards (or values 1 52) in array or list, shuffle them. requirement you're describing shuffling does.
Comments
Post a Comment