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

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  ir chequeando numeros en una matriz
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ir chequeando numeros en una matriz  (Leído 1,337 veces)
veravluis

Desconectado Desconectado

Mensajes: 11


Ver Perfil
ir chequeando numeros en una matriz
« en: 29 Abril 2016, 01:21 am »

Tengo un problema con esto espero puedan ayudarme, si to tengo una matriz

116456
115456
234566
789123
Ejemplo si yo estoy en la casilla (0,0) & al parecer en este momento soy el numero "1" el cual esta rodeado por los numeros "2 , 3 , 4 , 5 , 6" Lo que yo quiero hacer es que cuando le de al numero EJEMPLO "6" mi matriz quede así, osea transforme todos los numeros que llevaba en el numero que voy a presionar.

666456
665456
234566
789123

& si le vuelvo a dar al numero 4 mi matriz quedaría así.

444456
445456
234566
789123 & si vuelvo a presionar el 5 quedaría así

555556
555556
234566
789123 Bueno así hasta llenar la matriz con 1 solo numero, el problema es que en mi código cuando yo presiono el numero cambia todos los números, no solo los que tengo alrededor.

Los números que llevo deberían transformarse en el nuevo que acabo de presionar. espero su ayuda gracias.

Código
  1. [HIGHLIGHT="C"]
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5.  
  6. #define filas 10
  7. #define columnas 10
  8. #define fico 10
  9.  
  10. void cargar_matriz(int matriz[][columnas]);
  11. void pintar_matriz(int matriz[][columnas]);
  12. void movimiento_matriz(int matriz[][columnas]);
  13. void jugar(int matriz[][columnas]);
  14.  
  15. int i,j;
  16.  
  17. int main() {
  18.  
  19. int matriz[filas][columnas];
  20.  
  21. jugar(matriz);
  22.  
  23. }
  24.  
  25. void cargar_matriz(int matriz[][columnas]) {
  26.  
  27. for(i = 0; i < filas; i++) {
  28. for(j = 0; j < columnas; j++) {
  29. matriz[i][j] = rand()%6+1;
  30. }
  31. }
  32. return;
  33. }
  34.  
  35. void pintar_matriz(int matriz[][columnas]) {
  36.  
  37. for(i = 0; i < filas; i++) {
  38. printf("\n\t\t\t");
  39. for(j = 0; j < columnas; j++) {
  40. printf("%d",matriz[i][j]);
  41. }
  42. }
  43. printf("\n\n");
  44. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),7);
  45. printf("\t1 \t2 \t3 \t4 \t5 \t6 \n");
  46. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),1);
  47. printf("\t%c",219);
  48. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),2);
  49. printf("\t%c",219);
  50. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),3);
  51. printf("\t%c",219);
  52. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),4);
  53. printf("\t%c",219);
  54. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),5);
  55. printf("\t%c",219);
  56. SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),6);
  57. printf("\t%c",219);
  58.  
  59.  
  60. movimiento_matriz(matriz);
  61. }
  62.  
  63. void movimiento_matriz(int matriz[][columnas]){
  64.  
  65. int mycolor;
  66.  
  67. mycolor = matriz[0][0];
  68. matriz[0][0] = 10;
  69.  
  70. char tecla;
  71.  
  72. tecla = getch();
  73. //matriz[0][0] = 10;
  74.  
  75. switch (tecla) {
  76.  
  77. case '1' : {
  78. for(i = 0; i < filas; i++) {
  79. for(j = 0; j < columnas; j++) {
  80. if(matriz[i][j] == mycolor ){
  81. matriz[i][j] = 10;
  82. }
  83. }
  84. }
  85. for(i = 0; i < fico; i++) {
  86. for (j = 0; j < fico; j++){
  87. if(matriz[i][j] == 10) {
  88. matriz[i][j] = 1;
  89. }
  90. }
  91. }
  92.  
  93. break;
  94. }
  95.  
  96. case '2' : {
  97. for(i = 0; i < filas; i++) {
  98. for(j = 0; j < columnas; j++) {
  99. if(matriz[i][j] == mycolor ) {
  100. matriz[i][j] = 10;
  101. }
  102. }
  103.  
  104. }
  105. for(i = 0; i < fico; i++) {
  106. for (j = 0; j < fico; j++){
  107. if(matriz[i][j] == 10) {
  108. matriz[i][j] = 2;
  109. }
  110. }
  111. }
  112. break;
  113. }
  114.  
  115. case '3' : {
  116. for(i = 0; i < filas; i++) {
  117. for(j = 0; j < columnas; j++) {
  118. if(matriz[i][j] == mycolor ) {
  119. matriz[i][j] = 10;
  120. }
  121. }
  122. }
  123.  
  124. for(i = 0; i < fico; i++) {
  125. for (j = 0; j < fico; j++){
  126. if(matriz[i][j] == 10) {
  127. matriz[i][j] = 3;
  128. }
  129. }
  130. }
  131. break;
  132. }
  133.  
  134. case '4' : {
  135. for(i = 0; i < filas; i++) {
  136. for(j = 0; j < columnas; j++) {
  137. if(matriz[i][j] == mycolor ) {
  138. matriz[i][j] = 10;
  139. }
  140. }
  141. }
  142. for(i = 0; i < fico; i++) {
  143. for (j = 0; j < fico; j++){
  144. if(matriz[i][j] == 10) {
  145. matriz[i][j] = 4;
  146. }
  147. }
  148. }
  149. break;
  150. }
  151.  
  152. case '5' : {
  153. for(i = 0; i < filas; i++) {
  154. for(j = 0; j < columnas; j++) {
  155. if(matriz[i][j] == mycolor ) {
  156. matriz[i][j] = 10;
  157. }
  158. }
  159. }
  160. for(i = 0; i < fico; i++) {
  161. for (j = 0; j < fico; j++){
  162. if(matriz[i][j] == 10) {
  163. matriz[i][j] = 5;
  164. }
  165. }
  166. }
  167. break;
  168. }
  169.  
  170. case '6' : {
  171. for(i = 0; i < filas; i++) {
  172. for(j = 0; j < columnas; j++) {
  173. if(matriz[i][j]== mycolor ) {
  174. matriz[i][j] = 10;
  175. }
  176. }
  177. }
  178. for(i = 0; i < fico; i++) {
  179. for (j = 0; j < fico; j++){
  180. if(matriz[i][j] == 10) {
  181. matriz[i][j] = 6;
  182. }
  183. }
  184. }
  185. break;
  186. }
  187.  
  188. default : {
  189.  
  190. printf("\nError\n");
  191. break;
  192. }
  193. }
  194.  
  195. system("cls");
  196. pintar_matriz(matriz);
  197.  
  198. }
  199.  
  200. void jugar(int matriz[][columnas]) {
  201.  
  202. cargar_matriz(matriz);
  203. pintar_matriz(matriz);
  204. movimiento_matriz(matriz);
  205.  
  206. }
  207.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[SWT - JAVA] Crear matriz de números
Java
JorgeEMX 2 7,024 Último mensaje 4 Enero 2007, 07:29 am
por JorgeEMX
Ayuda con Programa numeros primos matriz
Java
Jaime1315 7 10,940 Último mensaje 9 Febrero 2013, 13:58 pm
por Mitsu
Pintar matriz de numeros
Java
d!lan 0 2,815 Último mensaje 4 Octubre 2013, 20:48 pm
por d!lan
Problema Matriz cuadrada con números aleatorios sin repetir
Programación C/C++
zaico77 3 6,776 Último mensaje 14 Febrero 2014, 21:06 pm
por leosansan
Ordenar una matriz sin repetir numeros.
Programación C/C++
veravluis 5 4,354 Último mensaje 25 Abril 2016, 00:29 am
por MAFUS
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines