elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  ¿Cómo logro que las cartas se muestren mejor?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ¿Cómo logro que las cartas se muestren mejor?  (Leído 105 veces)
Tachikomaia


Desconectado Desconectado

Mensajes: 1.631


Hackentifiko!


Ver Perfil
¿Cómo logro que las cartas se muestren mejor?
« en: Hoy a las 04:11 »

Por ahora logré esto:

En vez de T7 debería mostrarse el 7 de tréboles... o por lo menos que diga "7 tréboles"
y en D2 el 2 de diamantes, o que diga "2 diamantes".

Es para un Black Jack.

Código
  1. // Generar array de cartas:
  2. Cartas = [];
  3. Nro = 0;
  4. do {
  5. Nro++;
  6. Cartas[Cartas.length] = "P"+Nro;
  7. Cartas[Cartas.length] = "T"+Nro;
  8. Cartas[Cartas.length] = "C"+Nro;
  9. Cartas[Cartas.length] = "D"+Nro;
  10. } while (Nro < 13);
  11.  
  12. // Ordenarlas al azar:
  13. Posicion1aReubicarse = Cartas.length-1;
  14. while (Posicion1aReubicarse>0) {
  15. Posicion2aReubicarse = random(Posicion1aReubicarse+1);
  16. SaveDeElemento1 = Cartas[Posicion1aReubicarse];
  17. Cartas[Posicion1aReubicarse] = Cartas[Posicion2aReubicarse];
  18. Cartas[Posicion2aReubicarse] = SaveDeElemento1;
  19. Posicion1aReubicarse--;
  20. }
  21.  
  22. // Dar a jugadores:
  23. SiguienteNroDeCarta = 0;
  24. CartasDeHumano = [];
  25. CartasDeIA = [];
  26. do {
  27. CartasDeHumano[CartasDeHumano.length] = Cartas[SiguienteNroDeCarta];
  28. CartasDeIA[CartasDeIA.length] = Cartas[SiguienteNroDeCarta+1];
  29. SiguienteNroDeCarta = SiguienteNroDeCarta+2;
  30. } while (SiguienteNroDeCarta < 4);
  31. Mensaje = "Has recibido "+CartasDeHumano[0];
  32. Mensaje = Mensaje+"\nY "+CartasDeHumano[1];
  33.  
  34. // Agregarlas en pantalla:
  35. function AgregarCartasDeHumano () {
  36. CartaaAgregar = 0;
  37. if (CartasDeHumano.length % 2 == 0) {
  38. PosicionDe0 = 256 - CartasDeHumano.length-1 * 50 - 25;
  39. } else {
  40. PosicionDe0 = 256 - CartasDeHumano.length * 50;
  41. }
  42. do {
  43. Nombre = "CartaDeHumano"+CartasDeHumano[CartaaAgregar];
  44. attachMovie ("sCarta", Nombre, CartaaAgregar);
  45. setProperty (Nombre, _x, PosicionDe0+(CartaaAgregar)*150);
  46. setProperty (Nombre, _y, 192);
  47. set (Nombre+".Text", CartasDeHumano[CartaaAgregar]);
  48. CartaaAgregar++;
  49. } while (CartaaAgregar < CartasDeHumano.length);
  50. }
  51. AgregarCartasDeHumano();
  52.  
  53. // Calcular suma de humano:
  54. ValorDeCartaHumana0 = Math.min(10, Number(CartasDeHumano[0].substring(1, CartasDeHumano[0].length)));
  55. ValorDeCartaHumana1 = Math.min(10, Number(CartasDeHumano[1].substring(1, CartasDeHumano[1].length)));
  56. if (ValorDeCartaHumana0 == 1) {
  57. SumaDeHumano = 11+ValorDeCartaHumana1;
  58. } else if (ValorDeCarta1 == 1) {
  59. SumaDeHumano = ValorDeCartaHumana0+11;
  60. } else {
  61. SumaDeHumano = ValorDeCartaHumana0+ValorDeCartaHumana1;
  62. }
  63. Mensaje = Mensaje+"\nTu suma es "+SumaDeHumano;
  64.  
  65. // Calcular suma de IA:
  66. ValorDeCartaDeIA0 = Math.min(10, Number(CartasDeIA[0].substring(1, CartasDeIA[0].length)));
  67. ValorDeCartaDeIA1 = Math.min(10, Number(CartasDeIA[1].substring(1, CartasDeIA[1].length)));
  68. if (ValorDeCartaDeIA0 == 1) {
  69. SumaDeIA = 11+ValorDeCartaDeIA1;
  70. } else if (ValorDeCartaDeIA1 == 1) {
  71. SumaDeIA = ValorDeCartaDeIA0+11;
  72. } else {
  73. SumaDeIA = ValorDeCartaDeIA0+ValorDeCartaDeIA1;
  74. }
  75. Mensaje = Mensaje+"\nLa suma del rival es "+SumaDeIA;

No quiero copiar y pegar dibujos de 13*4 cartas. Debo copiar y pegar los 4 íconos (trébol, etc), y según la carta insertar en ella X de esos íconos, distribuídos en ella según el caso. Para J, Q, K y 1 sí usaré los dibujos.

¿Cómo lo hago?

Sobre que aparezca un texto más completo ya se me ocurrió cómo: El programa guarda el 1er caracter, lo quita, pone lo que queda (el número) y luego dependiendo de cual sea el caracter guardado agrega el texto, por ejemplo "tréboles" si es "T". Hago eso ahora.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines