|
Programacion Pregunta, consulta o ayuda a resolver los problemas o incógnitas que tengan los demás miembros de la comunidad sobre programación en general. |
Hola Invitado! Tómate un minuto para registrarte, es 100% GRATIS y no verás ninguna publicidad! ¿Qué estás esperando? Para Ingresa a Denunciando.com por medio de TapaTalk Clic ACA | Registrarse Ahora |
Programacion » bUSCAMINASParticipa en el tema bUSCAMINAS en el foro Programacion. |
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
Buscaminas en java | greed | Programacion | 5 | 27-12-2012 23:03:53 |
Los que se cansaron de Ganar en buscaminas, ahora en 3d, reto, PC y Linux | erwinos | Juegos y Consolas | 4 | 04-09-2011 15:13:43 |
Buscaminas Java | rexixtenxiaN | Programacion | 0 | 23-05-2011 11:42:58 |
Lo que todos esperábamos: El trailer de de.... ¡BUSCAMINAS, LA PELÍCULA! | Tyler Durden | Chistes / Cosas Charras | 9 | 23-04-2010 00:46:19 |
Ganar rapido en Solitario, Pinball, buscaminas, etc... | Alejo_385 | Juegos y Consolas | 8 | 31-12-2008 14:16:44 |
, 09:26:56 | #1 | |
bUSCAMINAS
Calificación: 5,00 de
5,00
Hola, necesito hacer un buscaminas por medio de matrices dispersas o tambien lo llaman matrices poco densas. Si alguien me puede ayudar gracias. Si es en java mejor. Gracias. | ||
Twittear Seguir a @denunciando
| |
No Calculado | #1.5 |
SponSor | Re: bUSCAMINAS |
10-09-2011 , 05:11:08 | #2 |
Recien Registrado | Respuesta: bUSCAMINAS
Este programa lo hice hace unos años y funcionaba perfectamente para el compilador Borland C++. No creo que sea muy difícil pasarlo a Java. Lo de las matrices ralas es fácil... debes crear una función matriz_rala_get y matriz_rala_set o algo así para escribir y leer los datos a la matriz. Saludos! (y no olvides ponerme puntos dándome las gracias) #include<stdio.h> #include<stdlib.h> #include<iostream.h> #include<conio.h> // Constantes #define bool int #define false 0 #define true 1 #define ESC 27 #define F_IZQ 75 #define F_DER 77 #define F_ARR 72 #define F_ABA 80 #define ESPACIO 32 #define ENTER 13 const int MAXFIL = 25; const int MAXCOL = 80; const int NMINAS = 150; // Variables globales bool destapado[MAXCOL+2][MAXFIL+2] = {false}; bool protegido[MAXCOL+2][MAXFIL+2] = {false}; bool esmina[MAXCOL+2][MAXFIL+2] = {false}; // Prototipos bool destapar(int x, int y); int sumaalrededor(int x, int y); void perdio(); void crearminas(int n); // Declaración de las funciones bool destapar(int x, int y){ if (x<1) return false; if (x>MAXCOL) return false; if (y<1) return false; if (y>MAXFIL) return false; if (destapado[x][y] || protegido[x][y]) return false; if (esmina[x][y]) perdio(); destapado[x][y] = true; int suma = sumaalrededor(x,y); gotoxy(x,y); if (suma==0){ putch(' '); destapar(x-1,y-1); destapar(x,y-1); destapar(x+1,y-1); destapar(x-1,y); destapar(x+1,y); destapar(x-1,y+1); destapar(x,y+1); destapar(x+1,y+1); } else { putch(suma+int('0')); } gotoxy(x,y); return true; } int sumaalrededor(int x, int y){ int i, j, suma=0; for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) suma += int(esmina[i][j]); return suma; } void perdio(){ //mostrar todas las minas gotoxy(1,25); cout << "Perdiste"; getch(); exit(EXIT_FAILURE); } void crearminas(int n){ for(int i=0;i<n;i++) esmina[random(MAXCOL)+1][random(MAXFIL)+1] = true; return; } int main(){ char c; int suma, i, j, x=MAXCOL/2, y=MAXFIL/2+1; bool marcadas; randomize(); crearminas(NMINAS); _wscroll = 0; clrscr(); _setcursortype(_NOCURSOR); //esto es para que el cursor no moleste for(i=1;i<=MAXCOL;i++){ for(j=1;j<=MAXFIL;j++){ gotoxy(i,j); putch('.'); } } gotoxy(x,y); putch((int)'#'); gotoxy(x,y); do{ c = (char)getch(); if (!c){ c = (char)getch(); switch((int)c){ case F_IZQ: if (x>1) x--; break; case F_DER: if (x<MAXCOL) x++; break; case F_ARR: if (y>1) y--; break; case F_ABA: if (y<MAXFIL) y++; break; } } else { switch((int)c){ case ENTER: destapar(x,y); break; case ESPACIO: if (!destapado[x][y]){ gotoxy(x,y); if (protegido[x][y]){ cout << '.'; protegido[x][y] = false; } else{ cout << '@'; protegido[x][y] = true; } gotoxy(x,y); } break; case ESC: exit(EXIT_SUCCESS); break; //esta nunca se ejecutara } } if (protegido[wherex()][wherey()]) putch('@'); else { if (destapado[wherex()][wherey()]){ suma = sumaalrededor(wherex(),wherey()); if (suma == 0) putch(' '); else cout << suma; } else putch('.'); } gotoxy(x,y); putch('#'); gotoxy(x,y); marcadas = true; for(i=1;i<=MAXCOL;i++){ for(j=1;j<=MAXFIL;j++){ if ((esmina[i][j] != protegido[i][j])){ // && // (esmina[i][j] != !destapado[i][j])){ marcadas = false; break; } } } }while(!marcadas); gotoxy(1,25); cout << "Ganaste "; // system("pause"); getch(); return 0; } |
10-09-2011 , 20:40:36 | #3 |
Denunciante Novato | Respuesta: bUSCAMINAS
hola, muchas gracias por tu aporte, lo voy a ensayar en java. Y te cuento que como soy nueva por aqui, no se como darte puntos. Si me dices como, claro que si. |
Etiquetas |
buscaminas |
|