Advertisement
Guest User

p6

a guest
May 2nd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <windows.h>
  6. using namespace std;
  7. void dibuja(char b[99][99],int x, int y,int n);
  8. int main()
  9. {
  10.  
  11. int i,j,a;
  12. char b[99][99];
  13. int n;
  14. cout<<"Tamaño de la matriz : ";cin>>n;cout<<"\n";
  15.  
  16. for(i=1;i<=n;i++){
  17. for(j=1;j<=n;j++){
  18. cin>>b[j][i];
  19. }
  20. }
  21. char mov;
  22.  
  23. system("cls");
  24.  
  25. int x=1,y=1;
  26. dibuja(b,1,1,n);
  27. int estado=1;
  28. do{
  29. cout<<"\n U(arriba) \t A(abajo) \t T(izquierda) \t D(derecha) \t \n Que quieres hacer : ";
  30. cin>>mov;
  31. system("cls");
  32. switch(mov)
  33. {
  34. case 'U':
  35. y--;
  36. break;
  37. case 'A':
  38. y++;
  39. break;
  40. case 'T':
  41. x--;
  42. break;
  43. case 'D':
  44. x++;
  45.  
  46. }
  47.  
  48.  
  49. if((1<=x&&x<=n )&&(1<=y&&y<=n))
  50. {
  51. char a=b[x][y];
  52.  
  53. switch(a){
  54. case '0':
  55. dibuja(b,x,y,n);
  56. break;
  57. case '1':
  58. switch(mov)
  59. {
  60. case 'U':
  61. y++;
  62. break;
  63. case 'A':
  64. y--;
  65. break;
  66. case 'T':
  67. x++;
  68. break;
  69. case 'D':
  70. x--;
  71. }
  72. dibuja(b,x,y,n);
  73. break;
  74. case '2':
  75. estado=0;
  76. break;
  77. case '3':
  78. x=1;
  79. y=1;
  80. dibuja(b,x,y,n);
  81. break;
  82. }
  83. }
  84. else
  85. {
  86. estado = 0;
  87. }
  88.  
  89. }while(estado==1);
  90. system("cls");
  91. cout <<" \n\n ==>ESTAS MUERTO<== \n\n ";
  92. }
  93.  
  94.  
  95.  
  96.  
  97. void dibuja(char b[99][99],int x ,int y,int n){
  98. int r;
  99. int i,j;
  100. cout<<"JUEGO 3.0 \n" ;
  101.  
  102.  
  103.  
  104.  
  105. for(j=1;j<=n;j++){
  106. for(i=1;i<=n;i++){
  107. if(i==x&&j==y){cout<<"X\t";}
  108. else {
  109. cout<<b[i][j];cout<<"\t";
  110. }
  111.  
  112. }
  113. cout<<"\n";
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement