Advertisement
Guest User

Untitled

a guest
May 24th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void display(int arr[5][5], int& y, int& x);
  7. bool move(char m, int arr[5][5]);
  8.  
  9. int main()
  10. {
  11. int arr[5][5];
  12. int m, ans;
  13. int x = 0;
  14. int y = 0;
  15.  
  16. do
  17. {
  18. cout << "Which direction do you want to move?(U, D, L, R) ";
  19. cin >> m;
  20.  
  21. display(arr, y, x);
  22.  
  23. }while(ans != 'Q');
  24.  
  25. return 0;
  26. }
  27.  
  28. void display(int arr[5][5], int &y, int& x)
  29. {
  30. for(int i = 0; i < 5; i++)
  31. {
  32. for(int j = 0; j < 5; j++)
  33. {
  34. if(i == y && j == x)
  35. {
  36. cout << "o";
  37. }
  38. else
  39. {
  40. cout << "x";
  41. }
  42. }
  43. }
  44. }
  45.  
  46. bool move(char m, int arr[5][5])
  47. {
  48. int x = 0;
  49. int y = 0;
  50. switch(m)
  51. {
  52. case 'U':
  53. if(y==0) y = 4;
  54. else y--;
  55. break;
  56. case 'D':
  57. if(y==4) y = 0;
  58. else y++;
  59. break;
  60. case 'R':
  61. if(x==4) x = 0;
  62. else x++;
  63. break;
  64. case 'L':
  65. if(x==0) x = 4;
  66. else x--;
  67. break;
  68. default:
  69. return false;
  70. break;
  71. }
  72. return true;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement