From b05dcd6c375c63fcbd1702a04838c359ad9c05c7 Mon Sep 17 00:00:00 2001 From: JoseBaezx Date: Wed, 27 Apr 2022 13:08:39 -0400 Subject: [PATCH] Poker app final 1.1 --- .idea/runConfigurations.xml | 10 ---------- Juego.java | 93 +++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ Main.java | 8 ++++---- out/production/poker/.idea/runConfigurations.xml | 10 ---------- out/production/poker/Juego.class | Bin 6599 -> 0 bytes out/production/poker/Main.class | Bin 2143 -> 0 bytes 6 files changed, 49 insertions(+), 72 deletions(-) delete mode 100644 .idea/runConfigurations.xml delete mode 100644 out/production/poker/.idea/runConfigurations.xml diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Juego.java b/Juego.java index f0c49ac..09fbc4f 100644 --- a/Juego.java +++ b/Juego.java @@ -48,7 +48,7 @@ public class Juego { } public boolean par(List cartas) { - if(comprobarPalo(cartas)<3) { + if (comprobarPalo(cartas) < 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { valores.add(extraer(c.valor)); @@ -67,8 +67,9 @@ public class Juego { } return false; } + public boolean parDoble(List cartas) { - if(comprobarPalo(cartas)<3) { + if (comprobarPalo(cartas) < 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { valores.add(extraer(c.valor)); @@ -87,6 +88,7 @@ public class Juego { } return false; } + public boolean trio(List cartas) { List valores = new ArrayList<>(); for (Carta c : cartas) { @@ -94,96 +96,91 @@ public class Juego { } //Collections.sort(valores); int[] numerosArray = pasarAArray(valores); - int counter=0; - int cantidadNumero=0; - for(int i=11; i<14; i++){ + int counter = 0; + int cantidadNumero = 0; + for (int i = 11; i < 14; i++) { for (int j = 0; j < numerosArray.length - 1; j++) { if (numerosArray[j] == numerosArray[j + 1]) { counter++; - if (counter == 2) { - return true; - } } } - if(counter > cantidadNumero){ + if (counter > cantidadNumero) { - cantidadNumero=counter; + cantidadNumero = counter; } - counter=0; + counter = 0; } - if (cantidadNumero==3){ + if (cantidadNumero == 3) { return true; - }else { + } else { return false; } } //Dos cartas iguales (mismo valor) junto con tres cartas iguales (mismo valor). public boolean full(List cartas) { - if(comprobarPalo(cartas)==3){ + if (comprobarPalo(cartas) == 3) { List valores = new ArrayList<>(); for (Carta c : cartas) { valores.add(extraer(c.valor)); } Collections.sort(valores); int[] numerosArray = pasarAArray(valores); - int con=0; - for (int i = 0; i < numerosArray.length-1; i++) { - if (numerosArray[i] == numerosArray[i+1]) { + int con = 0; + for (int i = 0; i < numerosArray.length - 1; i++) { + if (numerosArray[i] == numerosArray[i + 1]) { con++; - if (con==3 && numerosArray[2] == numerosArray[4]){ + if (con == 3 && numerosArray[2] == numerosArray[4]) { return true; - }else if(con==3 && numerosArray[2] == numerosArray[0]){ + } else if (con == 3 && numerosArray[2] == numerosArray[0]) { return true; } } } return false; - }else { + } else { return false; } } //Cuatro cartas iguales (mismo valor). public boolean poker(List cartas) { - if(comprobarPalo(cartas)==4){ - List valores = new ArrayList<>(); - comprobarPalo(cartas); - for (Carta c : cartas) { - valores.add(extraer(c.valor)); - } - Collections.sort(valores); - int counter=0; - int numero=0; - int cantidadNumero=0; - for(int i=1; i<14; i++){ - for (int j=0; j cantidadNumero){ - numero=i; - cantidadNumero=counter; + + List valores = new ArrayList<>(); + comprobarPalo(cartas); + for (Carta c : cartas) { + valores.add(extraer(c.valor)); + } + Collections.sort(valores); + int counter = 0; + int numero = 0; + int cantidadNumero = 0; + for (int i = 1; i < 14; i++) { + for (int j = 0; j < valores.size(); j++) { + int s = valores.get(j); + if (s == i) { + counter++; } - counter=0; } - if (cantidadNumero==4){ - return true; - }else { - return false; + if (counter > cantidadNumero) { + numero = i; + cantidadNumero = counter; } - - }else { + counter = 0; + } + if (cantidadNumero == 4) { + return true; + } else { return false; } + + } private int comprobarPalo(List cartas) { int contador = 0; - for (Carta c: cartas) { + for (Carta c : cartas) { if (c.palo.equals("K")) { contador++; diff --git a/Main.java b/Main.java index b4a2e2f..3ba68c1 100644 --- a/Main.java +++ b/Main.java @@ -9,11 +9,11 @@ public class Main { List cartas = new ArrayList<>(); cartas = Arrays.asList( - new Carta("TH"), new Carta("TD"), - new Carta("TC"), - new Carta("4D"), - new Carta("AD") + new Carta("KD"), + new Carta("AD"), + new Carta("JD"), + new Carta("QD") ); cartas.forEach(System.out::print); diff --git a/out/production/poker/.idea/runConfigurations.xml b/out/production/poker/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/out/production/poker/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/out/production/poker/Juego.class b/out/production/poker/Juego.class index 4328030..db8b9f6 100644 Binary files a/out/production/poker/Juego.class and b/out/production/poker/Juego.class differ diff --git a/out/production/poker/Main.class b/out/production/poker/Main.class index eea2f97..9fd73a0 100644 Binary files a/out/production/poker/Main.class and b/out/production/poker/Main.class differ -- libgit2 0.26.0