Beginner - card game shuffle problem
in
Programming Questions
•
1 year ago
I am working a Crazy 8's game. I'm having trouble with the shuffling part as sometimes it returns a null value.
Sorry for messy code, I started working on other parts of the game before I realized what was going on.
P.S. I was wondering if someone could tell me the difference between and Integer and an int.
- Integer[] deck = new Integer[52];
- Integer[] pickup = new Integer[52];
- //Integer[] discard = new Integer[52];
- int x = 0;
- Player p1;
- Player cpu;
- void setup(){
- p1 = new Player(true);
- cpu = new Player(false);
- for(int i = 1; i < 52; i++){
- deck[i-1] = new Integer(i);
- }
- java.util.Collections.shuffle(java.util.Arrays.asList(deck));
- pickup = deck;
- deal();
- }
- void draw(){}
- void mousePressed(){
- println(cardValue(pickup[x])[1] + " of " + cardValue(pickup[x])[0]);
- x ++;
- }
- void deal(){
- for(int i = 51;i > 37;i--){
- if(i%2 == 0){
- cpu.drawcard(pickup[i]);
- }
- else{
- p1.drawcard(pickup[i]);
- }
- pickup[i] = 0;
- }
- println("cpu cards");
- println();
- cpu.debug();
- println();
- println("P1 cards");
- println();
- p1.debug();
- println();
- println(pickup);
- }
- String[] cardValue(int c){
- int v = c%4;
- if(v == 0){cardValue[0] = "spades";}
- else if(v == 1){cardValue[0] = "clubs";}
- else if(v == 2){cardValue[0] = "diamonds";}
- else{cardValue[0] = "hearts";}
- if(c == 1 || c == 14 || c == 27 || c == 40){cardValue[1] = "ace";}
- else if(c == 2 || c == 15 || c == 28 || c == 41){cardValue[1] = "two";}
- else if(c == 3 || c == 16 || c == 29 || c == 42){cardValue[1] = "three";}
- else if(c == 4 || c == 17 || c == 30 || c == 43){cardValue[1] = "four";}
- else if(c == 5 || c == 18 || c == 31 || c == 44){cardValue[1] = "five";}
- else if(c == 6 || c == 19 || c == 32 || c == 45){cardValue[1] = "six";}
- else if(c == 7 || c == 20 || c == 33 || c == 46){cardValue[1] = "seven";}
- else if(c == 8 || c == 21 || c == 34 || c == 47){cardValue[1] = "eight";}
- else if(c == 9 || c == 22 || c == 35 || c == 48){cardValue[1] = "nine";}
- else if(c == 10 || c == 23 || c == 36 || c == 49){cardValue[1] = "ten";}
- else if(c == 11 || c == 24 || c == 37 || c == 50){cardValue[1] = "jack";}
- else if(c == 12 || c == 25 || c == 38 || c == 51){cardValue[1] = "queen";}
- else{cardValue[1] = "king";}
- return cardValue;
- }
1