Commit fb86f6e3 by willgonzz

Initial commit

parents
public class MainWilliam{
public static void main(String[] args) {
Poker p=new Poker();
String c[]={"2S","3S","4S","5S","6S"};
p.setCartas(c);
p.recorrer();
String d[]={"2S","2C","2D","2H","6S"};
p.setCartas(d);
p.recorrer();
String full[]={"2S","3S","2C","3D","3H"};
p.setCartas(full);
p.recorrer();
String color[]={"2S","3S","4S","5S","8S"};
p.setCartas(color);
p.recorrer();
String escalera[]={"3H","4D","5C","6S","7S"};
p.setCartas(escalera);
p.recorrer();
String trio[]={"3S","2C","3D","3H","4S"};
p.setCartas(trio);
p.recorrer();
String doblePar[]={"3D","3H","4S","4D","7H"};
p.setCartas(doblePar);
p.recorrer();
String doble[]={"3D","3H","4S","2D","5S"};
p.setCartas(doble);
p.recorrer();
String cartaAlta[]={"4S","9D","2S","3H","5C"};
p.setCartas(cartaAlta);
p.recorrer();
}
}
\ No newline at end of file
public class PokerWilliam{
private String cartas[];
public Poker() {
this.cartas=new String[5];
}
public String[] getCartas() {
return this.cartas;
}
public void setCartas(String[] cartas) {
this.cartas = cartas;
}
public static int convertir(char a){
if(a!='A'||a!='T'||a!='J'||a!='Q'||a!='K'){
return Character.getNumericValue(a);
}else if(a=='A'){
return 1;
}else if(a=='T'){
return 10;
}else if(a=='J'){
return 11;
}else if(a=='Q'){
return 12;
}else if(a=='K'){
return 13;
}else{
return 0;
}
}
public static void ordenarInt(int a[]){
int aux;
for(int i=0; i<4;i++){
for(int j=i+1;j<5;j++){
if(a[i]>a[j]){
aux=a[i];
a[i]=a[j];
a[j]=aux;
}
}
}
}
public static int iguales(int a[]){
ordenarInt(a);
int c=1;
int auxdoble=0;
int auxtriple=0;
for(int i=0;i<4;i++){
if(a[i]==a[i+1]){
c++;
if(c==2){
auxdoble++;
}else if(c==3){
auxdoble--;
auxtriple++;
}else if(c==4){
return 4;
}
}else if(i!=4){
c=1;
}
}
if(auxtriple==1 && auxdoble==1){
return 3;
}else if(auxtriple==1){
return 2;
}else if(auxdoble==2){
return 1;
}else if(auxdoble==1){
return 0;
}else{
return -1;
}
}
public static void ordenarString(char a[]){
char aux;
for(int i=0; i<4;i++){
for(int j=i+1;j<5;j++){
if(a[i]>a[j]){
aux=a[i];
a[i]=a[j];
a[j]=aux;
}
}
}
}
public static int verificaPalo(char palo[]){
ordenarString(palo);
int c=1;
for(int i=0;i<4;i++){
if(palo[i]==palo[i+1]){
c++;
}
}
if(c==5){
return 2;
}else if(c==4){
return 1;
}else{
return 0;
}
}
public static int verificasucesion(int a[]){
ordenarInt(a);
int c=1;
if(a[0]==1){
for(int i=0;i<4;i++){
if(a[i]==(a[i+1]+1)){
c++;
}else{
break;
}
}
if(c==5){
return c;
}
c=1;
for(int i=1; i<5;i++){
a[i-1]=a[i];
}
a[4]=14;
for(int i=0;i<4;i++){
if(a[i]==(a[i+1]+1)){
c++;
}else{
break;
}
}
}else{
for(int i=0;i<4;i++){
if(a[i]+1==(a[i+1])){
c++;
}else{
break;
}
}
}
return c;
}
public void recorrer(){
int j=0;
char tipo[]=new char[5];
int i[]=new int[5];
for(String carta: this.cartas){
i[j]=convertir(carta.charAt(0));
tipo[j]=carta.charAt(1);
System.out.print(carta+"|");
j++;
}
if(verificaPalo(tipo)==2 && verificasucesion(i)==5){
System.out.println("\nUsted tiene una Escalera Color");
}else if(iguales(i)==4){
System.out.println("\nUsted tiene una Poker");
}else if(iguales(i)==3){
System.out.println("\nUsted tiene Full");
}else if(verificaPalo(tipo)==2){
System.out.println("\nUsted tiene color");
}else if(verificasucesion(i)==5){
System.out.println("\nUsted tiene escalera");
}else if(iguales(i)==2){
System.out.println("\nUsted tiene trio");
}else if(iguales(i)==1){
System.out.println("\nUsted tiene par doble");
}else if(iguales(i)==0){
System.out.println("\nUsted tiene par");
}else{
System.out.println("\nUsted tiene carta Alta");
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment