I'm pretty new to programming and I was assigned a code where I have to deal 6 random numbers from 1 to 52 to three different players(objects). These numbers need to be transformed to their card values from 1 to 13 afterwards.
After generating the first hand (1 to 52 random values) I used another similar method to assign the new values (1-13) but whenever I go ahead and try to perform another action with them I get the same value from the first set assigned (1-52)
Here's my code so far
public void seleccionarCartas(){ //Selects an initial value for the cards
c1 = mazo[random.nextInt(mazo.length)];
c2 = mazo[random.nextInt(mazo.length)];
c3 = mazo[random.nextInt(mazo.length)];
c4 = mazo[random.nextInt(mazo.length)];
c5 = mazo[random.nextInt(mazo.length)];
c6 = mazo[random.nextInt(mazo.length)];
}
public void crearMano(){ //verifies that the card values are not repeated
if (c1==c2) {
c1 = mazo[random.nextInt(mazo.length)];
System.out.println(c1);
} else if (c1==c3){
c1 = mazo[random.nextInt(mazo.length)];
System.out.println(c1);
} else if (c1 == c4){
c1 = mazo[random.nextInt(mazo.length)];
System.out.println(c1);
} else if (c1==c5) {
c1 = mazo[random.nextInt(mazo.length)];
System.out.println(c1);
} else if (c1==c6){
c1 = mazo[random.nextInt(mazo.length)];
System.out.println(c1);
} else {
System.out.println(c1);
}
if (c2==c1) {
c2 = mazo[random.nextInt(mazo.length)];
System.out.println(c2);
} else if (c2==c3){
c2 = mazo[random.nextInt(mazo.length)];
System.out.println(c2);
} else if (c2 == c4){
c2 = mazo[random.nextInt(mazo.length)];
System.out.println(c2);
} else if (c2==c5) {
c2 = mazo[random.nextInt(mazo.length)];
System.out.println(c2);
} else if (c2==c6){
c2 = mazo[random.nextInt(mazo.length)];
System.out.println(c2);
} else{
System.out.println(c2);
}
if (c3==c2) {
c3 = mazo[random.nextInt(mazo.length)];
System.out.println(c3);
} else if (c3==c1){
c3 = mazo[random.nextInt(mazo.length)];
System.out.println(c3);
} else if (c3 == c4){
c3 = mazo[random.nextInt(mazo.length)];
System.out.println(c3);
} else if (c3==c5) {
c3 = mazo[random.nextInt(mazo.length)];
System.out.println(c3);
} else if (c3==c6){
c3 = mazo[random.nextInt(mazo.length)];
System.out.println(c3);
} else {
System.out.println(c3);
}
if (c4==c2) {
c4 = mazo[random.nextInt(mazo.length)];
System.out.println(c4);
} else if (c4==c3){
c4 = mazo[random.nextInt(mazo.length)];
System.out.println(c4);
} else if (c4 == c1){
c4 = mazo[random.nextInt(mazo.length)];
System.out.println(c4);
} else if (c4==c5) {
c4 = mazo[random.nextInt(mazo.length)];
System.out.println(c4);
} else if (c4==c6){
c4 = mazo[random.nextInt(mazo.length)];
System.out.println(c4);
} else {
System.out.println(c4);
}
if (c5==c2) {
c5 = mazo[random.nextInt(mazo.length)];
System.out.println(c5);
} else if (c5==c3){
c5 = mazo[random.nextInt(mazo.length)];
System.out.println(c5);
} else if (c5 == c4){
c5 = mazo[random.nextInt(mazo.length)];
System.out.println(c5);
} else if (c5==c1) {
c5 = mazo[random.nextInt(mazo.length)];
System.out.println(c5);
} else if (c5==c6){
c5 = mazo[random.nextInt(mazo.length)];
System.out.println(c5);
} else {
System.out.println(c5);
}
if (c6==c2) {
c6 = mazo[random.nextInt(mazo.length)];
System.out.println(c6);
} else if (c6==c3){
c6 = mazo[random.nextInt(mazo.length)];
System.out.println(c6);
} else if (c6 == c4){
c6 = mazo[random.nextInt(mazo.length)];
System.out.println(c6);
} else if (c6==c5) {
c6 = mazo[random.nextInt(mazo.length)];
System.out.println(c6);
} else if (c6==c1){
c6 = mazo[random.nextInt(mazo.length)];
System.out.println(c6);
} else {
System.out.println(c6);
}
}
public void asignarValores(){ //supposed to assign the new value to the variable, but it prints/uses the previous one
if (c1==1 && c1==14 && c1==27 && c1==40){
c1 = 1;
} else if (c1==2 && c1==15 && c1==28 && c1==41){
c1 = 2;
} else if (c1==3 && c1==16 && c1== 29 && c1 ==42){
c1 = 3;
} else if (c1==4 && c1==17 && c1== 30 && c1 ==43){
c1 = 4;
} else if (c1==5 && c1==18 && c1== 31 && c1 ==44){
c1 = 5;
} else if (c1==6 && c1==19 && c1== 32 && c1 ==45){
c1 = 6;
} else if (c1==7 && c1==20 && c1== 33 && c1 ==46){
c1 = 7;
} else if (c1==8 && c1==21 && c1== 34 && c1 ==47){
c1 = 8;
} else if (c1==9 && c1==22 && c1== 35 && c1 ==48){
c1 = 9;
} else if (c1==10 && c1==23 && c1== 36 && c1 ==49){
c1 = 10;
} else if (c1==11 && c1==24 && c1== 37 && c1 ==50){
c1 = 11;
} else if (c1==12 && c1==25 && c1== 38 && c1 ==51){
c1 = 12;
} else if (c1==13 && c1==26 && c1== 39 && c1 ==52){
c1 = 13;
}
if (c2==1 && c2==14 && c2==27 && c2==40){
c2 = 1;
} else if (c2==2 && c2==15 && c2==28 && c2==41){
c2 = 2;
} else if (c2==3 && c2==16 && c2== 29 && c2 ==42){
c2 = 3;
} else if (c2==4 && c2==17 && c2== 30 && c2 ==43){
c2 = 4;
} else if (c2==5 && c2==18 && c2== 31 && c2 ==44){
c2 = 5;
} else if (c2==6 && c2==19 && c2== 32 && c2 ==45){
c2 = 6;
} else if (c2==7 && c2==20 && c2== 33 && c2 ==46){
c2 = 7;
} else if (c2==8 && c2==21 && c2== 34 && c2 ==47){
c2 = 8;
} else if (c2==9 && c2==22 && c2== 35 && c2 ==48){
c2 = 9;
} else if (c2==10 && c2==23 && c2== 36 && c2 ==49){
c2 = 10;
} else if (c2==11 && c2==24 && c2== 37 && c2 ==50){
c2 = 11;
} else if (c2==12 && c2==25 && c2== 38 && c2 ==51){
c2 = 12;
} else if (c2==13 && c2==26 && c2== 39 && c2 ==52){
c2 = 13;
}
if (c3==1 && c3==14 && c3==27 && c3==40){
c3 = 1;
} else if (c3==2 && c3==15 && c3==28 && c3==41){
c3 = 2;
} else if (c3==3 && c3==16 && c3== 29 && c3 ==42){
c3 = 3;
} else if (c3==4 && c3==17 && c3== 30 && c3 ==43){
c3 = 4;
} else if (c3==5 && c3==18 && c3== 31 && c3 ==44){
c3 = 5;
} else if (c3==6 && c3==19 && c3== 32 && c3 ==45){
c3 = 6;
} else if (c3==7 && c3==20 && c3== 33 && c3 ==46){
c3 = 7;
} else if (c3==8 && c3==21 && c3== 34 && c3 ==47){
c3 = 8;
} else if (c3==9 && c3==22 && c3== 35 && c3 ==48){
c3 = 9;
} else if (c3==10 && c3==23 && c3== 36 && c3 ==49){
c3 = 10;
} else if (c3==11 && c3==24 && c3== 37 && c3 ==50){
c3 = 11;
} else if (c3==12 && c3==25 && c3== 38 && c3 ==51){
c3 = 12;
} else if (c3==13 && c3==26 && c3== 39 && c3 ==52){
c3 = 13;
}
if (c4==1 && c4==14 && c4==27 && c4==40){
c4 = 1;
} else if (c4==2 && c4==15 && c4==28 && c4==41){
c4 = 2;
} else if (c4==3 && c4==16 && c4== 29 && c4 ==42){
c4 = 3;
} else if (c4==4 && c4==17 && c4== 30 && c4 ==43){
c4 = 4;
} else if (c4==5 && c4==18 && c4== 31 && c4 ==44){
c4 = 5;
} else if (c4==6 && c4==19 && c4== 32 && c4 ==45){
c4 = 6;
} else if (c4==7 && c4==20 && c4== 33 && c4 ==46){
c4 = 7;
} else if (c4==8 && c4==21 && c4== 34 && c4 ==47){
c4 = 8;
} else if (c4==9 && c4==22 && c4== 35 && c4 ==48){
c4 = 9;
} else if (c4==10 && c4==23 && c4== 36 && c4 ==49){
c4 = 10;
} else if (c4==11 && c4==24 && c4== 37 && c4 ==50){
c4 = 11;
} else if (c4==12 && c4==25 && c4== 38 && c4 ==51){
c4 = 12;
} else if (c4==13 && c4==26 && c4== 39 && c4 ==52){
c4 = 13;
}
if (c5==1 && c5==14 && c5==27 && c5==40){
c5 = 1;
} else if (c5==2 && c5==15 && c5==28 && c5==41){
c5 = 2;
} else if (c5==3 && c5==16 && c5== 29 && c5 ==42){
c5 = 3;
} else if (c5==4 && c5==17 && c5== 30 && c5 ==43){
c5 = 4;
} else if (c5==5 && c5==18 && c5== 31 && c5 ==44){
c5 = 5;
} else if (c5==6 && c5==19 && c5== 32 && c5 ==45){
c5 = 6;
} else if (c5==7 && c5==20 && c5== 33 && c5 ==46){
c5 = 7;
} else if (c5==8 && c5==21 && c5== 34 && c5 ==47){
c5 = 8;
} else if (c5==9 && c5==22 && c5== 35 && c5 ==48){
c5 = 9;
} else if (c5==10 && c5==23 && c5== 36 && c5 ==49){
c5 = 10;
} else if (c5==11 && c5==24 && c5== 37 && c5 ==50){
c5 = 11;
} else if (c5==12 && c5==25 && c5== 38 && c5 ==51){
c5 = 12;
} else if (c5==13 && c5==26 && c5== 39 && c5 ==52){
c5 = 13;
}
if (c6==1 && c6==14 && c6==27 && c6==40){
c6 = 1;
} else if (c6==2 && c6==15 && c6==28 && c6==41){
c6 = 2;
} else if (c6==3 && c6==16 && c6== 29 && c6 ==42){
c6 = 3;
} else if (c6==4 && c6==17 && c6== 30 && c6 ==43){
c6 = 4;
} else if (c6==5 && c6==18 && c6== 31 && c6 ==44){
c6 = 5;
} else if (c6==6 && c6==19 && c6== 32 && c6 ==45){
c6 = 6;
} else if (c6==7 && c6==20 && c6== 33 && c6 ==46){
c6 = 7;
} else if (c6==8 && c6==21 && c6== 34 && c6 ==47){
c6 = 8;
} else if (c6==9 && c6==22 && c6== 35 && c6 ==48){
c6 = 9;
} else if (c6==10 && c6==23 && c6== 36 && c6 ==49){
c6 = 10;
} else if (c6==11 && c6==24 && c6== 37 && c6 ==50){
c6 = 11;
} else if (c6==12 && c6==25 && c6== 38 && c6 ==51){
c6 = 12;
} else if (c6==13 && c6==26 && c6== 39 && c6 ==52){
c6 = 13;
}
}
Aucun commentaire:
Enregistrer un commentaire