I'm writing a program that has 6 different pictures and displays 12 tiles, with two of each picture. It is a memory game, and I am working on generating a random tile placement. I need to use RandomIntGenerator to distribute the tiles throughout the board, but I can't think of a way to do this since RandomIntGenerator will duplicate numbers. I'm not allowed to use arrays, which would have made this much easier. Can you give me any insight into how this could be done?
Any help is really appreciated! -Ryan
Create a List<Integer> with 12 values (1-12)
List<Integer> list = new ArrayList<Integer>(12);
for(int i = 0; i < 12 ; i++){ list.add(i);}
and then shuffle it
Collections.suffle(list)
yes, it seems you need random shuffle of your cards. You could implement your version of simple Fisher-Yates shuffling, for example, or indeed, use Collections.shuffle()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With