Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cards Class
- import java.util.*;
- public class Cards {
- public enum Rank { DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6),
- SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11);
- private int Rankpoints;
- private Rank(int points)
- {
- this.Rankpoints = points;
- }
- public int getRankpoints()
- {
- return Rankpoints;
- }
- }
- public enum Suit { CLUBS(2), DIAMONDS(3), HEARTS(4), SPADES(1);
- private int Suitpoints;
- Suit(int points)
- {
- Suitpoints = points;
- }
- public int getSuitpoints()
- {
- return Suitpoints;
- }
- }
- private final Rank rank;
- private final Suit suit;
- private Cards(Rank rank, Suit suit)
- {
- this.rank = rank;
- this.suit = suit;
- }
- public Rank rank()
- {
- return this.rank;
- }
- public Suit suit()
- {
- return this.suit;
- }
- public String toString()
- {
- return rank + " of " + suit;
- }
- private static final List<Cards> protoDeck = new ArrayList<Cards>();
- // Initialize prototype deck
- static {
- for (Suit suit : Suit.values())
- for (Rank rank : Rank.values())
- protoDeck.add(new Cards(rank, suit));
- }
- public static ArrayList<Cards> newDeck()
- {
- return new ArrayList<Cards>(protoDeck); // Return copy of prototype deck
- }
- }
- //Deal Class
- import java.util.*;
- public class Deal {
- public static void main(String args[])
- {
- int numHands = 1;
- int cardsPerHand = 20;
- List<Cards> deck = Cards.newDeck();
- Collections.shuffle(deck);
- int total = 0;
- ArrayList<Cards> hand = new ArrayList<Cards>();
- for (int i=0; i < numHands; i++)
- System.out.println(deal(deck, cardsPerHand)); // prints the hand
- //deal(deck,cardsPerHand,numHands);
- }
- // hand
- public static ArrayList<Cards> deal(List<Cards> deck, int n) {
- int deckSize = deck.size();
- List<Cards> handView = deck.subList(deckSize-n, deckSize);
- ArrayList<Cards> hand = new ArrayList<Cards>(handView);
- handView.clear();
- // Map<String, Map<String, Integer>> inputWords = new HashMap<String, Map<String, Integer>>();
- return hand;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement