Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.92 KB | None | 0 0
  1. package dados;
  2. import java.util.*;
  3.  
  4.  
  5. public class dados {
  6.    
  7.    
  8.     /*Desde el metodo main el primer metodo de la clase llamdo es el de tirada, a su vez el mismo
  9.      * retorna un array de enteros al metodo tirada_ordenada que trata de un algoritmo de ordenamiento
  10.      * de vectores del tipo burbuja
  11.      */
  12.     public static int[] tirada(int [] jugada) {
  13.         for (int i=0; i<jugada.length; i++) {
  14.             jugada[i]= (int) (Math.random()*(6) + 1);
  15.         }  
  16.         return tirada_ordenada(jugada);
  17.     }
  18.    
  19.     public static int[] tirada_ordenada(int[] jugada) {
  20.         for (int i=0; i<jugada.length;i++ ) {
  21.             for (int j=0; j<(jugada.length -1); j++) {
  22.                 if (jugada[j]>jugada[j+1]) {
  23.                     int aux;
  24.                     aux=jugada[j];
  25.                     jugada[j]=jugada[j+1];
  26.                     jugada[j+1]=aux;
  27.                 }
  28.             }
  29.         }
  30.         return jugada; 
  31.     }
  32.    
  33.     /*este es un metodo vacio que imprime la jugada ordenada */
  34.     public static void mostrar_jugada(int[] jugada) {
  35.         for (int i = 0; i < jugada.length; i++) {
  36.             System.oupokert.print (jugada[i] + " - " );
  37.         }
  38.         System.out.println("");
  39.     }
  40.     /*metodo vacio suma los valores de los dados*/
  41.     public static void sumar_dados(int[] jugada) {
  42.         int suma=0;
  43.         for (int i = 0; i < jugada.length; i++) {
  44.             suma = suma + jugada[i];
  45.         }
  46.         System.out.println("La suma total de los dados es: " + suma);
  47.     }
  48.     /*metodo que retorna un boleano si encuentra uno de los tres tipos de escalera posible*/
  49.     public static boolean check_escalera(int[] jugada) {
  50.         int count = 0;
  51.         if ((jugada[0]==1 && jugada[4]==6) || (jugada[0]==1 && jugada[4]==5) || (jugada[0]==2 && jugada[4]==6)) {
  52.             for (int i=1; i<=3; i++) {
  53.                 if(jugada[i]==(jugada[i+1]-1)) {
  54.                     count++;
  55.                 }
  56.             }
  57.         }
  58.         if (count==3) {
  59.             return true;
  60.         }else {
  61.             return false;
  62.         }
  63.     }
  64.    
  65.     /*metodo que retorna un boleano y que valida formalmente la frecuencia de valores en el vector jugada*/
  66.     public static boolean check_full(int[] jugada) {
  67.         int count = 0;
  68.         boolean frecuencia=false;
  69.         int [] check_frecuencia = new int[7];          
  70.         for (int i=0; i<jugada.length;i++) {   
  71.             check_frecuencia[jugada[i]]+=1;
  72.         }
  73.         for (int j=1; j < check_frecuencia.length;j++) {
  74.             if (check_frecuencia[j]>=4) {
  75.                 frecuencia=true;
  76.             }
  77.         }
  78.         if (frecuencia==false) {
  79.             //al temañano del vector en el bucle se le resta 1 para que jugada[i+1] no desborde el vector.
  80.             for (int i=0; i < (jugada.length -1); i++) {
  81.                 if (jugada[i]==jugada[i+1]) {
  82.                     count ++;
  83.                     if (count == 3 ) {
  84.                         return true;
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.         return false;
  90.     }
  91.    
  92.     //Metodo que valida si hay poker en el vector utilizando un algoritmo de frecuencia.
  93.     public static boolean check_poker(int[] jugada) {
  94.         int [] check_frecuencia = new int[7];          
  95.         for (int i=0; i<jugada.length;i++) {   
  96.             check_frecuencia[jugada[i]]+=1;
  97.         }
  98.         for (int j=1; j < check_frecuencia.length;j++) {
  99.             if (check_frecuencia[j]==4) {
  100.                 return true;
  101.             }
  102.         }  
  103.         return false;
  104.     }
  105.    
  106.     //Metodo que valida si hay generala en el vector utilizando un algoritmo de frecuencia.
  107.     public static boolean check_generala(int[] jugada) {
  108.         int [] check_frecuencia = new int[7];          
  109.         for (int i=0; i<jugada.length;i++) {   
  110.             check_frecuencia[jugada[i]]+=1;
  111.         }
  112.         for (int j=1; j < check_frecuencia.length;j++) {
  113.             if (check_frecuencia[j]==5) {
  114.                 return true;
  115.             }
  116.         }  
  117.         return false;
  118.     }
  119.    
  120.     public static void main(String[] args) {
  121.        
  122.         Scanner entrada=new Scanner(System.in);
  123.         int n = 0;
  124.         int opcion;
  125.         int count = 0;
  126.         String [] juego_nombre= new String [50];
  127.         String [] juego_jugado= new String [50];
  128.    
  129.         //Interface de usuario
  130.         /*acá use interface para que el usuario intere sobre la app
  131.          * */
  132.         while(n!=1) {
  133.             opcion = 0;
  134.             System.out.println("");
  135.             System.out.println("Bienvenido a la Generala!");
  136.             System.out.println("");
  137.             System.out.println("Ingrese una opcion valida:!");
  138.             System.out.println("1 - Para Jugar");
  139.             System.out.println("2 - Para Salir");
  140.             System.out.print("Opcion: ");
  141.             opcion=entrada.nextInt();
  142.            
  143.             switch(opcion) {
  144.            
  145.             case 1:
  146.                 boolean hay_juego = false;
  147.                 int[] jugada = new int [5];
  148.                 jugada = tirada(jugada);
  149.                 System.out.println("");
  150.                 System.out.println("Estos son los resultados: ");
  151.                 System.out.println("===========================");
  152.                 mostrar_jugada(jugada);
  153.                
  154.                 boolean[] check_juegos = new boolean[4];
  155.                 check_juegos[0]=check_generala(jugada);
  156.                 check_juegos[1]=check_poker(jugada);
  157.                 check_juegos[2]=check_full(jugada);
  158.                 check_juegos[3]=check_escalera(jugada);
  159.                
  160.                 String[] mensajes_juego = new String[4];
  161.                 mensajes_juego[0]="Que buena suerte tienes, Generala";
  162.                 mensajes_juego[1]="Tines magia en las manos, Poker!";
  163.                 mensajes_juego[2]="Muy buena ronda, Full!";
  164.                 mensajes_juego[3]="Para subir o bajar nada mejor que una: Escalera!";
  165.                
  166.                 for(int i=0;i<check_juegos.length;i++) {
  167.                     if(check_juegos[i]) {
  168.                         System.out.println(mensajes_juego[i]);
  169.                         hay_juego=true;
  170.                             juego_jugado[count]=mensajes_juego[i];
  171.                     }
  172.                 }
  173.                
  174.                 if(hay_juego==false) {
  175.                     System.out.println("Es una pena no has podido conseguir ningun juego.");
  176.                     juego_jugado[count]="No tuviste Surte, cero puntos";
  177.                 }
  178.                
  179.                 sumar_dados(jugada);
  180.                 System.out.print("Indique su nombre luego presione Enter:");
  181.                 String ingresar_nombre = entrada.next();
  182.                 juego_nombre[count] = ingresar_nombre;
  183.                 count++;
  184.                 break;
  185.            
  186.            
  187.             case 2: n = 1;
  188.                     int indice=0;
  189.                     System.out.println("\n");
  190.                     System.out.println("Score Total de las Partidas: ");
  191.                     System.out.println("===============================");
  192.                     while(juego_nombre[indice]!=null) {
  193.                        
  194.                         System.out.print("Juego: " + (indice+1));
  195.                         System.out.print(" || ");
  196.                         System.out.print(juego_nombre[indice]);
  197.                         System.out.print(" || ");
  198.                         System.out.print(juego_jugado[indice]);
  199.                         System.out.println("");
  200.                         indice ++;
  201.                     }
  202.             break;
  203.             default: System.out.println("Opcion no valida.");
  204.             }
  205.            
  206.            
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement