Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Java, Happy Family Game, using ArrayList

$
0
0
The code for the deck by using ArrayList:
ArrayList<Card> deck = new ArrayList<Card>();
	public static final int TOTALFAMILIES = 12;
	public static final int TOTALCARDS = TOTALFAMILIES * 4;
	private int cardsDispensed = 0;
	String [] members={"Father", "Mother", "Son", "Daughter"};
	String [] families={"Back","Carr","Duck", "Mike", 
								"Pug", "Putt", "Salt", "Snap", 
								"Strong", "Swift", "Weed", "Wing"};
	String [] occupations={"Footballer", "Motorist", "Cricketer", 
								"Announcer", "Boxer", "Golfer", "Boatman",
								"Photographer", "Weight Lifter", "Runner", 
								"Gardener", "Airman"}; 



Anyone knows how does this method mean and how can I do it in Happy Family Game which I have already got a createDeck method
 public Card createCard(String, String){
		
	}


How can i change the code from an array to arraylist
public void createDeck(){
		for (int i=0; i<families.length; i++){
			for (int k=0; k<members.length; k++){
				deck[i * 4 + k] = new Card(families[i], members[k],occupations[i]);
			}
		} 
	}

public void shuffleDeck(){
		for (int i=0; i<1000; i++){
			int pos = new java.util.Random().nextInt(TOTALCARDS);
			Card temp = deck[pos];
			deck[pos] = deck[0];
			deck[0] = temp;
		} 

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>