Advertisement
lilflamekid91

Lab 6 - Card Deck Class

May 25th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.util.Random;
  2. public class CardDeck {
  3.     private Card c = new Card();
  4.     private Card [] deck;
  5.     int count = 0;
  6.     public int User = 0;
  7.     public int Comp = 0;
  8.    
  9.     public CardDeck()
  10.     {
  11.        
  12.         deck = new Card [52];
  13.         char [] rankValue = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
  14.         char [] suitValue = {'D','C','H','S'};
  15.        
  16.         for(int i = 0; i<52; i++)
  17.         {
  18.             deck[i] = c;
  19.            
  20.         }
  21.    
  22.    
  23.         for(int i = 0; i<4; i++)
  24.         {
  25.             for (int j = 0; j<13; j++)
  26.             {
  27.                 deck[i*13+j] = new Card(suitValue[i],rankValue[j]);
  28.                 //deck[i*13+j].setRank(rankValue[j]);
  29.                 //deck[i*13+j].setSuit(suitValue[i]);
  30.             }
  31.         }
  32.     }
  33.  
  34.     public Card Deal()
  35.     {
  36.         int Card;
  37.         Card Top;
  38.         Card = 51-count;
  39.         count++;
  40.         Top = deck[Card];
  41.         return Top;
  42.        
  43.     }
  44.  
  45.     public int cardsLeft()
  46.     {
  47.         int cardsLeft;
  48.         cardsLeft = 52-count;
  49.         return cardsLeft;
  50.     }
  51.    
  52.     public void ShowMenu()
  53.     {
  54.         System.out.println("--------------------------");
  55.         System.out.println("What Would You Like To Do?");
  56.         System.out.println("--------------------------");
  57.         System.out.println("1) Get A New Card Deck");
  58.         System.out.println("2) Shuffle");
  59.         System.out.println("3) Display All Cards Remaining In The Deck");
  60.         System.out.println("4) Play Black Jack");
  61.         System.out.println("5) Exit");
  62.     }
  63.     public void displayCardAt(int s)
  64.     {
  65.         int next=0;
  66.         for(int y=0; y<s/13; y++)
  67.         {
  68.             for(int j=0; j<=9; j++)
  69.             {
  70.                 for(int x=0; x<13;x++)
  71.                 {
  72.                     deck[x+(13*y)].displayCard(j);
  73.                 }
  74.             System.out.println("");
  75.             }  
  76.             next =y;
  77.         }
  78.        
  79.        
  80.             for(int j=0; j<=9; j++)
  81.             {
  82.                 for(int x=0; x<s%13;x++)
  83.                 {
  84.                     deck[x+(13*(next+1))].displayCard(j);
  85.                 }
  86.             System.out.println("");
  87.             }  
  88.        
  89.     }
  90.     public void shuffle()
  91.     {
  92.         int x,y;
  93.         Card temp;
  94.         Random r = new Random();
  95.         for(int i=0; i<1000000;i++)
  96.             {
  97.                 x = r.nextInt(52-count);
  98.                 y = r.nextInt(52-count);
  99.                 temp = deck[x];
  100.                 deck[x]= deck[y];
  101.                 deck[y] = temp;
  102.             }
  103.     }
  104.    
  105.    
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement