Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dados;
- import java.util.*;
- public class dados {
- /*Desde el metodo main el primer metodo de la clase llamdo es el de tirada, a su vez el mismo
- * retorna un array de enteros al metodo tirada_ordenada que trata de un algoritmo de ordenamiento
- * de vectores del tipo burbuja
- */
- public static int[] tirada(int [] jugada) {
- for (int i=0; i<jugada.length; i++) {
- jugada[i]= (int) (Math.random()*(6) + 1);
- }
- return tirada_ordenada(jugada);
- }
- public static int[] tirada_ordenada(int[] jugada) {
- for (int i=0; i<jugada.length;i++ ) {
- for (int j=0; j<(jugada.length -1); j++) {
- if (jugada[j]>jugada[j+1]) {
- int aux;
- aux=jugada[j];
- jugada[j]=jugada[j+1];
- jugada[j+1]=aux;
- }
- }
- }
- return jugada;
- }
- /*este es un metodo vacio que imprime la jugada ordenada */
- public static void mostrar_jugada(int[] jugada) {
- for (int i = 0; i < jugada.length; i++) {
- System.oupokert.print (jugada[i] + " - " );
- }
- System.out.println("");
- }
- /*metodo vacio suma los valores de los dados*/
- public static void sumar_dados(int[] jugada) {
- int suma=0;
- for (int i = 0; i < jugada.length; i++) {
- suma = suma + jugada[i];
- }
- System.out.println("La suma total de los dados es: " + suma);
- }
- /*metodo que retorna un boleano si encuentra uno de los tres tipos de escalera posible*/
- public static boolean check_escalera(int[] jugada) {
- int count = 0;
- if ((jugada[0]==1 && jugada[4]==6) || (jugada[0]==1 && jugada[4]==5) || (jugada[0]==2 && jugada[4]==6)) {
- for (int i=1; i<=3; i++) {
- if(jugada[i]==(jugada[i+1]-1)) {
- count++;
- }
- }
- }
- if (count==3) {
- return true;
- }else {
- return false;
- }
- }
- /*metodo que retorna un boleano y que valida formalmente la frecuencia de valores en el vector jugada*/
- public static boolean check_full(int[] jugada) {
- int count = 0;
- boolean frecuencia=false;
- int [] check_frecuencia = new int[7];
- for (int i=0; i<jugada.length;i++) {
- check_frecuencia[jugada[i]]+=1;
- }
- for (int j=1; j < check_frecuencia.length;j++) {
- if (check_frecuencia[j]>=4) {
- frecuencia=true;
- }
- }
- if (frecuencia==false) {
- //al temañano del vector en el bucle se le resta 1 para que jugada[i+1] no desborde el vector.
- for (int i=0; i < (jugada.length -1); i++) {
- if (jugada[i]==jugada[i+1]) {
- count ++;
- if (count == 3 ) {
- return true;
- }
- }
- }
- }
- return false;
- }
- //Metodo que valida si hay poker en el vector utilizando un algoritmo de frecuencia.
- public static boolean check_poker(int[] jugada) {
- int [] check_frecuencia = new int[7];
- for (int i=0; i<jugada.length;i++) {
- check_frecuencia[jugada[i]]+=1;
- }
- for (int j=1; j < check_frecuencia.length;j++) {
- if (check_frecuencia[j]==4) {
- return true;
- }
- }
- return false;
- }
- //Metodo que valida si hay generala en el vector utilizando un algoritmo de frecuencia.
- public static boolean check_generala(int[] jugada) {
- int [] check_frecuencia = new int[7];
- for (int i=0; i<jugada.length;i++) {
- check_frecuencia[jugada[i]]+=1;
- }
- for (int j=1; j < check_frecuencia.length;j++) {
- if (check_frecuencia[j]==5) {
- return true;
- }
- }
- return false;
- }
- public static void main(String[] args) {
- Scanner entrada=new Scanner(System.in);
- int n = 0;
- int opcion;
- int count = 0;
- String [] juego_nombre= new String [50];
- String [] juego_jugado= new String [50];
- //Interface de usuario
- /*acá use interface para que el usuario intere sobre la app
- * */
- while(n!=1) {
- opcion = 0;
- System.out.println("");
- System.out.println("Bienvenido a la Generala!");
- System.out.println("");
- System.out.println("Ingrese una opcion valida:!");
- System.out.println("1 - Para Jugar");
- System.out.println("2 - Para Salir");
- System.out.print("Opcion: ");
- opcion=entrada.nextInt();
- switch(opcion) {
- case 1:
- boolean hay_juego = false;
- int[] jugada = new int [5];
- jugada = tirada(jugada);
- System.out.println("");
- System.out.println("Estos son los resultados: ");
- System.out.println("===========================");
- mostrar_jugada(jugada);
- boolean[] check_juegos = new boolean[4];
- check_juegos[0]=check_generala(jugada);
- check_juegos[1]=check_poker(jugada);
- check_juegos[2]=check_full(jugada);
- check_juegos[3]=check_escalera(jugada);
- String[] mensajes_juego = new String[4];
- mensajes_juego[0]="Que buena suerte tienes, Generala";
- mensajes_juego[1]="Tines magia en las manos, Poker!";
- mensajes_juego[2]="Muy buena ronda, Full!";
- mensajes_juego[3]="Para subir o bajar nada mejor que una: Escalera!";
- for(int i=0;i<check_juegos.length;i++) {
- if(check_juegos[i]) {
- System.out.println(mensajes_juego[i]);
- hay_juego=true;
- juego_jugado[count]=mensajes_juego[i];
- }
- }
- if(hay_juego==false) {
- System.out.println("Es una pena no has podido conseguir ningun juego.");
- juego_jugado[count]="No tuviste Surte, cero puntos";
- }
- sumar_dados(jugada);
- System.out.print("Indique su nombre luego presione Enter:");
- String ingresar_nombre = entrada.next();
- juego_nombre[count] = ingresar_nombre;
- count++;
- break;
- case 2: n = 1;
- int indice=0;
- System.out.println("\n");
- System.out.println("Score Total de las Partidas: ");
- System.out.println("===============================");
- while(juego_nombre[indice]!=null) {
- System.out.print("Juego: " + (indice+1));
- System.out.print(" || ");
- System.out.print(juego_nombre[indice]);
- System.out.print(" || ");
- System.out.print(juego_jugado[indice]);
- System.out.println("");
- indice ++;
- }
- break;
- default: System.out.println("Opcion no valida.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement