From 10f9d3f29c2fa97a5ffd54ea0ab4a7af519ef9a1 Mon Sep 17 00:00:00 2001 From: Yovan Martinez Date: Tue, 26 Apr 2022 13:26:19 -0400 Subject: [PATCH] Creacion clase poker --- Poker.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Poker.java diff --git a/Poker.java b/Poker.java new file mode 100644 index 0000000..9d8eedd --- /dev/null +++ b/Poker.java @@ -0,0 +1,101 @@ +public class Poker { + + public String valoracionMano(){ + if (controlPalos(getSuit()) == 25 && controlValor(getValue()).equals("ESCALERA")){ + return "ESCALERA COLOR"; + }else if(controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("POKER")){ + return "POKER"; + }else if (controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("FULL")) { + return "FULL"; + }else if (controlPalos(getSuit()) == 25 && controlValor(getValue()).equals("NADA") ) { + return "COLOR"; + }else if (controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("ESCALERA") ) { + return "ESCALERA"; + }else if (controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("TRIO") ) { + return "TRIO"; + }else if (controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("PAR") ) { + return "PAR"; + }else if (controlPalos(getSuit()) < 25 && controlValor(getValue()).equals("PAR DOBLE") ) { + return "PAR DOBLE"; + } + return "NADA"; + } + public String controlPalos(String palos){ + int contador = 0; + for (int i = 0; i < palos.length(); i++) { + for (int j = 0; j < palos.length(); j++) { + if (palos.charAt(i) == palos.charAt(j)) { + contador++; + } + } + } + if (contador == 25) { + return "COLOR" + } else { + + } + return contador; + } + //***********CONTROLA QUE JUGADA SE DA EN LOS VALORES + public String controlValor(String valores){ + int contador = 0; + int secuencial = 0; + boolean thereIsLetter = false; + for (int i = 0; i < valores.length(); i++) { + for (int j = 0; j < valores.length(); j++) { + if (valores.charAt(i) == valores.charAt(j)) { + contador++; + } + } + } + if (contador < 6) { + //controla que existan letras en los valores mandados + for (int i = 0; i < valores.length(); i++) { + String l = String.valueOf(valores.charAt(i)); + if (l == "T" || l == "J" || l == "Q" || l == "K" || l == "A") { + thereIsLetter = true; + break; + } + } + //Una condicional para el caso que existan letras + if(thereIsLetter == false){ + //Para mejor entendimiento visual lo guardo en una variable de nombre mas corto + String v = getValue(); + if ( (v.equals("89JQT")) || (v.equals("9JKQT")) || ((v).equals("AJKQT")) ||(v.equals("2345A")) || (v.equals("789JT")) ||(v.equals("6789T"))){ + return "ESCALERA"; + } + }else{ + for (int i = 1; i < valores.length(); i++) { + if (valores.charAt(i) == valores.charAt(i-1) + 1) { + secuencial++; + } + } + if (secuencial == 4) { + return "ESCALERA"; + } + } + }else if (contador == 17) { + return "POKER"; + }else if(contador == 13){ + return "FULL"; + }else if(contador == 11){ + return "TRIO"; + }else if(contador == 9){ + return "PAR DOBLE"; + }else if(contador == 7){ + return "PAR"; + } + return "NADA"; + } + public static void main(String[] args) { + + Carta cartas = new Carta(); + String [] mano = new String []{"TH","JH","QH","KH","AH"}; + for (int i = 0; i < mano.length; i++) { + cartas.armarPalos(mano[i]); + cartas.armarValores(mano[i]); + } + System.out.println(cartas.valoracionMano()); + + } +} -- libgit2 0.26.0