Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum compass {EAST = 1, NORTH = 2, WEST = 3, SOUTH = 4};
- char *player;
- int direction = EAST;
- bool flag, finish = false;
- for(int i = 0; i < 12; i++)
- {
- for(int k = 0; k < 12; k++)
- {
- if(maze[i][k] == 's')
- {
- player = &maze[i][k];
- }
- }
- }
- system("pause");
- do
- {
- flag = false;
- if(direction == EAST)
- {
- //right
- if(*player + 12 == '.')
- {
- player += 12;
- direction -= 1;
- flag = true;
- }
- //straight
- else if(*player + 1 == '.')
- {
- player += 1;
- flag = true;
- }
- if(flag == false)
- {
- direction += 1;
- }
- }
- else if(direction == NORTH)
- {
- //right
- if(*player + 1 == '.')
- {
- player += 1;
- direction -= 1;
- flag = true;
- }
- //straight
- else if(*player - 12 == '.')
- {
- player -= 12;
- flag = true;
- }
- if(flag == false)
- {
- direction += 1;
- }
- }
- else if(direction == WEST)
- {
- //right
- if(*player - 12 == '.')
- {
- player -= 12;
- direction -= 1;
- flag = true;
- }
- //straight
- else if(*player - 1 == '.')
- {
- player -= 1;
- flag = true;
- }
- if(flag == false)
- {
- direction += 1;
- }
- }
- else if(direction == SOUTH)
- {
- //right
- if(*player - 1 == '.')
- {
- player -= 1;
- direction -= 1;
- flag = true;
- }
- //straight
- else if(*player + 12 == '.')
- {
- player += 12;
- flag = true;
- }
- if(flag == false)
- {
- direction += 1;
- }
- }
- if(direction > SOUTH)
- {
- direction = EAST;
- }
- if(direction < EAST)
- {
- direction = SOUTH;
- }
- if(*player == 'f')
- {
- finish = true;
- }
- displayMaze(maze, player);
- system("pause");
- system("cls");
- }while(finish == false);
- system("pause");
Add Comment
Please, Sign In to add comment