Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "labirinto.h"
  2. #include <iostream>
  3. using namespace std;
  4. int matriz[7][13]={
  5.     {1,1,1,0,1,1,0,0,0,1,1,1,1}
  6.     ,{1,0,1,1,1,0,1,1,1,1,1,0,1}
  7.     ,{1,0,0,0,1,0,1,0,1,0,1,0,1}
  8.     ,{1,0,0,0,1,1,1,0,1,0,1,1,1}
  9.     ,{1,1,1,1,1,0,0,0,0,1,0,0,0}
  10.     ,{0,0,0,0,1,0,0,0,0,0,0,0,0}
  11.     ,{0,0,0,0,1,1,1,1,1,1,1,1,1}};
  12.     void mover(int x,int y);
  13. int main( int argc, const char* argv[] ){
  14.    
  15.  
  16.    
  17.     mover(0,0);
  18.     for(int i=0;i<7;i++){
  19.         for(int j =0;j<13;j++){
  20.             cout<<matriz[i][j];
  21.  
  22.         }
  23.         cout<<endl;
  24.     }
  25.     system("PAUSE");
  26.  
  27.  
  28. }
  29.  
  30. void mover(int x,int y){
  31.        
  32.         if(x==6 && y==12) return;
  33.  
  34.         if(x-1 >= 0 && matriz[x-1][y]!=9 && matriz[x-1][y]!=0){//CIMA
  35.             matriz[x][y]=9;
  36.             mover(x-1,y);
  37.         }
  38.         if(y+1 <13 && matriz[x][y+1]!=9  && matriz[x][y+1]!=0){//DIREITA
  39.             matriz[x][y]=9;
  40.             mover(x,y+1);
  41.         }
  42.         if(x+1 < 7 && matriz[x+1][y]!=9 && matriz[x+1][y]!=0){//BAIXO
  43.             matriz[x][y]=9;
  44.             mover(x+1,y);
  45.         }
  46.         if(y-1 >= 0 && matriz[x][y-1]!=9 && matriz[x][y-1]!=0){//Esquerda
  47.             matriz[x][y]=9;
  48.             mover(x,y-1);
  49.         }
  50.  
  51.  
  52.     }
Add Comment
Please, Sign In to add comment