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

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  AYUDA URGENTE EN EJERCICIO DE TRES EN LINEA//PUPILO EN APUROS
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: AYUDA URGENTE EN EJERCICIO DE TRES EN LINEA//PUPILO EN APUROS  (Leído 1,686 veces)
nelxiton

Desconectado Desconectado

Mensajes: 5


Ver Perfil
AYUDA URGENTE EN EJERCICIO DE TRES EN LINEA//PUPILO EN APUROS
« en: 25 Junio 2012, 22:04 pm »

HOLA, TENGO UN PROBLEMA CON RESOLVER ESTE EJERCICIO ...

TRATA SOBRE EL JUEGO TRES EN LINEA...

ME FALTA HALLAR SI GANO DE FORMA VERTICAL Y DE FORMA DIAGONAL IZQUIERDA Y DERECHA

ESPERO QUE ALGUIEN ME PUEDA AYUDAR CON ESTE PROBLEMA LE ESTARIA MUY AGRADECIDO..   :huh:


Código
  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "conio.h"
  4. #include "stdlib.h"
  5. //declaro matriz
  6. int matriz[3][3];
  7.  
  8. using namespace System;
  9.  
  10.  
  11. //declaro funcion
  12. int verifica_horizontal();
  13.  
  14. int main(array<System::String ^> ^args)
  15. {
  16.  
  17. Random r;
  18.  
  19. //Inicio matriz - por filas
  20. for(int i=0;i<3;i++)
  21. for(int j=0;j<3;j++)
  22. matriz[i][j]=0;
  23.  
  24. //Genero matriz aleatoria
  25. for(int i=0;i<3;i++)
  26. for(int j=0;j<3;j++)
  27. matriz[i][j]=r.Next(0,2);
  28.  
  29. //Mostrar matriz original - por filas
  30. for(int i=0;i<3;i++)
  31. {
  32. for(int j=0;j<3;j++)
  33. printf("%4d",matriz[i][j]);
  34.  
  35. printf("\n");
  36. }
  37.  
  38. printf("\n");
  39. printf("\n");
  40. //Mostrar matriz - por filas
  41. for(int i=0;i<3;i++)
  42. {
  43. for(int j=0;j<3;j++)
  44. {
  45. if( matriz[i][j] == 0)
  46. {
  47. printf("O");
  48. }
  49. if( matriz[i][j] == 1)
  50. {
  51. printf("X");
  52. }
  53. }
  54. printf("\n");
  55. }
  56.  
  57. //Invoco funciones
  58. //int horizontal = verifica_horizontal();
  59.  
  60. if (verifica_horizontal() == 1)
  61. printf("\n\n\t GANA HORIZONTAL");
  62. else
  63. printf("\n\n\t NO HAY GAANDOR HORIZONTAL");
  64.  
  65.  
  66. _getch();
  67.    return 0;
  68. }
  69.  
  70. //Implemento funcion
  71. int verifica_horizontal()
  72. {
  73. int gana=0;
  74. int contador;
  75.  
  76. for(int i=0;i<3;i++)
  77. {
  78. contador=0;
  79. for(int j=0;j<3;j++)
  80. {
  81. if(matriz[i][j]==1)
  82. contador++;
  83. }
  84. if( contador == 3 )
  85. {
  86. gana=1;
  87. break;
  88. }
  89. }
  90.  
  91. return gana;
  92. }
  93.  


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