Advertisement
Guest User

Untitled

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