Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
import java.util.Random;
public Carta() {
case 1:
valor = "A";
break;
case 11:
valor = "J";
x = 10;
break;
case 12:
valor = "Q";
x = 10;
break;
case 13:
valor = "K";
x = 10;
break;
default:
valor =Integer.toString(x);
}
int y = 1;
y += (int)(rnd.nextDouble() * 4.0);
switch (y) {
case 1:
palo="Corazones Rojos";
break;
case 2:
palo="Diamantes";
break;
case 3:
palo="Trébol";
break;
case 4:
palo="Espadas";
break;
default:
palo = Integer.toString(y);
}
}
if(valor.equals("A"))
return 1;
else
if(valor.equals("J") || valor.equals("Q") ||
valor.equals("K"))
return 10;
return Integer.parseInt(valor);
}
return palo;
}
}
package ocio;
import javax.swing.JOptionPane;
String a = JOptionPane.showInputDialog(null,"**Digita tu
nombre: ");
nombre = a ;
String b = JOptionPane.showInputDialog(null,"**Digita tu
password: ");
password = b;
for(;;){
int d;
try {
d=Integer.parseInt(c);
if(d < 1)
JOptionPane.showMessageDialog(null,"Te
recordamos que tus apuestas deben exceder" +
" a un dólar");
else {
apuesta = d;
break;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Te recordamos
que tus apuestas deben exceder" +
" a un dólar");
}
}
numCarta=1;
}
for(int i=0;i<2;i++){
}
}
numCarta+=1;
arregloCartas[numCarta] = new Carta();
}
return(apuesta);
}
return password;
}
return nombre;
}
if(no .toUpperCase().equals("S")) {
return true;
}
else {
if(no.toUpperCase().equals("N")) {
return false;
}
else {
JOptionPane.showMessageDialog(null,"Su opción no es
válida");
}
return false;
}
}
int sum = 0;
try {
if(this.arregloCartas[i].getValor() == 1) {
sum = 11 + sum;
as=true;
}
else
sum = this.arregloCartas[i].getValor() +
sum;
}
}catch(Exception e) {
System.out.print("");
}
if(as)
if(sum > 21)
sum -= 10;
return (sum);
}
package ocio;
import javax.swing.JOptionPane;
for(int i=0;i<nj;i++) {
JOptionPane.showMessageDialog(null,"Jugador:
" + (i+1));
arregloJugador[i] = new Jugador(nj,i);
}
}catch(Exception e) {
}
this.arregloJugador = arregloJugador;
apuestaTotal = sumaApuestas(nj);
JOptionPane.showMessageDialog(null,"la apuesta
acumulada en mesa es: $ " + apuestaTotal);
saldo = sumaApuestas(nj);
return (arregloJugador[n]);
}
int sum = 0;
try {
sum = this.getArregloJugador(i).getApuesta()
+ sum;
}
}catch(Exception e) {
System.out.print("");
}
return (sum);
}
}
package ocio;
import javax.swing.JOptionPane;
public class Aplica {
JOptionPane.showMessageDialog(null,"JUGUEMOS BLACKJACK");
Mesa temp = new Mesa(0);
int indiceMenu = 0;
int a;
int numberJug = 0;
boolean ope1 = false, ope2 = false;
String pa = "";
do
for(;;){
try {
indiceMenu = Integer.parseInt(men);
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null,"Las letras no
se admiten como opciones" +
" del menú");
indiceMenu=8;
}
switch(indiceMenu) {
case 1:
boolean number = true;
do{
String me =
JOptionPane.showInputDialog(null,"Cuántas personas " +
"participarán??? ");
try {
numberJug = Integer.parseInt
(me);
number = false;
}catch(Exception e) {
number = true;
number = true;
case 2:
if(!ope1) {
temp.getArregloJugador(i).setArregloCartas();
}
case 3:
if(ope1) {
if(!ope2){
a = capturarPassword (numberJug,
temp, pa);
if(a >= 0 &&
temp.getArregloJugador(a).total() <= 21) {
JOptionPane.showMessageDialog(null,"Bienvenido " +
temp.getArregloJugador(a).getNombre());
temp.getArregloJugador(a).total());
while(temp.getArregloJugador(a).preguntar()) {
temp.getArregloJugador(a).setCarta();
if(
temp.getArregloJugador(a).total()<=21)
temp.getArregloJugador(a).total());
else {
case 4:
if(ope1) {
if(!ope2) {
a = capturarPassword (numberJug,
temp, pa);
if(a >= 0)
temp.getArregloJugador(a).verCartas();
else
JOptionPane.showMessageDialog(null,"Contraseña incorrecta!");
}
break;
}
else {
case 5:
if(ope1){
if(!ope2){
a=-1;
String m =
JOptionPane.showInputDialog(null,"Ingrese el password: ");
try {
pa = m;
}catch(Exception e) {
JOptionPane.showMessageDialog(null,"Error en la captura!");
}
if(pa.equals(temp.getArregloJugador(numberJug-1).getPass())) {
for(int i = 0; i <
numberJug; i++) {
temp.getArregloJugador(i).verCartas();
}
comparaJugadores(temp, numberJug) +
" y gano \n" +
temp.sumaApuestas(numberJug));
indiceMenu=6;
}
else {
"autorizado!");
}
break;
}
}
else {
case 6:
JOptionPane.showMessageDialog(null,"\t\t\t\t
NO ES DIFÍCIL JUGAR BLACK " +
"JACK... Te ofrecemos una
ayuda\n\n" +
"1. Te recomendamos seguir los
el orden del menú\n" +
"2. Debes tratar de alcanzar la
suma de tus " +
"cartas cercano a 21 pero si lo
superas " +
"pierdes el juego
automáticamente\n" +
"3. El As puede tomar el valor
de uno u once\n" +
"4. No te preocupes por los
resultados podrás" +
"mirarlo en la opción del menú
correspondiente" +
"conocer estado de la mesa\n" +
"5. GRACIAS POR JUGAR ES UN " +
"GUSTO SERVIRTE\n");
break;
case 7:
{
JOptionPane.showMessageDialog (null,"ESPERO
QUE ESTE PROGRAMA HAYA SIDO DE SU AGRADO");
System.exit(0);
}break;
default:
JOptionPane.showMessageDialog(null,"Opción
Incorrecta, escoja de nuevo");
}
}while(indiceMenu!=7);
}
if(a.getArregloJugador(i).total()>altoPuntaje &&
a.getArregloJugador(i).total()<=21) {
altoPuntaje=a.getArregloJugador(i).total();
winner=i;
}
}
return "" + a.getArregloJugador(winner).getNombre() + " con:
" + a.getArregloJugador(winner).total();
}
int p=-1;
String m =JOptionPane.showInputDialog(null,"***Digita tu
password: ");
try {
pa=m;
}catch(Exception e) {
JOptionPane.showMessageDialog(null,"ERROR!!!!");
}