Dungeon crawl

Having a lot of trouble with this problem don't even know where to start any help would be appreciated!

The input to your problem is an ascii representation of a 10 by 10 labyrinth. The characters * are walls, . is an empty space, Y is you, and m is a monster.

Input:

**********
*.*m..*.**
*Y*.*....*
*.*.*.*.**
*..****.**
*....m...*
***.****.*
**..mm.***
*..***...*
**********

The maze may differ, but you will always start at coordinate 1 2 . You can move north, south, east, or west, in that order. You can't move into walls, but you can move into monsters. Your job is to explore the entire dungeon. Your output should be the location of each monster you encounter along the way.

Output:

MONSTER at 4 7
MONSTER at 5 7
MONSTER at 5 5
MONSTER at 3 1

Please use the following algorithm:
1. Read the maze, line by line with getline, into a global string array string maze[10]
2. Make a function void crawl(int x, int y) and call it: crawl(1,2)
In crawl:
3. check if maze[y][x] is a wall '*'. If so, return
4. check if maze[y][x] is a monster 'm'. If so, print the message.
5. change maze[y][x] into a wall '*'. That way you won't revisit it.
6. go north: recursively call crawl(x, y-1)
7. go south
8. go east
9. go west
This is awesome, can't wait to see how you do it.
I don't know how to do it I need help!
Well why don't you start and give us something to work with here, or do you expect us to do it for you ?
looking for some tips on how to get started not for the answer
sounds to me like you need to work with 2 dimension arrays making them constants of course once "create the walls" your "player" needs to move up left right, i don't think you want your player to move down it seems like it will be to easy for that. If i were you i would do it as classes your pseudocode is right there


1. Read the maze, line by line with getline, into a global string array string maze[10]
2. Make a function void crawl(int x, int y) and call it: crawl(1,2)
In crawl:
3. check if maze[y][x] is a wall '*'. If so, return
4. check if maze[y][x] is a monster 'm'. If so, print the message.
5. change maze[y][x] into a wall '*'. That way you won't revisit it.
6. go north: recursively call crawl(x, y-1)
7. go south
8. go east
9. go west


Last edited on
how would I go about outputting the location of each monster?
you would have to check every location maze[y][x] and check the value.

Topic archived. No new replies allowed.