Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class CardDeck {
- private Card c = new Card();
- private Card [] deck;
- int count = 0;
- public int User = 0;
- public int Comp = 0;
- public CardDeck()
- {
- deck = new Card [52];
- char [] rankValue = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
- char [] suitValue = {'D','C','H','S'};
- for(int i = 0; i<52; i++)
- {
- deck[i] = c;
- }
- for(int i = 0; i<4; i++)
- {
- for (int j = 0; j<13; j++)
- {
- deck[i*13+j] = new Card(suitValue[i],rankValue[j]);
- //deck[i*13+j].setRank(rankValue[j]);
- //deck[i*13+j].setSuit(suitValue[i]);
- }
- }
- }
- public Card Deal()
- {
- int Card;
- Card Top;
- Card = 51-count;
- count++;
- Top = deck[Card];
- return Top;
- }
- public int cardsLeft()
- {
- int cardsLeft;
- cardsLeft = 52-count;
- return cardsLeft;
- }
- public void ShowMenu()
- {
- System.out.println("--------------------------");
- System.out.println("What Would You Like To Do?");
- System.out.println("--------------------------");
- System.out.println("1) Get A New Card Deck");
- System.out.println("2) Shuffle");
- System.out.println("3) Display All Cards Remaining In The Deck");
- System.out.println("4) Play Black Jack");
- System.out.println("5) Exit");
- }
- public void displayCardAt(int s)
- {
- int next=0;
- for(int y=0; y<s/13; y++)
- {
- for(int j=0; j<=9; j++)
- {
- for(int x=0; x<13;x++)
- {
- deck[x+(13*y)].displayCard(j);
- }
- System.out.println("");
- }
- next =y;
- }
- for(int j=0; j<=9; j++)
- {
- for(int x=0; x<s%13;x++)
- {
- deck[x+(13*(next+1))].displayCard(j);
- }
- System.out.println("");
- }
- }
- public void shuffle()
- {
- int x,y;
- Card temp;
- Random r = new Random();
- for(int i=0; i<1000000;i++)
- {
- x = r.nextInt(52-count);
- y = r.nextInt(52-count);
- temp = deck[x];
- deck[x]= deck[y];
- deck[y] = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement