Carta.java 2.46 KB
Newer Older
1 2
import java.util.ArrayList;
import java.util.List;
Jose Baez committed
3
import java.util.Objects;
4 5

public class Carta {
6 7
    private String valor;
    private String palo;
8 9
    private final int MIN=1;
    private final int MAX=4;
10 11 12 13 14 15

    public Carta() {
        valorAleatorio();
        paloAleatorio();
    }

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    public String getValor() {
        return valor;
    }

    public void setValor(String valor) {
        this.valor = valor;
    }

    public String getPalo() {
        return palo;
    }

    public void setPalo(String palo) {
        this.palo = palo;
    }

32 33 34 35 36 37 38 39 40 41 42 43
    public Carta(String completo) {
        String a = String.valueOf(completo.charAt(0));
        String b = String.valueOf(completo.charAt(1));
        this.valor = a.toUpperCase();
        this.palo = b.toUpperCase();
    }

    String valorPalo() {
        return this.valor + this.palo;
    }

    public void valorAleatorio(){
44
        int max = 13;
45 46
        int range = max - MIN + 1;
        int rand = (int)(Math.random() * range) + MIN;
47 48 49 50
        for (int i = 0; i < 1; i++) {
            if(rand==10){
                this.valor="T";
            }
51
            else if(rand==11){
52 53
                this.valor="J";
            }
54
            else if(rand==12){
55 56
                this.valor="Q";
            }
57
            else if(rand==13){
58 59
                this.valor="K";
            }
60 61 62
            else if (rand==1) {
                this.valor="A";
            } else {
63 64 65 66 67 68
                this.valor=String.valueOf(rand);
            }
        }
    }

    public void paloAleatorio(){
69 70
        int range = MAX - MIN + 1;
        int rand = (int)(Math.random() * range) + MIN;
71 72 73 74
        for (int i = 0; i < 1; i++) {
            if(rand==1){
                this.palo="C";
            }
75
            else if (rand==2){
76 77
                this.palo="H";
            }
78
            else if(rand==4){
79 80 81 82 83 84 85
                this.palo="D";
            }else {
                this.palo="S";
            }
        }
    }

Jose Baez committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Carta carta = (Carta) o;
        return Objects.equals(valor, carta.valor) && Objects.equals(palo, carta.palo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(valor, palo);
    }

    @Override
    public String toString() {
        return "Carta{" +
                "valor='" + valor + '\'' +
                ", palo='" + palo + '\'' +
                '}';
    }
106
}