Programa que simula el juego del 21 para 3 jugadores donde diga quien es el ganador y el total de su suma sin pasarse del 21 en Java
/**
Programa que simula el juego del 21 para 3 jugadores
donde diga quien es el ganador y el total de su suma
sin pasarse del 21
*/
class Juego21
{
public static void main(String args[])
{
int i,jug,J1=0,J2=0,J3=0;
int Li=1,Ls=13,posible,A;
int La=1,Lb=4,B;
boolean E1,E2,E3;
double aleat;
for(jug=1;jug<4;jug++)//inicio for 3 jugadores
{
System.out.println("««JUGADOR NUMERO "+jug+"»»");
for(i=1;i<=3;i++)//inicio for 3 cartas
{
/*********Numero de la carta****************/
posible=(Ls+1)-Li;
aleat=Math.random()*posible;
aleat=Math.floor(aleat);
aleat=(Li+aleat);
A=(int)aleat;
/*************Tipo de carta*****************/
posible=(Lb+1)-La;
aleat=Math.random()*posible;
aleat=Math.floor(aleat);
aleat=(La+aleat);
B=(int)aleat;
/******************************************/
if(jug==1)
{J1=J1+A;}
if(jug==2)
{J2=J2+A;}
if(jug==3)
{J3=J3+A;}
/******************************************/
switch(B)
{
case 1:
System.out.print("Trebol [");
break;
case 2:
System.out.print("Diamante [");
break;
case 3:
System.out.print("Corazòn [");
break;
case 4:
System.out.print("Pica [");
break;
}
if(A>10)
{
switch(A)
{
case 11:
System.out.println("J]");
break;
case 12:
System.out.println("Q]");
break;
case 13:
System.out.println("K]");
break;
}
}
else
{
System.out.println(A+"]");
}
}//fin for 3 cartas
}//fin for 3 jugadores
if((J1>=17)|(J1>=21))
{
if((J1>J2)&(J1>J3))
{
System.out.println("!!! Gano el jugador 1 !!!");
}
}
if((J2>=17)|(J2>=21))
{
if((J2>J1)&(J2>J3))
{
System.out.println("!!! Gano el jugador 2 !!!");
}
}
if((J3>=17)|(J3>=21))
{
if((J3>J1)&(J3>J2))
{
System.out.println("!!! Gano el jugador 3 !!!");
}
}
if((J1==J2)&(J1==J3)&(J2==J3))
{
System.out.println("!!! JUEGO EMPATADO !!!");
}
/******************************************/
/******************************************/
/******************************************/
}//fin clase principal
}//fin clase Juego21
Programa que simula el juego del 21 para 3 jugadores
donde diga quien es el ganador y el total de su suma
sin pasarse del 21
*/
class Juego21
{
public static void main(String args[])
{
int i,jug,J1=0,J2=0,J3=0;
int Li=1,Ls=13,posible,A;
int La=1,Lb=4,B;
boolean E1,E2,E3;
double aleat;
for(jug=1;jug<4;jug++)//inicio for 3 jugadores
{
System.out.println("««JUGADOR NUMERO "+jug+"»»");
for(i=1;i<=3;i++)//inicio for 3 cartas
{
/*********Numero de la carta****************/
posible=(Ls+1)-Li;
aleat=Math.random()*posible;
aleat=Math.floor(aleat);
aleat=(Li+aleat);
A=(int)aleat;
/*************Tipo de carta*****************/
posible=(Lb+1)-La;
aleat=Math.random()*posible;
aleat=Math.floor(aleat);
aleat=(La+aleat);
B=(int)aleat;
/******************************************/
if(jug==1)
{J1=J1+A;}
if(jug==2)
{J2=J2+A;}
if(jug==3)
{J3=J3+A;}
/******************************************/
switch(B)
{
case 1:
System.out.print("Trebol [");
break;
case 2:
System.out.print("Diamante [");
break;
case 3:
System.out.print("Corazòn [");
break;
case 4:
System.out.print("Pica [");
break;
}
if(A>10)
{
switch(A)
{
case 11:
System.out.println("J]");
break;
case 12:
System.out.println("Q]");
break;
case 13:
System.out.println("K]");
break;
}
}
else
{
System.out.println(A+"]");
}
}//fin for 3 cartas
}//fin for 3 jugadores
if((J1>=17)|(J1>=21))
{
if((J1>J2)&(J1>J3))
{
System.out.println("!!! Gano el jugador 1 !!!");
}
}
if((J2>=17)|(J2>=21))
{
if((J2>J1)&(J2>J3))
{
System.out.println("!!! Gano el jugador 2 !!!");
}
}
if((J3>=17)|(J3>=21))
{
if((J3>J1)&(J3>J2))
{
System.out.println("!!! Gano el jugador 3 !!!");
}
}
if((J1==J2)&(J1==J3)&(J2==J3))
{
System.out.println("!!! JUEGO EMPATADO !!!");
}
/******************************************/
/******************************************/
/******************************************/
}//fin clase principal
}//fin clase Juego21
Comentarios
Publicar un comentario