From 2f079f95e4b24f652effc06a4255ed6328be6ec7 Mon Sep 17 00:00:00 2001 From: JoseBaezx Date: Thu, 28 Apr 2022 10:35:59 -0400 Subject: [PATCH] Se crea metodo para comporar mano de carta --- .idea/vcs.xml | 6 ++++++ out/production/java-e005-poker-02/Carta.class | Bin 2086 -> 0 bytes out/production/java-e005-poker-02/Juego.class | Bin 6585 -> 0 bytes out/production/java-e005-poker-02/MyClass.class | Bin 2276 -> 0 bytes src/Carta.java | 44 ++++++++++++++++++++++++++++---------------- src/Juego.java | 70 +++++++++++++++++++++++++++++++++++++++++----------------------------- src/MyClass.java | 33 ++++++++++++++++----------------- 7 files changed, 91 insertions(+), 62 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/java-e005-poker-02/Carta.class b/out/production/java-e005-poker-02/Carta.class index 68bc665..c43fcd9 100644 Binary files a/out/production/java-e005-poker-02/Carta.class and b/out/production/java-e005-poker-02/Carta.class differ diff --git a/out/production/java-e005-poker-02/Juego.class b/out/production/java-e005-poker-02/Juego.class index 3f93001..96a0714 100644 Binary files a/out/production/java-e005-poker-02/Juego.class and b/out/production/java-e005-poker-02/Juego.class differ diff --git a/out/production/java-e005-poker-02/MyClass.class b/out/production/java-e005-poker-02/MyClass.class index 48fefca..5f6ba5a 100644 Binary files a/out/production/java-e005-poker-02/MyClass.class and b/out/production/java-e005-poker-02/MyClass.class differ diff --git a/src/Carta.java b/src/Carta.java index e121c84..a0126df 100644 --- a/src/Carta.java +++ b/src/Carta.java @@ -2,14 +2,30 @@ import java.util.ArrayList; import java.util.List; public class Carta { - String valor; - String palo; + private String valor; + private String palo; public Carta() { valorAleatorio(); paloAleatorio(); } + 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; + } + public Carta(String completo) { String a = String.valueOf(completo.charAt(0)); String b = String.valueOf(completo.charAt(1)); @@ -29,24 +45,22 @@ public class Carta { for (int i = 0; i < 1; i++) { if(rand==10){ this.valor="T"; - continue; } - - if(rand==11){ + else if(rand==11){ this.valor="J"; - continue; } - if(rand==12){ + else if(rand==12){ this.valor="Q"; - continue; } - if(rand==13){ + else if(rand==13){ this.valor="K"; - continue; } - if(rand==14){ + else if(rand==14){ this.valor="A"; - }else { + } + else if (rand==1) { + this.valor="A"; + } else { this.valor=String.valueOf(rand); } } @@ -63,13 +77,11 @@ public class Carta { for (int i = 0; i < 1; i++) { if(rand==1){ this.palo="C"; - continue; } - if(rand==2){ + else if (rand==2){ this.palo="H"; - continue; } - if(rand==4){ + else if(rand==4){ this.palo="D"; }else { this.palo="S"; diff --git a/src/Juego.java b/src/Juego.java index fd5aa3e..51653d2 100644 --- a/src/Juego.java +++ b/src/Juego.java @@ -7,51 +7,67 @@ public class Juego { public Juego() { } - - public void juegosPosibles(List cartas) { + public String mano1VsMano2(int carta1, int carta2) { + if(carta1 > carta2){ + return "1"; + }else if(carta1 < carta2){ + return "2"; + } else if (carta1==carta2) { + return "SON IGUALES"; + } + return "NO HAY GANADOR"; + } + public int juegosPosibles(List cartas) { boolean siguiente = true; if (escaleraColor(cartas)) { siguiente = false; System.out.println("ESCALERA COLOR"); + return 9; } if (siguiente && poker(cartas)) { siguiente = false; - System.out.println("POKER"); + System.out.println("ESCALERA COLOR"); + return 8; } if (siguiente && full(cartas)) { siguiente = false; - System.out.println("FULL"); + System.out.println("ESCALERA COLOR"); + return 7; } if (siguiente && escalera(cartas)) { siguiente = false; System.out.println("ESCALERA"); + return 6; } if (siguiente && color(cartas)) { siguiente = false; System.out.println("COLOR"); + return 5; } if (siguiente && trio(cartas)) { siguiente = false; System.out.println("TRIO"); + return 4; } if (siguiente && parDoble(cartas)) { siguiente = false; System.out.println("PAR DOBLE"); + return 3; } if (siguiente && par(cartas)) { siguiente = false; System.out.println("PAR"); + return 1; } - if (siguiente) { - System.out.println("CARTA ALTA"); - } + System.out.println("CARTA ALTA"); + return 0; } public boolean par(List cartas) { if (cantidadPalosIguales(cartas) < 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); int[] numerosArray = pasarAArray(valores); @@ -72,7 +88,7 @@ public class Juego { if (cantidadPalosIguales(cartas) < 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); int[] numerosArray = pasarAArray(valores); @@ -92,7 +108,7 @@ public class Juego { public boolean trio(List cartas) { List valores = new ArrayList<>(); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } //Collections.sort(valores); int[] numerosArray = pasarAArray(valores); @@ -123,7 +139,7 @@ public class Juego { if (cantidadPalosIguales(cartas) == 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); int[] numerosArray = pasarAArray(valores); @@ -150,7 +166,7 @@ public class Juego { List valores = new ArrayList<>(); cantidadPalosIguales(cartas); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); int counter = 0; @@ -182,16 +198,16 @@ public class Juego { int contador = 0; for (Carta c : cartas) { - if (c.palo.equals("K")) { + if (c.getPalo().equals("K")) { contador++; } - if (c.palo.equals("Q")) { + if (c.getPalo().equals("Q")) { contador++; } - if (c.palo.equals("K")) { + if (c.getPalo().equals("K")) { contador++; } - if (c.palo.equals("C")) { + if (c.getPalo().equals("C")) { contador++; } } @@ -203,7 +219,7 @@ public class Juego { public boolean color(List cartas) { String valuePalo = estraerPrimerPalo(cartas); for (int i = 0; i < cartas.size(); i++) { - if (!valuePalo.equals(cartas.get(i).palo)) { + if (!valuePalo.equals(cartas.get(i).getPalo())) { return false; } } @@ -215,7 +231,7 @@ public class Juego { List valores = new ArrayList<>(); for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); //valores.forEach(System.out::println); @@ -241,7 +257,7 @@ public class Juego { boolean valor1 = true; String valuePalo = estraerPrimerPalo(cartas); for (int i = 0; i < cartas.size(); i++) { - if (!valuePalo.equals(cartas.get(i).palo)) { + if (!valuePalo.equals(cartas.get(i).getPalo())) { valor1 = false; } } @@ -249,7 +265,7 @@ public class Juego { List valores = new ArrayList<>(); if (valor1) { for (Carta c : cartas) { - valores.add(convertirValorStringAInteger(c.valor)); + valores.add(convertirValorStringAInteger(c.getValor())); } Collections.sort(valores); //valores.forEach(System.out::println); @@ -287,17 +303,13 @@ public class Juego { int valor = 0; if (carta.equals("A")) { return valor = 1; - } - if (carta.equals("T")) { + }else if (carta.equals("T")) { return valor = 10; - } - if (carta.equals("J")) { + }else if (carta.equals("J")) { return valor = 11; - } - if (carta.equals("Q")) { + }else if (carta.equals("Q")) { return valor = 12; - } - if (carta.equals("K")) { + }else if (carta.equals("K")) { return valor = 13; } return Integer.valueOf(carta); @@ -306,7 +318,7 @@ public class Juego { public String estraerPrimerPalo(List cartas) { String value = ""; for (Carta c : cartas) { - value = c.palo; + value = c.getPalo(); break; } return value; diff --git a/src/MyClass.java b/src/MyClass.java index 527870c..55be4d8 100644 --- a/src/MyClass.java +++ b/src/MyClass.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class MyClass { @@ -7,32 +8,23 @@ public class MyClass { // pero la corrección del ejercicio será automática en base a este // método que está acá public String ganadores(List jugadas) { + int cont=1; System.out.println("Cantidad de jugadas: " + jugadas.size()); for (Carta[] mano : jugadas) { - System.out.println("JUGADA ======================"); + System.out.println("JUGADA "+cont+" ======================"); + cont++; for (Carta c : mano) { - System.out.println(c.valorPalo()); + System.out.print("["+c.valorPalo()+"] "); } + System.out.println(); } - return "0"; + return "Resultados: "; } public static void main(String args[]) { - + Juego j = new Juego(); MyClass mc = new MyClass(); List jugadas = new ArrayList(); -// Carta[] m1 = new Carta[5]; -// m1[0] = new Carta("AH"); -// m1[1] = new Carta("AD"); -// m1[2] = new Carta("TH"); -// m1[3] = new Carta("TC"); -// m1[4] = new Carta("6S"); -// Carta[] m2 = new Carta[5]; -// m2[0] = new Carta("AH"); -// m2[1] = new Carta("KD"); -// m2[2] = new Carta("QH"); -// m2[3] = new Carta("3C"); -// m2[4] = new Carta("3S"); Carta[] m1 = new Carta[5]; m1[0] = new Carta(); m1[1] = new Carta(); @@ -49,6 +41,13 @@ public class MyClass { jugadas.add(m1); jugadas.add(m2); String ganadores = mc.ganadores(jugadas); - System.out.println("Ganadores = " + ganadores); + + System.out.println("\n"+ganadores); + System.out.print("Jugada 1 = "); + int valor = j.juegosPosibles(Arrays.asList(m1[0], m1[1] , m1[2] , m1[3] , m1[4] )); + System.out.print("Jugada 2 = "); + int valor2 = j.juegosPosibles(Arrays.asList(m2[0], m2[1] , m2[2] , m2[3] , m2[4] )); + + System.out.println("GANADOR JUGADA # "+ j.mano1VsMano2(valor,valor2)); } } \ No newline at end of file -- libgit2 0.26.0