Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Card {
- //making it so there is no Houdini numbers
- final int PAIR = 2;
- final int SET = 4;
- int draw = 0;
- //used for generating random numbers
- Random ran = new Random();
- //setting the suit length to 13
- final int SUIT_LENGTH = 13;
- //declaring where the numbers are for the suit so exp.
- // Heart of spades = 14+1 =15 (Ace of Hearts is number 15)
- final int SPADE = 1;
- final int HEART = 14;
- final int DIAMOND = 27;
- final int CLUB = 40;
- //setting an array of values for 0-12 (really 1-13)
- int [] VALUE = { 0,1,2,3,4,5,6,7,8,9,10,11,12 };
- //taking the suit numbers from above and adding them to an array
- //so i can call on them using value + suit = card.
- int [] SUIT = {SPADE,HEART,DIAMOND,CLUB};
- //these 4 arrays are set to 2 so I can make it so
- // grab 2 numbers from value and one from suit.
- int firstPick[] = new int [PAIR];
- int secondPick[] = new int [PAIR];
- int thirdPick[] = new int [PAIR];
- int forthPick[] = new int [PAIR];
- //taking the firstPick area
- int cards [ ] = new int [SET];
- public void Card()
- {
- setCard();
- }
- public void setCard()
- {
- //this grabs the suit and the value for secondpick array
- firstPick[0] = SUIT[ran.nextInt(SUIT.length)];
- firstPick[1] = VALUE[ran.nextInt(VALUE.length)];
- draw++;
- do {
- //makes sure that the
- secondPick[0] = SUIT[ran.nextInt(SUIT.length)];
- secondPick[1] = VALUE[ran.nextInt(VALUE.length)];
- draw++;
- } while (firstPick[0] != secondPick[0]);
- do{
- thirdPick[0] = SUIT[ran.nextInt(SUIT.length)];
- thirdPick[1] = VALUE[ran.nextInt(VALUE.length)];
- draw++;
- }while (secondPick[0] != thirdPick[0] &&
- thirdPick[0] != firstPick[0]);
- do{
- forthPick[0] = SUIT[ran.nextInt(SUIT.length)];
- forthPick[1] = VALUE[ran.nextInt(VALUE.length)];
- }while (thirdPick[0] != forthPick[0] &&
- forthPick[0] != secondPick[0] &&
- forthPick[0] != thirdPick[0]);
- }
- public void getCard()
- {
- cards[0] = firstPick[0] + firstPick[1];
- cards[1] = secondPick[0] + secondPick[1];
- cards[2] = thirdPick[0] + thirdPick[1];
- cards[3] = forthPick[0] + forthPick[1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment