Last active
September 13, 2024 16:36
-
-
Save kurotori/ac59bf5134080d04ea46fa51df80ebbd to your computer and use it in GitHub Desktop.
Solitario 1 Informática - Estado del código al 23 de agosto 2024
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package solitario; | |
import java.util.Random; | |
/** | |
* | |
* @author sebastian | |
*/ | |
public class Solitario { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
String[] tipos | |
= {"oro", "espada", "copa", "basto"}; | |
int[][] baraja = new int[48][2]; | |
int numero = 0; | |
for (int carta = 0; carta < 48; carta++) { | |
int tipo = 0; | |
if (carta < 12) { | |
tipo = 0; //oro | |
} | |
if ((carta >= 12) && (carta < 24)) { | |
tipo = 1; //espada | |
} | |
if ((carta >= 24) && (carta < 36)) { | |
tipo = 2; //copa | |
} | |
if ((carta >= 36) && (carta < 48)) { | |
tipo = 3; //espada | |
} | |
numero++; | |
if (numero > 12) { | |
numero = 1; | |
} | |
baraja[carta][1] = numero; | |
baraja[carta][0] = tipo; | |
} | |
barajarMazo(baraja); | |
for (int[] carta:baraja) { | |
System.out.println( | |
tipos[carta[0]] + "-" + carta[1] | |
); | |
} | |
} | |
static void barajarMazo(int[][] mazo){ | |
Random azar = new Random(); | |
int[] carta1 = null; | |
int posicion = 0; | |
for (int i = 0; i < mazo.length; i++) { | |
carta1 = mazo[i]; | |
posicion = azar.nextInt(mazo.length); | |
mazo[i] = mazo[posicion]; | |
mazo[posicion] = carta1; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package solitario; | |
import javax.swing.JFrame; | |
import java.awt.Dimension; | |
/** | |
* | |
* @author Informática 1ero | |
*/ | |
public class Ventanas { | |
static public JFrame crearVentana(int ancho, int alto){ | |
JFrame ventana = new JFrame(); | |
Dimension tamanio = new Dimension(ancho, alto); | |
ventana.setSize(tamanio); | |
//ventana.setVisible(true); | |
return ventana; | |
} | |
public static void main(String[] args) { | |
JFrame v1 = crearVentana(250, 300); | |
v1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
v1.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment