Created
October 31, 2023 11:28
-
-
Save kurotori/6a4f9d4acfb4234ef8fb4c4f0c22c143 to your computer and use it in GitHub Desktop.
Evaluación Final de Programación 2 2023 - BLOQUE 1
This file contains hidden or 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
//BLOQUE 6 | |
public boolean archivoExiste(File archivo){ | |
boolean resultado = false; | |
if(archivo.exists() && ! archivo.isDirectory()){ | |
resultado = true; | |
} | |
return resultado; | |
} | |
//FIN DEL BLOQUE 6 |
This file contains hidden or 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
//BLOQUE 2 | |
public static void main(String[] args) { | |
herramientas.Archivo archivo = new Archivo(); | |
File archivoConfig = new File("config.txt"); | |
if (! archivo.archivoExiste(archivoConfig)) { | |
archivo.guardarArchivo("...:0", archivoConfig); | |
} | |
ventanas.Inicio inicio = new Inicio(); | |
inicio.setVisible(true); | |
} | |
//FIN DEL BLOQUE 2 |
This file contains hidden or 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
//BLOQUE 3 | |
private void btn_EntrarMouseClicked(java.awt.event.MouseEvent evt) { | |
String jugador = txt_nombreUsuario.getText(); | |
Principal principal = new Principal(this, jugador); | |
principal.setVisible(true); | |
this.setVisible(false); | |
} | |
//FIN DEL BLOQUE 3 |
This file contains hidden or 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
//BLOQUE 1 | |
private void btn_rojoMouseClicked(java.awt.event.MouseEvent evt) { | |
agregarBorde(btn_rojo); | |
quitarBorde(btn_amarillo); | |
quitarBorde(btn_azul); | |
quitarBorde(btn_verde); | |
valorApuesta = 1; | |
} | |
private void btn_azulMouseClicked(java.awt.event.MouseEvent evt) { | |
agregarBorde(btn_azul); | |
quitarBorde(btn_amarillo); | |
quitarBorde(btn_rojo); | |
quitarBorde(btn_verde); | |
valorApuesta = 2; | |
} | |
private void btn_verdeMouseClicked(java.awt.event.MouseEvent evt) { | |
agregarBorde(btn_verde); | |
quitarBorde(btn_amarillo); | |
quitarBorde(btn_azul); | |
quitarBorde(btn_rojo); | |
valorApuesta = 3; | |
} | |
private void btn_amarilloMouseClicked(java.awt.event.MouseEvent evt) { | |
agregarBorde(btn_amarillo); | |
quitarBorde(btn_verde); | |
quitarBorde(btn_azul); | |
quitarBorde(btn_rojo); | |
valorApuesta = 4; | |
} | |
//FIN DEL BLOQUE 1 |
This file contains hidden or 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
//BLOQUE 4 | |
private void btn_apostarMouseClicked(java.awt.event.MouseEvent evt) { | |
if (valorApuesta == 0) { | |
JOptionPane.showMessageDialog(this, "Debes elegir un color"); | |
} else { | |
int valorResultado = herrVarias.alAzarEntre(1, 4); | |
switch (valorResultado) { | |
case 1: | |
btn_resultado.setBackground(Color.red); | |
break; | |
case 2: | |
btn_resultado.setBackground(Color.blue); | |
break; | |
case 3: | |
btn_resultado.setBackground(Color.green); | |
break; | |
case 4: | |
btn_resultado.setBackground(Color.yellow); | |
break; | |
} | |
if (valorResultado == valorApuesta) { | |
JOptionPane.showMessageDialog(this, "Ganaste"); | |
puntos += 10; | |
} else { | |
JOptionPane.showMessageDialog(this, "Perdiste"); | |
puntos -= 10; | |
} | |
lbl_puntos.setText(puntos+""); | |
quitarBorde(btn_amarillo); | |
quitarBorde(btn_azul); | |
quitarBorde(btn_verde); | |
quitarBorde(btn_rojo); | |
if (puntos == 0) { | |
JOptionPane.showMessageDialog(this, | |
"Ya no te quedan puntos.\nFin del juego."); | |
ventanaInicio.setVisible(true); | |
this.dispose(); | |
} | |
if (puntos > puntosMax){ | |
puntosMax = puntos; | |
jugadorMax = jugador; | |
lbl_puntosMax.setText(puntosMax + " de " + jugadorMax); | |
herrArchivo.guardarArchivo( | |
jugadorMax+":"+puntosMax, archivoConfig); | |
} | |
} | |
} | |
//FIN DEL BLOQUE 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment