From be623b332fb633c1dc9957d2b841e39bd2a5c86b Mon Sep 17 00:00:00 2001 From: JoseBaezx Date: Tue, 26 Apr 2022 16:57:24 -0400 Subject: [PATCH] Se agrega metodo para verificar escalera color y solo escalera --- .idea/inspectionProfiles/Project_Default.xml | 10 ++++++++++ Carta.java | 2 ++ Juego.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- Main.java | 41 +++++++++++++++-------------------------- out/production/poker/.idea/inspectionProfiles/Project_Default.xml | 10 ++++++++++ out/production/poker/Carta.class | Bin 1220 -> 0 bytes out/production/poker/Juego.class | Bin 636 -> 0 bytes out/production/poker/Main.class | Bin 2775 -> 0 bytes 8 files changed, 152 insertions(+), 28 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 out/production/poker/.idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6e3ba12 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/Carta.java b/Carta.java index 2852040..8237e25 100644 --- a/Carta.java +++ b/Carta.java @@ -1,3 +1,5 @@ +import java.util.Objects; + public class Carta { public String valor; public String palo; diff --git a/Juego.java b/Juego.java index 6153fd4..547c07b 100644 --- a/Juego.java +++ b/Juego.java @@ -1,15 +1,128 @@ +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class Juego { - static List escalera= Arrays.asList("2S", "3S", "4S", "5S", "6S"); + List valores = null; public Juego() { } + public void juegosPosibles(List cartas){ + boolean siguiente = true; + if(escaleraColor(cartas)){ + siguiente =false; + System.out.println("ESCALERA COLOR"); + } + if(siguiente && escalera(cartas)){ + System.out.println("ESCALERA"); + } + } + + public boolean escalera(List cartas) { + int contador = 0; + List valores = new ArrayList<>(); + + for (Carta c : cartas) { + valores.add(extraer(c.valor)); + } + Collections.sort(valores); + valores.forEach(System.out::println); + + int[] valoresArry = pasarAArray(valores); + for (int i = 0; i < valoresArry.length - 1; i++) { + + if (valoresArry[i] > 1) { + if (valoresArry[i + 1] - valoresArry[i] != 1) { + return false; + } else { + return true; + } + } + + contador += valoresArry[i]; + if (contador == 34 && valoresArry[0] == 1) { + return true; + } + } + return false; + } + + public boolean escaleraColor(List cartas) { + boolean valor1 = true; + String valuePalo = estraerPalo(cartas); + for (int i = 0; i < cartas.size(); i++) { + if (!valuePalo.equals(cartas.get(i).palo)) { + valor1 = false; + } + } + int contador = 0; + List valores = new ArrayList<>(); + if (valor1) { + for (Carta c : cartas) { + valores.add(extraer(c.valor)); + } + Collections.sort(valores); + valores.forEach(System.out::println); + + int[] valoresArry = pasarAArray(valores); + for (int i = 0; i < valoresArry.length - 1; i++) { - public void escalera(){ + if (valoresArry[i] > 1) { + if (valoresArry[i + 1] - valoresArry[i] != 1) { + return false; + } else { + return true; + } + } + + contador += valoresArry[i]; + if (contador == 34 && valoresArry[0] == 1) { + return true; + } + } + } + + return false; + + } + + private int[] pasarAArray(List valores) { + int[] value = new int[5]; + for (int i = 0; i < valores.size(); i++) { + value[i] = valores.get(i); + } + return value; + } + + public Integer extraer(String carta) { + int valor = 0; + if (carta.equals("A")) { + return valor = 1; + } + if (carta.equals("T")) { + return valor = 10; + } + if (carta.equals("J")) { + return valor = 11; + } + if (carta.equals("Q")) { + return valor = 12; + } + if (carta.equals("K")) { + return valor = 13; + } + return Integer.valueOf(carta); + } + public String estraerPalo(List cartas) { + String value = ""; + for (Carta c : cartas) { + value = c.palo; + break; + } + return value; } } diff --git a/Main.java b/Main.java index b4b91b5..f39b1f9 100644 --- a/Main.java +++ b/Main.java @@ -1,42 +1,31 @@ +import com.sun.jdi.Value; + import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { - Juego g = new Juego(); + Juego j = new Juego(); - boolean valor1 = true; List cartas = new ArrayList<>(); cartas = Arrays.asList( - new Carta("AS"), - new Carta("2S"), - new Carta("3S"), - new Carta("4S"), - new Carta("5S") + new Carta("7H"), + new Carta("8H"), + new Carta("9H"), + new Carta("JH"), + new Carta("TH") ); - cartas.stream().collect(Collectors.toList()); + + cartas.forEach(System.out::print); + cartas.sort(Comparator.comparing(carta -> carta.valor)); + System.out.println(); cartas.forEach(System.out::print); System.out.println(); - List carta= Arrays.asList("2S", "3S", "4S", "5S", "6S"); - for (Carta c: cartas){ - if(!c.palo.equals("S")){ - valor1=false; - } - } - for (int i = 0; i + + + \ No newline at end of file diff --git a/out/production/poker/Carta.class b/out/production/poker/Carta.class index 6098b16..22b01db 100644 Binary files a/out/production/poker/Carta.class and b/out/production/poker/Carta.class differ diff --git a/out/production/poker/Juego.class b/out/production/poker/Juego.class index 2768e94..113997e 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 99b5424..65542ef 100644 Binary files a/out/production/poker/Main.class and b/out/production/poker/Main.class differ -- libgit2 0.26.0