| Ver tema anterior :: Ver siguiente tema | | Autor | Mensaje |
|---|
mihina
Registrado: 21 Feb 2011 Mensajes: 9
| Publicado: 05/05/2011 8:47 am | | | Título: Recursividad "Buscaminas" |
| Buenas tengo hecho el juego del buscaminas en c++; y ahora intento implementar la recursividad en la hora de destapar las casillas, pero no me sale. Haver si alguien me puede ayudar! Gracias de antemano!!!!
| Código: | bool Taulell::preDestaparMarcar(char jugada) { bool sortir=false; cout << "INTRODUEIX LA POSICIO" << endl; char posicio1, posicio2; cin >> posicio1; cin >> posicio2; int x=posicio1-97; int y=posicio2-65; if(x<a_files && x>=0 && y<a_colum && y>=0) { if(jugada=='d') //DESTAPAR { if(a_Casella[x][y].obtEstat()==3) { bool mina=a_Casella[x][y].obtHiHaMina(); if(mina==false){ destaparCasella(x,y); sortir=fiJoc(); } else{ char continuar; cout << "HAS TROBAT UNA MINA!" << endl; cout << "VOLS FER UNA NOVA PARTIDA? (s/n)" << endl; cin >> continuar; if(continuar=='s') { eliminarCasella(); preJugar(); } else { cout << "FI PESCAMINES" << endl; sortir=true; } } } } else //MARCAR O DESMARCAR{ marcaCasella(x,y); } } else{ cout << "POSICIO INCORRECTA" << endl; } return sortir; }
|
| Código: | void Taulell::destaparCasella(int x,int y) { for(int f=-1; f<=1; f++) { for(int c=-1; c<=1; c++) { if((f>=0 && f<a_files) && (c>=0 && c<a_colum)) { if(!a_Casella[x+f][y+c].obtHiHaMina() && a_Casella[x+f][y+c].obtEstat()==3) { if (a_Casella[x+f][x+c].obtNumDeMines()>0) { a_Casella[x][y].modEstat(1); a_CasellesTapades--; } else { a_Casella[x][y].modEstat(1); a_CasellesTapades--; destaparCasella(x+f,y+c); } } } } } }
|
|
| | Volver arriba | |  | mihina
Registrado: 21 Feb 2011 Mensajes: 9
| Publicado: 05/05/2011 12:18 pm | | | Título: Lo he solucinado |
| Lo he solucionado: pongo la solucion por si a alguien le interesa; el primer metodo no he tocado nada solo he modificado el segundo.
| Código: | void Taulell::destaparCasella(int x,int y, int f, int c) { if((x+f>=0 && x+f<a_files) && (y+c>=0 && y+c<a_colum)){ if(!a_Casella[x+f][y+c].obtHiHaMina() && a_Casella[x+f][y+c].obtEstat()==3){ if (a_Casella[x+f][y+c].obtNumDeMines()>0){ a_Casella[x][y].modEstat(1); a_CasellesTapades--; } if (a_Casella[x+f][y+c].obtNumDeMines()==0){ for(int f=-1; f<=1; f++){ for(int c=-1; c<=1; c++){ a_Casella[x][y].modEstat(1); a_CasellesTapades--; destaparCasella(x+f,y+c,0,0); } } } } } }
| [/code] |
| | Volver arriba | |  | | |
| No puede crear mensajes No puede responder temas No puede editar sus mensajes No puede borrar sus mensajes No puede votar en encuestas
|
|
| |