Quote
So now I can use the Collection.shuffle ( images) and randomly remove elements?
You can use either. You don't have to use both approaches.




Posted 17 January 2013 - 12:57 AM
Quote
Posted 17 January 2013 - 01:03 AM
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.util.*;
public class DeckofCards1 extends Applet {
public void init ( ) {
String[] suits = {"c", "s", "h", "d"};
String[] values = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "j", "q", "k"};
ArrayList<Image> images = new ArrayList<Image>( );
for(String suit : suits){
for(String value : values){
Image img = getImage ( getDocumentBase ( ), "images/" + suit + value + ".gif" );
images.add(img);
}
}
Collections.shuffle ( images );
System.out.println ( "images " );
}
}
This post has been edited by bwong23: 17 January 2013 - 01:05 AM
Posted 17 January 2013 - 01:18 AM
Posted 17 January 2013 - 01:34 AM
Collections.shuffle ( images );//how to get first ten cards
public void paint ( Graphics g ) { //can i pass the first ten images to this?
g.drawImage (whatGoesHere, 10, 10, this);
Posted 17 January 2013 - 07:13 AM
ArrayList<Card> al;
Random ran = new Random();
Card[] getHand(int nb) {
Card[] hand = new Card[nb];
for(int i = 0; i < nb; ++i) {
int index = ran.nextInt(al.size());
hand[i] = al.remove(index);
}
return hand;
}
Posted 17 January 2013 - 06:41 PM
Posted 17 January 2013 - 10:06 PM
pbl, on 17 January 2013 - 07:13 AM, said:
ArrayList<Card> al;
Random ran = new Random();
Card[] getHand(int nb) {
Card[] hand = new Card[nb];
for(int i = 0; i < nb; ++i) {
int index = ran.nextInt(al.size());
hand[i] = al.remove(index);
}
return hand;
}
Posted 17 January 2013 - 10:08 PM
Posted 17 January 2013 - 10:17 PM
Posted 17 January 2013 - 10:19 PM
Posted 17 January 2013 - 10:25 PM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
