Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void display(int arr[5][5], int& y, int& x);
- bool move(char m, int arr[5][5]);
- int main()
- {
- int arr[5][5];
- char ans;
- int x = 0;
- int y = 0;
- do
- {
- cout << "Which direction do you want to move?(U, D, L, R) ";
- cin >> ans;
- display(arr, y, x);
- }while(ans != 'Q');
- return 0;
- }
- void display(int arr[5][5], int &y, int& x)
- {
- for(int i = 0; i < 5; i++)
- {
- for(int j = 0; j < 5; j++)
- {
- if(i == y && j == x)
- {
- cout << "o";
- }
- else
- {
- cout << "x";
- }
- }
- }
- }
- bool move(char m, int arr[5][5])
- {
- int x = 0;
- int y = 0;
- switch(m)
- {
- case 'U':
- if(y==0) y = 4;
- else y--;
- break;
- case 'D':
- if(y==4) y = 0;
- else y++;
- break;
- case 'R':
- if(x==4) x = 0;
- else x++;
- break;
- case 'L':
- if(x==0) x = 4;
- else x--;
- break;
- default:
- return false;
- break;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement